mixmod  3.2.0
Mixture models for clustering and classification
 All Classes Namespaces Files Functions Variables Enumerations Friends
GaussianParameter.h
1 /***************************************************************************
2  SRC/mixmod/Kernel/Parameter/GaussianParameter.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 XEMGaussianParameter_H
26 #define XEMGaussianParameter_H
27 
28 #include "mixmod/Utilities/Util.h"
29 #include "mixmod/Kernel/Parameter/Parameter.h"
30 
31 namespace XEM {
32 
33 // pre-declaration
34 class Model;
35 class Matrix;
36 class DiagMatrix;
37 
42 class GaussianParameter : public Parameter {
43 
44 public:
45 
46  //----------------------------
47  // constructors / desctructors
48  // ---------------------------
49 
52 
54  // called by XEMModel
55  GaussianParameter(Model * iModel, ModelType * iModelType);
56 
58  // called by XEMGaussianEDDAParameter if initialization is USER
59  GaussianParameter(int64_t iNbCluster, int64_t iPbDimension, ModelType * iModelType);
60 
62  GaussianParameter(const GaussianParameter * iParameter);
63 
65  virtual ~GaussianParameter();
66 
68  virtual bool operator ==(const GaussianParameter & param) const;
69 
70  virtual Parameter* clone()const = 0;
71 
73  virtual void reset();
74 
75 
76  //----------
77  // selectors
78  //----------
79 
81  double ** getTabMean() const;
82 
83 
84  //----------------
85  // compute methods
86  //----------------
87 
89  void computeGlobalDiagDataVariance(DiagMatrix * matrixDiagDataVar);
90 
92  virtual void computeTabWkW();
93 
95  int64_t computeClassAssigment(int64_t idxSample);
96 
98  void computeTabMean();
99 
104  void computeTabMeanInitUSER_PARTITION(int64_t & nbInitializedCluster, bool * tabNotInitializedCluster, Partition * initPartition);
105 
107  // NB : compute also lambda, shape, orientation, wk, w
108  //virtual void computeTabSigma();
109 
110  //Compute normal probability density function
111  // for iSample the sample and kCluster th cluster
112  virtual double getPdf(int64_t iSample, int64_t kCluster) const = 0;
113 
114  // compute normal probability density function
115  // for all i=1,..,n and k=1,..,K
116  virtual void getAllPdf(double ** tabFik, double * tabProportion) const = 0;
117 
118  // compute normal probability density function
119  // for the line x within the kCluster cluster
120  virtual double getPdf(Sample * x, int64_t kCluster) const = 0;
121 
122 
123  //-----------
124  // Algorithms
125  //-----------
126 
128  void MAPStep();
129 
131  virtual void MStep();
132 
133 
134  // SELECTORS for square matrices
135 
137  //XEMMatrix ** getTabSigma();
138 
142  Matrix ** getTabWk() const;
143 
147  Matrix * getW() const;
148 
149  // edit (for debug)
150  virtual void edit() = 0;
151 
153  virtual void edit(std::ofstream & oFile, bool text = false) = 0;
154 
155  virtual void input(std::ifstream & fi) = 0;
156 
157  virtual double getLogLikelihoodOne() const = 0;
158 
160  // utilisé par SMALL_EM, CEM_INIT
161  virtual void recopy(Parameter * otherParameter) = 0;
162 
163  virtual void updateForCV(Model * originalModel, CVBlock & CVBlock);
164 
165  //init
166  //----
167  void updateForInitRANDOMorUSER_PARTITION(Sample ** tabSampleForInit, bool * tabClusterToInitialize);
168 
170  virtual void initUSER(Parameter * iParam) = 0;
171 
172 protected:
173 
174  // Square matrices
175  // Table of covariance Matrix of each cluster
176  //XEMMatrix ** _tabSigma;
177 
178  // Table of inverse of covariance matrix of each cluster
179  //XEMMatrix ** _tabInvSigma;
180 
182  Matrix ** _tabWk;
183 
185  Matrix * _W;
186 
187  // 1/det(Sigma)
188  //double * _tabInvSqrtDetSigma;
189 
191  double ** _tabMean;
192 
193  // called by constructor
194  // update _freeProportion
195  void initFreeProportion(ModelType * iModelType);
196 
199  void computeMeanOne(double * Mean, double * weight, double** y_Store,
200  int64_t nbSample, double totalWeight) const;
201 
202  void putIdentityInDiagonalMatrix(double * mat_store);
203 
204  void putIdentityInMatrix(double * mat_store);
205 
206  void initDiagonalMatrixToZero(double * A_store);
207 
208  double determinantDiag(double * mat_store, Exception& errorType);
209 };
210 
211 //---------------
212 // inline methods
213 //---------------
214 
215 inline double ** GaussianParameter::getTabMean() const {
216  return this->_tabMean;
217 }
218 
219 /*inline XEMMatrix ** XEMGaussianParameter::getTabSigma(){
220  return _tabSigma;
221 }*/
222 
224  return _tabWk;
225 }
226 
227 inline Matrix * GaussianParameter::getW() const {
228  return _W;
229 }
230 
231 }
232 
233 #endif
class XEMDiagMatrix
Definition: DiagMatrix.h:40
virtual void initUSER(Parameter *iParam)=0
init user
Base class for ModelType(s)
Definition: ModelType.h:37
virtual void MStep()
Maximization step method.
Definition: GaussianParameter.cpp:503
Matrix * getW() const
Selector.
Definition: GaussianParameter.h:227
virtual ~GaussianParameter()
Destructor.
Definition: GaussianParameter.cpp:115
Definition: Exception.h:42
XEMCVBlock.
Definition: Util.h:393
virtual void reset()
reset to default values
Definition: GaussianParameter.cpp:163
virtual void computeTabWkW()
Compute table of cluster scattering matrices Wk and W.
Definition: GaussianParameter.cpp:236
void computeTabMean()
Compute table of means of the samples for each cluster.
Definition: GaussianParameter.cpp:393
void computeTabMeanInitUSER_PARTITION(int64_t &nbInitializedCluster, bool *tabNotInitializedCluster, Partition *initPartition)
Definition: GaussianParameter.cpp:333
GaussianParameter()
Default constructor.
Definition: GaussianParameter.cpp:45
Base class for Partition(s)
Definition: Partition.h:39
double ** getTabMean() const
get TabMean
Definition: GaussianParameter.h:215
Definition: Model.h:50
void computeMeanOne(double *Mean, double *weight, double **y_Store, int64_t nbSample, double totalWeight) const
Definition: GaussianParameter.cpp:448
virtual double getPdf(int64_t iSample, int64_t kCluster) const =0
Compute table of sigmas of the samples for each cluster.
void MAPStep()
Maximum a posteriori step method.
Base class for XEMGaussianParameter(s)
Definition: GaussianParameter.h:42
virtual bool operator==(const GaussianParameter &param) const
Comparison operator.
Definition: GaussianParameter.cpp:150
virtual Parameter * clone() const =0
Selector.
Constants definitions, various utilities to describe models, and others...
Base class for Sample.
Definition: Sample.h:41
int64_t computeClassAssigment(int64_t idxSample)
compute label of idxSample
Definition: GaussianParameter.cpp:296
virtual double getLogLikelihoodOne() const =0
get loglikelihood with one cluster
void computeGlobalDiagDataVariance(DiagMatrix *matrixDiagDataVar)
computeDiagGlobalDataVariance
Definition: GaussianParameter.cpp:198
Matrix ** getTabWk() const
get TabSigma
Definition: GaussianParameter.h:223
Base class for Matrix.
Definition: Matrix.h:41
Base class for XEMParameter(s)
Definition: Parameter.h:45
virtual void input(std::ifstream &fi)=0
input
virtual void recopy(Parameter *otherParameter)=0
recopie sans faire construction / destruction