mixmod  3.2.0
Mixture models for clustering and classification
 All Classes Namespaces Files Functions Variables Enumerations Friends
Model.h
1 /***************************************************************************
2  SRC/mixmod/Kernel/Model/Model.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 XEMMODEL_H
26 #define XEMMODEL_H
27 
28 #include "mixmod/Utilities/Util.h"
29 #include "mixmod/Utilities/Error.h"
30 #include "mixmod/Kernel/IO/Data.h"
31 #include "mixmod/Kernel/Parameter/Parameter.h"
32 
33 namespace XEM {
34 
40 // pre-declaration
41 class Parameter;
42 class GaussianData;
43 class BinaryData;
44 class ClusteringStrategyInit;
45 class Partition;
46 class Sample;
47 class ModelType;
48 class LabelDescription;
49 
50 class Model {
51 
52 public:
53 
55  Model();
56 
57  //clone the model
58  virtual Model * clone();
60  Model(Model * iModel);
61 
63  Model(ModelType * modelType, int64_t nbCluster, Data *& data, Partition * knownPartition);
64 
66  virtual ~Model();
67 
68  void updateForCV(Model * originalModel, CVBlock & CVBlock);
69 
70 
71  //-------
72  // select
73  //-------
74 
79  GaussianParameter * getGaussianParameter();
80  BinaryParameter * getBinaryParameter();
81 
85  int64_t getNbCluster();
86 
90  Data * getData();
91 
102 
106  Exception& getErrorType() const;
107 
111  ModelType * const & getModelType() const;
112 
116  int64_t getNbSample();
117 
121  double ** getTabFik();
122 
124  double * getTabSumF();
125 
131  double ** getTabTik();
132 
136  int64_t ** getTabZikKnown();
137 
138  double ** getTabCik();
139 
141  bool * getTabZiKnown();
142 
146  double * getTabNk();
147 
148  bool getDeleteData();
149 
150 
151  //---------
152  // compute
153  //--------
154 
156  void computeFik();
157 
159  void computeNk();
160 
164  double getLogLikelihood(bool fikMustBeComputed);
165 
166 
170  double getLogLikelihoodOne();
171 
176  double getEntropy();
177 
181  double getCompletedLogLikelihood();
182 
185 
187  int64_t getFreeParameter();
188 
192  double getLogN();
193 
196  void getLabelAndPartitionByMAPOrKnownPartition(int64_t * label, int64_t ** partition);
197 
200  int64_t getLabelByMAPOrKnownPartition(int64_t i);
201 
205  int64_t getKnownLabel(int64_t i);
206 
208  double ** getPostProba();
209 
210 
211  //--------
212  // compute
213  //--------
214 
218  int64_t computeLabel(int64_t i0);
219 
223  int64_t computeLabel(Sample * x);
224 
225 
226  //------
227  // algo
228  //------
229 
231  void MAPstep();
232 
234  void Estep();
235 
237  void Mstep();
238 
240  void Sstep();
241 
243  void Cstep();
244 
245 
246  //-----
247  // init
248  //-----
249 
251  void initRANDOM(int64_t nbTry);
252 
255  bool * tabIndividualCanBeUsedForInitRandom, bool * tabClusterToInitialize);
256 
258  void initUSER(Parameter * initParameter);
259 
261  void initUSER_PARTITION(Partition * initPartition, int64_t nbTryInInit = defaultNbTryInInit);
262 
263  // set name of the algorithm
264  void setParameter(Parameter * parameter);
265 
266  // set name of the algorithm
267  void setAlgoName(AlgoName algoName);
268 
269  AlgoName getAlgoName();
270 
271  // set an error for the model
272  void setError(Exception& errorType);
273 
275  void FixKnownPartition(Partition *& y);
276 
277  // edit debug information
278  void editDebugInformation();
279  void editFik();
280  void editCik();
281  void editTik();
282  void editNk();
283 
284 protected:
285 
287  ModelType * _modelType;
288 
290  int64_t _nbCluster;
291 
293  int64_t _nbSample;
294 
296  Data * _data;
297  bool _deleteData;
298 
300  Parameter * _parameter;
301 
304  double ** _tabFik;
305 
307  double * _tabSumF;
308 
311  double ** _tabTik;
312 
315  int64_t ** _tabZikKnown;
316 
325  double ** _tabCik;
326 
327 
329  bool * _tabZiKnown;
330 
331 
333  double * _tabNk;
334 
335  // name of the algorithm
336  AlgoName _algoName;
337 
338  // Error handler
339  Error _error;
340 };
341 
342 //--------------
343 //inline methods
344 //--------------
345 
346 inline bool * Model::getTabZiKnown() {
347  return _tabZiKnown;
348 }
349 
350 inline int64_t ** Model::getTabZikKnown() {
351  return _tabZikKnown;
352 }
353 
354 inline double ** Model::getTabCik() {
355  return _tabCik;
356 }
357 
358 inline double ** Model::getTabTik() {
359  return _tabTik;
360 }
361 
362 inline double ** Model::getTabFik() {
363  return _tabFik;
364 }
365 
366 inline double * Model::getTabSumF() {
367  return _tabSumF;
368 }
369 
370 inline double * Model::getTabNk() {
371  return _tabNk;
372 }
373 
374 inline int64_t Model::getNbCluster() {
375  return _nbCluster;
376 }
377 
378 inline Data * Model::getData() {
379  return _data;
380 }
381 
383  return _data->getGaussianData();
384 }
385 
387  return _data->getBinaryData();
388 }
389 
391  return _parameter;
392 }
393 
394 inline GaussianParameter * Model::getGaussianParameter() {
395  return _parameter->getGaussianParameter();
396 }
397 
398 inline BinaryParameter * Model::getBinaryParameter() {
399  return _parameter->getBinaryParameter();
400 }
401 
402 inline int64_t Model::getNbSample() {
403  return _nbSample;
404 }
405 
406 inline double ** Model::getPostProba() {
407  return _tabTik;
408 }
409 
410 inline ModelType * const & Model::getModelType() const {
411  return _modelType;
412 }
413 
415  return _error.getError();
416 }
417 
418 }
419 
420 #endif
int64_t ** getTabZikKnown()
Selector.
Definition: Model.h:350
Base class for ModelType(s)
Definition: ModelType.h:37
int64_t getNbCluster()
Selector.
Definition: Model.h:374
double getLogN()
Selector.
Definition: Model.cpp:267
int64_t computeLabel(int64_t i0)
Compute the label of the i0-th point of the sample.
Definition: Model.cpp:682
void Sstep()
Stochastic classification step method.
Definition: Model.cpp:1298
void initUSER_PARTITION(Partition *initPartition, int64_t nbTryInInit=defaultNbTryInInit)
User partition initialization of the parameters of the model.
Definition: Model.cpp:882
double * getTabNk()
Selector.
Definition: Model.h:370
Base class for XEMBinaryParameter(s)
Definition: BinaryParameter.h:41
Definition: Exception.h:42
Base class for Binary Data.
Definition: BinaryData.h:41
void FixKnownPartition(Partition *&y)
Fix label Known.
Definition: Model.cpp:700
XEMCVBlock.
Definition: Util.h:393
Exception & getErrorType() const
Selector.
Definition: Model.h:414
double ** getTabTik()
Selector.
Definition: Model.h:358
double getEntropy()
Compute the entropy.
Definition: Model.cpp:533
Base class for Error(s)
int64_t getLabelByMAPOrKnownPartition(int64_t i)
Definition: Model.cpp:398
AlgoName
Enumeration of Algo type.
Definition: Util.h:319
double ** getTabFik()
Selector.
Definition: Model.h:362
int64_t getFreeParameter()
return the number of free parameters
Definition: Model.cpp:634
Base class for Error(s)
Definition: Error.h:42
Base class for Partition(s)
Definition: Partition.h:39
int64_t getNbSample()
Selector.
Definition: Model.h:402
double getCompletedLogLikelihoodOrLogLikelihood()
Definition: Model.cpp:497
Definition: Model.h:50
Model()
Default constructor.
Definition: Model.cpp:51
virtual BinaryData * getBinaryData()
Definition: Data.h:72
double getLogLikelihood(bool fikMustBeComputed)
Compute the log-likelihood.
Definition: Model.cpp:464
Base class for XEMGaussianParameter(s)
Definition: GaussianParameter.h:42
int64_t getKnownLabel(int64_t i)
Definition: Model.cpp:319
void computeFik()
compute _fik
Definition: Model.cpp:579
Constants definitions, various utilities to describe models, and others...
void Estep()
Expectation step method.
Definition: Model.cpp:1234
Base class for Sample.
Definition: Sample.h:41
double ** getPostProba()
getPostProba
Definition: Model.h:406
bool * getTabZiKnown()
getTabZikKnown
Definition: Model.h:346
double * getTabSumF()
return _tabSumF
Definition: Model.h:366
double getLogLikelihoodOne()
Compute the log-likelihood with one cluster.
Definition: Model.cpp:457
Base class for Gaussian Data.
Definition: GaussianData.h:37
void Mstep()
Maximization step method.
Definition: Model.cpp:1280
void randomForInitRANDOMorUSER_PARTITION(bool *tabIndividualCanBeUsedForInitRandom, bool *tabClusterToInitialize)
random step for init RANDOM or USER_PARTITION
Definition: Model.cpp:814
void computeNk()
Compute the number of points in each class.
Definition: Model.cpp:603
Base class for Data.
Definition: Data.h:43
void initUSER(Parameter *initParameter)
User initialization of the parameters of the model.
Definition: Model.cpp:850
virtual Exception const & getError() const
Definition: Exception.h:57
BinaryData * getBinaryData()
Return Binary data.
Definition: Model.h:386
virtual ~Model()
Destructor.
Definition: Model.cpp:199
GaussianData * getGaussianData()
Return Gaussian data.
Definition: Model.h:382
Base class for XEMParameter(s)
Definition: Parameter.h:45
void initRANDOM(int64_t nbTry)
Random center initialization of the parameters of the model.
Definition: Model.cpp:751
void Cstep()
Classification step method.
Definition: Model.cpp:1360
double getCompletedLogLikelihood()
Compute the completed log-likelihood.
Definition: Model.cpp:514
ModelType *const & getModelType() const
Selector.
Definition: Model.h:410
Data * getData()
Selector.
Definition: Model.h:378
void getLabelAndPartitionByMAPOrKnownPartition(int64_t *label, int64_t **partition)
Definition: Model.cpp:339
virtual GaussianData * getGaussianData()
Definition: Data.h:65
void MAPstep()
Maximum a posteriori step method.
Definition: Model.cpp:1215
Parameter * getParameter()
Selector.
Definition: Model.h:390