mixmod  3.2.0
Mixture models for clustering and classification
 All Classes Namespaces Files Functions Variables Enumerations Friends
SymmetricMatrix.h
1 /***************************************************************************
2  SRC/mixmod/Matrix/SymmetricMatrix.h description
3  copyright : (C) MIXMOD Team - 2001-2016
4  email : contact@mixmod.org
5  ***************************************************************************/
6 
7 /***************************************************************************
8  This file is part of MIXMOD
9 
10  MIXMOD is free software: you can redistribute it and/or modify
11  it under the terms of the GNU General Public License as published by
12  the Free Software Foundation, either version 3 of the License, or
13  (at your option) any later version.
14 
15  MIXMOD is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  GNU General Public License for more details.
19 
20  You should have received a copy of the GNU General Public License
21  along with MIXMOD. If not, see <http://www.gnu.org/licenses/>.
22 
23  All informations available on : http://www.mixmod.org
24 ***************************************************************************/
25 #ifndef XEMSYMMETRICMATRIX_H
26 #define XEMSYMMETRICMATRIX_H
27 
28 #include "mixmod/Matrix/Matrix.h"
29 
30 namespace XEM {
31 
37 class DiagMatrix;
38 
39 class SymmetricMatrix : public Matrix {
40 
41 public:
42 
45 
48  SymmetricMatrix(int64_t pbDimension, double d = 1.0);
49 
51 
53  virtual ~SymmetricMatrix();
54 
56  double determinant(Exception& errorType);
57 
59  double * getStore();
60 
63 
65  int64_t getStoreDim();
66 
68  void inverse(Matrix * & A);
69 
71  double norme(double * xMoinsMean);
72 
74  void equalToMatrixDividedByDouble(Matrix * A, double d);
75 
77  void equalToMatrixMultiplyByDouble(Matrix*D, double d);
78 
80  void add(double * xMoinsMean, double cik);
81 
82  // add : diag( cik * xMoinsMean * xMoinsMean' ) to this
83  //void addDiag(double * xMoinsMean, double cik);
84 
86  double putSphericalValueInStore(double & store);
88  double addSphericalValueInStore(double & store);
89 
90  double getSphericalStore();
91 
93  double* putDiagonalValueInStore(double * store);
95  double* addDiagonalValueInStore(double * store);
96 
97  double* getDiagonalStore();
98 
100  double* putSymmetricValueInStore(double * store);
102  double* addSymmetricValueInStore(double * store);
103 
104  double* getSymmetricStore();
105 
107  double* putGeneralValueInStore(double * store);
109  double* addGeneralValueInStore(double * store);
110 
111  double* getGeneralStore();
112 
114  void computeSVD(DiagMatrix* & S, GeneralMatrix* & O);
115 
116 
118  void operator=(const double& d);
120  void operator/=(const double& d);
122  void operator*=(const double& d);
124  void operator+=(Matrix* M);
126  void operator=(Matrix* M);
127 
128 
130  void input(std::ifstream & fi);
131  virtual void input(double ** variances);
132 
133  /* ///compute SVD decomposition for a symmetric matrix
134  void computeSVD(XEMDiagMatrix* & S, XEMGeneralMatrix* & O);*/
135 
137  void computeShape_as__diag_Ot_this_O(DiagMatrix* & Shape, GeneralMatrix* & Ori, double diviseur = 1.0);
138  // double trace_this_O_Sm1_O(XEMGeneralMatrix* & O, XEMDiagMatrix* & S);
139 
141  void compute_as__multi_O_S_O(double multi, GeneralMatrix* & O, DiagMatrix* & S);
142 
144  void compute_as_O_S_O(GeneralMatrix* & O, double* & S_store);
146  double computeTrace();
147 
149  void compute_as_M_tM(GeneralMatrix* M, int64_t d);
150 
152  void compute_as_M_V(SymmetricMatrix* M, double * V);
153 
155  void compute_product_Lk_Wk(Matrix* Wk, double L);
156 
158  double compute_trace_W_C(Matrix * C);
159 
162 
164  void compute_M_tM(double* V, int64_t l);
165 
167  double detDiag(Exception& errorType);
168 
170  double trace_this_O_Sm1_O(GeneralMatrix* & O, DiagMatrix* & S);
171 
173 
174  void setSymmetricStore(double * store);
175  void setGeneralStore(double * store);
176  void setDiagonalStore(double * store);
177  void setSphericalStore(double store);
178  double** storeToArray() const;
179 
180 protected:
181 
183  MATH::SymmetricMatrix * _value;
184 
186  double * _store;
187 
189  int64_t _s_storeDim;
190 };
191 
192 // TODO static :
193 // int64_t XEMGeneralMatrix::_s_storeDim = 0;
194 
195 inline double * SymmetricMatrix::getStore() {
196  return _store;
197 }
198 
200  return _value;
201 }
202 
204  return _s_storeDim;
205 }
206 
207 inline void SymmetricMatrix::setSymmetricStore(double * store) {
208  // _store = store;
209  recopyTab(store, _store, _s_storeDim);
210 }
211 
212 inline void SymmetricMatrix::setSphericalStore(double store) {
213  THROW(OtherException, wrongMatrixType);
214 }
215 
216 inline void SymmetricMatrix::setGeneralStore(double * store) {
217  THROW(OtherException, wrongMatrixType);
218 }
219 
220 inline void SymmetricMatrix::setDiagonalStore(double * store) {
221  THROW(OtherException, wrongMatrixType);
222 }
223 
224 /* TODO static
225 inline void XEMGeneralMatrix::initiate(){
226  _s_storeDim = _s_pbDimension * _s_pbDimension / 2;
227 }
228  */
229 
230 }
231 
232 #endif
void operator=(const double &d)
this = (d * Identity)
Definition: SymmetricMatrix.cpp:287
class XEMDiagMatrix
Definition: DiagMatrix.h:40
void operator+=(Matrix *M)
this = this + matrix
Definition: SymmetricMatrix.cpp:319
void equalToMatrixMultiplyByDouble(Matrix *D, double d)
compute : this = A * d
Definition: SymmetricMatrix.cpp:83
class GeneralMatrix
Definition: GeneralMatrix.h:40
Definition: Eigen.h:98
double compute_trace_W_C(Matrix *C)
copute trace of W * C
Definition: SymmetricMatrix.cpp:132
void compute_product_Lk_Wk(Matrix *Wk, double L)
compute this as double * matrix
Definition: SymmetricMatrix.cpp:124
Definition: SymmetricMatrix.h:39
double trace_this_O_Sm1_O(GeneralMatrix *&O, DiagMatrix *&S)
trace( this * O * S^{-1} * O' )
Definition: SymmetricMatrix.cpp:600
double * addDiagonalValueInStore(double *store)
Add store of a diagonal matrix in a diagonal one.
Definition: SymmetricMatrix.cpp:216
Definition: OtherException.h:37
void input(std::ifstream &fi)
read symmetric matrix store in file
Definition: SymmetricMatrix.cpp:557
Definition: Exception.h:42
void setSymmetricStore(double *store)
set store
Definition: SymmetricMatrix.h:207
void compute_M_as__O_Sinverse_Ot_this(GeneralMatrix &M, GeneralMatrix *&O, DiagMatrix *&S)
compute M as : M = ( O * S^{-1} * O' ) * this
Definition: SymmetricMatrix.cpp:499
double * addSymmetricValueInStore(double *store)
Add store of a diagonal matrix in a diagonal one.
Definition: SymmetricMatrix.cpp:234
void operator*=(const double &d)
this = this * ( Identity * d)
Definition: SymmetricMatrix.cpp:307
void compute_M_tM(double *V, int64_t l)
compute this as vector * vector'
Definition: SymmetricMatrix.cpp:103
void computeSVD(DiagMatrix *&S, GeneralMatrix *&O)
compute general matrix SVD decomposition
Definition: SymmetricMatrix.cpp:425
double * getStore()
Return store of symmetric matrix.
Definition: SymmetricMatrix.h:195
void operator/=(const double &d)
this = this / (Identity * d)
Definition: SymmetricMatrix.cpp:299
SymmetricMatrix()
Default constructor.
Definition: SymmetricMatrix.cpp:35
void compute_as_M_V(SymmetricMatrix *M, double *V)
compute this as matrix * vector
Definition: SymmetricMatrix.cpp:474
MATH::SymmetricMatrix * getValue()
Return newmat symmetric matrix.
Definition: SymmetricMatrix.h:199
double norme(double *xMoinsMean)
compute (x - mean)' this (x - mean)
Definition: SymmetricMatrix.cpp:161
double detDiag(Exception &errorType)
gives : det(diag(this))
Definition: SymmetricMatrix.cpp:586
double computeTrace()
compute trace of this
Definition: SymmetricMatrix.cpp:410
double addSphericalValueInStore(double &store)
Add store of a spherical matrix in a symmetric one.
Definition: SymmetricMatrix.cpp:193
void computeShape_as__diag_Ot_this_O(DiagMatrix *&Shape, GeneralMatrix *&Ori, double diviseur=1.0)
compute Shape as diag(Ot . this . O ) / diviseur
Definition: SymmetricMatrix.cpp:324
void compute_as_M_tM(GeneralMatrix *M, int64_t d)
compute this as M * M'
Definition: SymmetricMatrix.cpp:444
double determinant(Exception &errorType)
Compute determinant of symmetric matrix.
Definition: SymmetricMatrix.cpp:69
void equalToMatrixDividedByDouble(Matrix *A, double d)
compute : this = A / d
Definition: SymmetricMatrix.cpp:250
void add(double *xMoinsMean, double cik)
add : cik * xMoinsMean * xMoinsMean' to this
Definition: SymmetricMatrix.cpp:260
void compute_as__multi_O_S_O(double multi, GeneralMatrix *&O, DiagMatrix *&S)
compute this as : multi * (O * S * O' )
Definition: SymmetricMatrix.cpp:360
void inverse(Matrix *&A)
Inverse symmetric matrix.
Definition: SymmetricMatrix.cpp:148
double putSphericalValueInStore(double &store)
Return store of a spherical matrix in a symmetric one.
Definition: SymmetricMatrix.cpp:178
Base class for Matrix.
Definition: Matrix.h:41
double * putDiagonalValueInStore(double *store)
Return store of a diagonal matrix.
Definition: SymmetricMatrix.cpp:205
double * putGeneralValueInStore(double *store)
Return store of a diagonal matrix.
Definition: SymmetricMatrix.cpp:241
double * putSymmetricValueInStore(double *store)
Return store of a diagonal matrix.
Definition: SymmetricMatrix.cpp:227
virtual ~SymmetricMatrix()
Destructor.
Definition: SymmetricMatrix.cpp:62
void compute_as_O_S_O(GeneralMatrix *&O, double *&S_store)
compute this as O*S*O'
Definition: SymmetricMatrix.cpp:385
double * addGeneralValueInStore(double *store)
Add store of a diagonal matrix in a diagonal one.
Definition: SymmetricMatrix.cpp:245
int64_t getStoreDim()
Return dimension of store.
Definition: SymmetricMatrix.h:203