mixmod  3.2.0
Mixture models for clustering and classification
 All Classes Namespaces Files Functions Variables Enumerations Friends
BinaryParameter.h
1 /***************************************************************************
2  SRC/mixmod/Kernel/Parameter/BinaryParameter.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 XEMBinaryParameter_H
26 #define XEMBinaryParameter_H
27 
28 #include "mixmod/Utilities/Util.h"
29 #include "mixmod/Kernel/Parameter/Parameter.h"
30 
31 namespace XEM {
32 
33 class GaussianParameter;
34 class BinaryParameter;
35 
41 class BinaryParameter : public Parameter {
42 
43 public:
44 
45  //----------------------------
46  // constructors / desctructors
47  // ---------------------------
48 
51 
53  // called by XEMModel (via XEMBinary...Parameter)
54  BinaryParameter(Model * iModel, ModelType * iModelType, int64_t * tabNbModality);
55 
56  // constructor
57  // called if USER initialisation
58  BinaryParameter(int64_t iNbCluster, int64_t iPbDimension,
59  ModelType * iModelType, int64_t * tabNbModality);
60 
62  BinaryParameter(const BinaryParameter * iParameter);
63 
65  virtual ~BinaryParameter();
66 
68  virtual bool operator ==(const BinaryParameter & param) const;
69 
70 
72  virtual void reset();
73 
75  Parameter * createParameter(Model * iModel, int64_t i0, int64_t ki0);
76 
77 
78  //----------
79  // selectors
80  //----------
81 
83  int64_t ** getTabCenter() const;
84 
86  int64_t * getTabNbModality() const;
87 
89  int64_t getTotalNbModality() const;
90 
91  //----------------
92  // compute methods
93  //----------------
94 
95  void getAllPdf(double ** tabFik, double * tabProportion) const;
96 
102  virtual double getPdf(int64_t iSample, int64_t kCluster) const = 0;
103 
108  virtual long double getLogPdf(int64_t iSample, int64_t kCluster) const = 0;
109 
113  //double getPdf(RowVector x, int64_t kCluster);
114  virtual double getPdf(Sample * x, int64_t kCluster) const = 0;
115 
117  virtual double getLogLikelihoodOne() const = 0;
118 
120  virtual void computeTikUnderflow(int64_t i, double ** tabTik);
121 
123  void computeTabCenter();
124 
126  virtual void computeScatter() = 0;
127 
129  virtual void computeRandomScatter() = 0;
130 
132  virtual void recopyScatter(Parameter * iParam) = 0;
133 
134 
135  //---------------
136  // initialization
137  //---------------
138 
140  void initUSER(Parameter * iParam);
141 
144  Sample ** tabSampleForInit, bool * tabClusterToInitialize);
145 
147  void initForInitRANDOM();
148 
153  void initForInitUSER_PARTITION(int64_t & nbInitializedCluster,
154  bool * tabNotInitializedCluster, Partition * initPartition);
155 
159  void computeTabCenterInitUSER_PARTITION(int64_t & nbInitializedCluster,
160  bool * tabNotInitializedCluster, Partition * initPartition);
161 
162 
163  //-----------
164  // Algorithms
165  //-----------
166 
168  void MAPStep();
169 
171  //void EStep();
172 
174  void MStep();
175 
176 
177  //---------------
178  // input / output
179  //---------------
180 
181  // edit (for debug)
182  void edit();
183 
185  virtual void editScatter(int64_t k) = 0;
186 
188  void edit(std::ofstream & oFile, bool text = false);
189 
191  virtual void editScatter(std::ofstream & oFile, int64_t k, bool text = false) = 0;
192 
193  // Read Parameters in input file
194  void input(std::ifstream & fi);
195 
196  // Read Parameters in input containers
197  void input(
198  double * proportions,
199  double ** centers,
200  double *** scatters);
201 
202  // Read Scatter in input file
203  virtual void inputScatter(std::ifstream & fi) = 0;
204  virtual void inputScatter(double *** scatters) = 0;
205 
207  // utilise par SMALL_EM, CEM_INIT, SEM ...
208  void recopy(Parameter * otherParameter);
209 
211  virtual void createScatter(double *** scatter) = 0;
212  virtual double *** scatterToArray() const = 0;
213 
214  void updateForCV(Model * originalModel, CVBlock & CVBlock);
215 
216 protected:
217 
219  // _tabCenter will not be changed
220  void getTabCenterIfOneCluster(int64_t * tabCenter, double * tabNbSampleInMajorModality,
221  double ** tabNbSamplePerModality = NULL) const;
222 
224  int64_t ** _tabCenter;
225 
227  int64_t * _tabNbModality;
228 
230  int64_t _totalNbModality;
231 };
232 
234 double computePdfOneCluster(Sample * x, int64_t * Center, double Scatter, int64_t * tabNbModality);
235 
237 double computePdfOneCluster(Sample * x, int64_t * Center,
238  double * Scatter, int64_t * tabNbModality);
239 
241 // (Scatter is a array of double*double, depends on variables and modalities)
242 double computePdfOneCluster(Sample * x, int64_t * Center,
243  double ** Scatter, int64_t * tabNbModality);
244 
245 //---------------
246 // inline methods
247 //---------------
248 
249 inline int64_t ** BinaryParameter::getTabCenter() const {
250  return _tabCenter;
251 }
252 
253 inline int64_t * BinaryParameter::getTabNbModality() const {
254  return _tabNbModality;
255 }
256 
257 inline int64_t BinaryParameter::getTotalNbModality() const {
258  return _totalNbModality;
259 }
260 
261 }
262 
263 #endif
virtual double getLogLikelihoodOne() const =0
getlogLikelihoodOne (one cluster)
int64_t ** getTabCenter() const
get TabCenter
Definition: BinaryParameter.h:249
Base class for ModelType(s)
Definition: ModelType.h:37
virtual double getPdf(int64_t iSample, int64_t kCluster) const =0
Compute probability density.
void recopy(Parameter *otherParameter)
recopie sans faire construction / destruction
Definition: BinaryParameter.cpp:700
int64_t getTotalNbModality() const
get total number of modality
Definition: BinaryParameter.h:257
Parameter * createParameter(Model *iModel, int64_t i0, int64_t ki0)
create the same parameter than this but after updating because without xi0
virtual void recopyScatter(Parameter *iParam)=0
recopy scatter from param (used for init : USER)
Base class for XEMBinaryParameter(s)
Definition: BinaryParameter.h:41
virtual ~BinaryParameter()
Destructor.
Definition: BinaryParameter.cpp:140
void initForInitRANDOM()
initialize attributes before an InitRandom
Definition: BinaryParameter.cpp:469
void computeTabCenter()
Compute table of centers of the samples for each cluster.
Definition: BinaryParameter.cpp:354
virtual void reset()
reset to default values
Definition: BinaryParameter.cpp:178
XEMCVBlock.
Definition: Util.h:393
void MStep()
Expectation step method.
Definition: BinaryParameter.cpp:512
void getTabCenterIfOneCluster(int64_t *tabCenter, double *tabNbSampleInMajorModality, double **tabNbSamplePerModality=NULL) const
compute TabCenter if there is only One Cluster
Definition: BinaryParameter.cpp:193
BinaryParameter()
Default constructor.
Definition: BinaryParameter.cpp:46
void computeTabCenterInitUSER_PARTITION(int64_t &nbInitializedCluster, bool *tabNotInitializedCluster, Partition *initPartition)
Definition: BinaryParameter.cpp:302
virtual void createScatter(double ***scatter)=0
create Scatter from "Binary Parameter Ekjh"
double computePdfOneCluster(Sample *x, int64_t *Center, double Scatter, int64_t *tabNbModality)
compute Pdf in case nbCluster=1 (Scatter is a scalar)
Definition: BinaryParameter.cpp:650
Base class for Partition(s)
Definition: Partition.h:39
Definition: Model.h:50
virtual void computeScatter()=0
Compute scatter(s)
void MAPStep()
Maximum a posteriori step method.
virtual bool operator==(const BinaryParameter &param) const
Comparison operator.
Definition: BinaryParameter.cpp:161
void initUSER(Parameter *iParam)
init user
Definition: BinaryParameter.cpp:426
virtual void editScatter(int64_t k)=0
editScatter (for debug)
int64_t * getTabNbModality() const
get _tabNbModality
Definition: BinaryParameter.h:253
Constants definitions, various utilities to describe models, and others...
void updateForInitRANDOMorUSER_PARTITION(Sample **tabSampleForInit, bool *tabClusterToInitialize)
updateForInitRANDOMorUSER_PARTITION
Definition: BinaryParameter.cpp:397
Base class for Sample.
Definition: Sample.h:41
void input(std::ifstream &fi)
input
Definition: BinaryParameter.cpp:596
void initForInitUSER_PARTITION(int64_t &nbInitializedCluster, bool *tabNotInitializedCluster, Partition *initPartition)
Definition: BinaryParameter.cpp:479
virtual long double getLogPdf(int64_t iSample, int64_t kCluster) const =0
Compute log probability density.
Base class for XEMParameter(s)
Definition: Parameter.h:45
virtual void computeTikUnderflow(int64_t i, double **tabTik)
compute Tik for xi (i=0 -> _nbSample-1) when underflow
Definition: BinaryParameter.cpp:249
virtual void computeRandomScatter()=0
Compute random scatter(s)