mixmod  3.2.0
Mixture models for clustering and classification
 All Classes Namespaces Files Functions Variables Enumerations Friends
GeneralMatrix.h
1 /***************************************************************************
2  SRC/mixmod/Matrix/GeneralMatrix.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 XEMGENERALMATRIX_H
26 #define XEMGENERALMATRIX_H
27 
28 #include "mixmod/Matrix/Matrix.h"
29 
30 namespace XEM {
31 
32 // pre-declaration
33 class DiagMatrix;
34 
40 class GeneralMatrix : public Matrix {
41 
42 public:
43 
45  GeneralMatrix();
46 
49  GeneralMatrix(int64_t pbDimension, double d = 1.0);
50 
52 
54  virtual ~GeneralMatrix();
55 
57  double determinant(Exception& errorType);
58 
60  double * getStore();
61 
64 
66  int64_t getStoreDim();
67 
69  void inverse(Matrix * & A);
70 
71  void compute_product_Lk_Wk(Matrix* Wk, double L);
72 
74  double norme(double * xMoinsMean);
75 
77  void equalToMatrixDividedByDouble(Matrix * A, double d);
79  void equalToMatrixMultiplyByDouble(Matrix*D, double d);
80 
81 
83  void add(double * xMoinsMean, double cik);
84 
85  // add : diag( cik * xMoinsMean * xMoinsMean' ) to this
86  //void addDiag(double * xMoinsMean, double cik);
87 
89  double putSphericalValueInStore(double & store);
91  double addSphericalValueInStore(double & store);
92 
93  double getSphericalStore();
94 
96  double* putDiagonalValueInStore(double * store);
98  double* addDiagonalValueInStore(double * store);
99 
100  double* getDiagonalStore();
101 
103  double* putSymmetricValueInStore(double * store);
105  double* addSymmetricValueInStore(double * store);
106 
107  double* getSymmetricStore();
108 
110  double* putGeneralValueInStore(double * store);
112  double* addGeneralValueInStore(double * store);
113 
114  double* getGeneralStore();
115 
117  void operator=(const double& d);
118 
120  void operator/=(const double& d);
121 
123  void operator*=(const double& d);
124 
126  void operator+=(Matrix* M);
127 
129  void operator=(Matrix* M);
130 
131 
133  void edit(std::ostream& flux, std::string before, std::string sep, int64_t dim);
134 
136  void input(std::ifstream & fi);
138  void input(std::ifstream & fi, int64_t dim);
139  virtual void input(double ** variances);
140 
141 
143  void computeSVD(DiagMatrix* & S, GeneralMatrix* & O);
144 
146  void computeShape_as__diag_Ot_this_O(DiagMatrix* & Shape, GeneralMatrix* & Ori, double diviseur = 1.0);
147 
149  void compute_as__multi_O_S_O(double multi, GeneralMatrix* & O, DiagMatrix *& S);
150 
152  void compute_as_O_S_O(GeneralMatrix* & O, double* & S_store);
153 
155  double computeTrace();
156 
158  void compute_as_M_tM(GeneralMatrix* M, int64_t d);
159 
161  void compute_as_M_V(GeneralMatrix* M, double * V);
163  void multiply(double * V, int64_t nk, GeneralMatrix * Q);
164 
167  double compute_trace_W_C(Matrix * C);
168  // void computeShape_as__diag_Ot_this_O(XEMDiagMatrix* & Shape, XEMGeneralMatrix* & Ori, double diviseur = 1.0);
170  double detDiag(Exception& errorType);
171 
173  double trace_this_O_Sm1_O(GeneralMatrix* & O, DiagMatrix* & S);
174 
175  //void refreshStore();
176 
177  void setSymmetricStore(double * store);
178  void setGeneralStore(double * store);
179  void setDiagonalStore(double * store);
180  void setSphericalStore(double store);
181 
182  double** storeToArray() const;
183 
184 protected:
185 
186  // General matrix as in mathematical library
187  MATH::Matrix * _value;
188 
189  double * _store;
190 
191  int64_t _s_storeDim;
192 };
193 
194 // TODO static :
195 // int64_t XEMGeneralMatrix::_s_storeDim = 0;
196 
197 inline double * GeneralMatrix::getStore() {
198  return _store;
199 }
200 
202  return _value;
203 }
204 
205 inline int64_t GeneralMatrix::getStoreDim() {
206  return _s_storeDim;
207 }
208 
209 inline void GeneralMatrix::setSymmetricStore(double * store) {
210  THROW(OtherException, wrongMatrixType);
211 }
212 
213 inline void GeneralMatrix::setSphericalStore(double store) {
214  THROW(OtherException, wrongMatrixType);
215 }
216 
217 inline void GeneralMatrix::setGeneralStore(double * store) {
218  //_store = store;
219  recopyTab(store, _store, _s_storeDim);
220 }
221 
222 inline void GeneralMatrix::setDiagonalStore(double * store) {
223  THROW(OtherException, wrongMatrixType);
224 }
225 
226 /* TODO static
227 inline void GeneralMatrix::initiate(){
228  _s_storeDim = _s_pbDimension * _s_pbDimension / 2;
229 }
230  */
231 
232 }
233 
234 #endif
double addSphericalValueInStore(double &store)
add store of a spherical matrix in a general one
Definition: GeneralMatrix.cpp:146
class XEMDiagMatrix
Definition: DiagMatrix.h:40
double computeTrace()
compute trace of this
Definition: GeneralMatrix.cpp:247
class GeneralMatrix
Definition: GeneralMatrix.h:40
double * getStore()
return store of general matrix
Definition: GeneralMatrix.h:197
double * putSymmetricValueInStore(double *store)
Return store of a diagonal matrix.
Definition: GeneralMatrix.cpp:158
void compute_M_as__O_Sinverse_Ot_this(GeneralMatrix &M, GeneralMatrix *&O, DiagMatrix *&S)
compute M as : M = ( O * S^{-1} * O' ) * this
Definition: GeneralMatrix.cpp:264
void computeSVD(DiagMatrix *&S, GeneralMatrix *&O)
compute general matrix SVD decomposition
Definition: GeneralMatrix.cpp:251
void compute_as_O_S_O(GeneralMatrix *&O, double *&S_store)
compute this as O * S *O'
Definition: GeneralMatrix.cpp:242
Definition: OtherException.h:37
void compute_as_M_tM(GeneralMatrix *M, int64_t d)
compute this as matrix * matrix'
Definition: GeneralMatrix.cpp:255
Definition: Exception.h:42
double * addDiagonalValueInStore(double *store)
Add store of a diagonal matrix in a diagonal one.
Definition: GeneralMatrix.cpp:154
double * putGeneralValueInStore(double *store)
Return store of a diagonal matrix.
Definition: GeneralMatrix.cpp:166
void edit(std::ostream &flux, std::string before, std::string sep, int64_t dim)
edit general matrix
Definition: GeneralMatrix.cpp:218
void input(std::ifstream &fi)
read general matrix from input file
Definition: GeneralMatrix.cpp:270
void setSymmetricStore(double *store)
set store
Definition: GeneralMatrix.h:209
void compute_as__multi_O_S_O(double multi, GeneralMatrix *&O, DiagMatrix *&S)
compute this as : multi * (O * S * O' )
Definition: GeneralMatrix.cpp:236
void computeShape_as__diag_Ot_this_O(DiagMatrix *&Shape, GeneralMatrix *&Ori, double diviseur=1.0)
compute Shape as diag(Ot . this . O ) / diviseur
Definition: GeneralMatrix.cpp:109
MATH::Matrix * getValue()
return newmat general matrix
Definition: GeneralMatrix.h:201
double * addGeneralValueInStore(double *store)
Add store of a diagonal matrix in a diagonal one.
Definition: GeneralMatrix.cpp:173
virtual ~GeneralMatrix()
Destructor.
Definition: GeneralMatrix.cpp:61
void operator/=(const double &d)
this = this / (d x Identity)
Definition: GeneralMatrix.cpp:200
double detDiag(Exception &errorType)
gives : det(diag(this))
Definition: GeneralMatrix.cpp:304
void equalToMatrixMultiplyByDouble(Matrix *D, double d)
this = A * d
Definition: GeneralMatrix.cpp:72
Definition: Eigen.h:64
double trace_this_O_Sm1_O(GeneralMatrix *&O, DiagMatrix *&S)
trace( this * O * S^{-1} * O' )
Definition: GeneralMatrix.cpp:309
GeneralMatrix()
Default constructor.
Definition: GeneralMatrix.cpp:34
double * putDiagonalValueInStore(double *store)
Return store of a diagonal matrix.
Definition: GeneralMatrix.cpp:150
int64_t getStoreDim()
return dimension of store
Definition: GeneralMatrix.h:205
void operator*=(const double &d)
this = this * (d x Identity)
Definition: GeneralMatrix.cpp:205
void multiply(double *V, int64_t nk, GeneralMatrix *Q)
compute this as vector multiplied by matrix
Definition: GeneralMatrix.cpp:76
double norme(double *xMoinsMean)
compute (x - mean)' this (x - mean)
Definition: GeneralMatrix.cpp:123
void add(double *xMoinsMean, double cik)
add : cik * xMoinsMean * xMoinsMean' to this
Definition: GeneralMatrix.cpp:133
void operator=(const double &d)
this = (d x Identity)
Definition: GeneralMatrix.cpp:181
double determinant(Exception &errorType)
compute determinant of general matrix
Definition: GeneralMatrix.cpp:68
double putSphericalValueInStore(double &store)
return store of a spherical matrix in a general one
Definition: GeneralMatrix.cpp:142
void equalToMatrixDividedByDouble(Matrix *A, double d)
this = A / d
Definition: GeneralMatrix.cpp:128
void compute_as_M_V(GeneralMatrix *M, double *V)
compute this as matrix * vector
Definition: GeneralMatrix.cpp:259
double * addSymmetricValueInStore(double *store)
Add store of a diagonal matrix in a diagonal one.
Definition: GeneralMatrix.cpp:162
Base class for Matrix.
Definition: Matrix.h:41
void inverse(Matrix *&A)
inverse general matrix
Definition: GeneralMatrix.cpp:115
void operator+=(Matrix *M)
this = this + matrix
Definition: GeneralMatrix.cpp:214