mixmod  3.2.0
Mixture models for clustering and classification
 All Classes Namespaces Files Functions Variables Enumerations Friends
Parameter.h
1 /***************************************************************************
2  SRC/mixmod/Kernel/Parameter/Parameter.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 XEMParameter_H
26 #define XEMParameter_H
27 
28 #include "mixmod/Utilities/Util.h"
29 #include "mixmod/Kernel/Model/ModelType.h"
30 
31 namespace XEM {
32 
33 // pre-declaration
34 class Model;
35 class Sample;
36 class Partition;
37 class GaussianParameter;
38 class BinaryParameter;
39 
45 class Parameter {
46 
47 public:
48 
50  Parameter();
51 
53  // called by GaussianParameter or BinaryParameter (called by StrategyType)
54  // if USER initialisation
55  Parameter(int64_t iNbCluster, int64_t iPbDimension, ModelType * iModelType);
56 
58  // called by XEMParameter (called by XEMModel)
59  Parameter(Model * iModel, ModelType * iModelType);
60 
62  Parameter(const Parameter * iParameter);
63 
65  virtual ~Parameter();
66 
67  virtual GaussianParameter* getGaussianParameter() {
68  return (GaussianParameter*)this;
69  }
70 
71  virtual BinaryParameter* getBinaryParameter() {
72  return (BinaryParameter*)this;
73  }
75  virtual bool operator ==(const Parameter & param) const;
76 
78  virtual void reset() = 0;
79 
80  //void initRandomForMeanOrCenter();
81 
85  virtual Parameter * clone()const = 0;
86 
87 
88  //--------
89  // compute
90  //--------
91 
95  virtual double getPdf(int64_t iSample, int64_t kCluster) const = 0;
96 
97  // compute normal probability density function
98  // for all i=1,..,n and k=1,..,K
99  virtual void getAllPdf(double ** tabFik, double * tabProportion) const = 0;
100 
104  virtual double getPdf(Sample * x, int64_t kCluster) const = 0;
105 
106  // computeTabProportion
107  void computeTabProportion();
108 
112  virtual int64_t getFreeParameter() const = 0;
113 
115  virtual double getLogLikelihoodOne() const = 0;
116 
118  virtual void computeTikUnderflow(int64_t i, double ** tabTik);
119 
120 
121  //---------------
122  // initialization
123  //---------------
124 
126  virtual void initUSER(Parameter * iParam) = 0;
127 
128  int64_t generateRandomIndex(bool * tabIndividualCanBeUsedForInitRandom,
129  double * weight, double totalWeight);
130 
132  virtual void initForInitRANDOM() = 0;
133 
134  virtual void updateForInitRANDOMorUSER_PARTITION(
135  Sample ** tabSampleForInit, bool * tabClusterToInitialze) = 0;
136 
141 
142  virtual void initForInitUSER_PARTITION(int64_t & nbInitializedCluster,
143  bool * tabNotInitializedCluster, Partition * initPartition) = 0;
144 
145 
146  //-----------
147  // Algorithms
148  //-----------
149 
151  //virtual void MAPStep() = 0;
152 
154  virtual void MStep() = 0;
155 
156 
157  //-------
158  // in/out
159  //-------
160 
161  // edit (for debug)
162  virtual void edit() = 0;
163 
165  virtual void edit(std::ofstream & oFile, bool text = false) = 0;
166 
168  virtual void input(std::ifstream & fi) = 0;
169 
170 
171  //-------
172  // select
173  //-------
174 
176  double * getTabProportion() const;
177 
179  int64_t getNbCluster() const;
180 
182  int64_t getPbDimension() const;
183 
185  bool getFreeProportion() const;
186 
188  Model * getModel() const;
189 
191  ModelType * getModelType() const;
192 
194  virtual void setModel(Model * iModel);
195 
197  void setModelType(ModelType * iModeltype);
198 
200  const std::string & getFilename() const;
201 
203  void setFilename(const std::string & filename);
204 
206  // utilisé par SMALL_EM, CEM_INIT
207  virtual void recopy(Parameter * otherParameter) = 0;
208 
209  virtual void updateForCV(Model * originalModel, CVBlock & CVBlock) = 0;
210 
212  FormatNumeric::FormatNumericFile getFormat()const;
213 
215  void setFormat(const FormatNumeric::FormatNumericFile format);
216 
217 protected:
218 
220  int64_t _nbCluster;
221 
223  int64_t _pbDimension;
224 
226  double * _tabProportion;
227 
229  bool _freeProportion;
230 
232  Model * _model; // not agregated
233 
235  ModelType * _modelType;
236 
237 private:
238 
240  std::string _filename;
241 
242  FormatNumeric::FormatNumericFile _format;
243 };
244 
245 //---------------
246 // inline methods
247 //---------------
248 
249 inline int64_t Parameter::getNbCluster() const {
250  return _nbCluster;
251 }
252 
253 inline int64_t Parameter::getPbDimension() const {
254  return _pbDimension;
255 }
256 
257 inline double * Parameter::getTabProportion() const {
258  return _tabProportion;
259 }
260 
261 inline bool Parameter::getFreeProportion() const {
262  return _freeProportion;
263 }
264 
265 inline Model * Parameter::getModel() const {
266  return _model;
267 }
268 
269 inline void Parameter::setModel(Model * iModel) {
270  _model = iModel;
271 }
272 
273 inline void Parameter::setModelType(ModelType * iModeltype) {
274  _modelType = iModeltype;
275 }
276 
278  return _modelType;
279 }
280 
281 inline const std::string & Parameter::getFilename() const {
282  return _filename;
283 }
284 
285 inline void Parameter::setFilename(const std::string & filename) {
286  _filename = filename;
287 }
288 
289 inline FormatNumeric::FormatNumericFile Parameter::getFormat() const {
290  return _format;
291 }
292 
293 inline void Parameter::setFormat(const FormatNumeric::FormatNumericFile format) {
294  _format = format;
295 }
296 
297 }
298 
299 #endif
virtual void reset()=0
reset to default values
Definition: Parameter.cpp:128
Base class for ModelType(s)
Definition: ModelType.h:37
int64_t getNbCluster() const
get nbCluster
Definition: Parameter.h:249
double * getTabProportion() const
get TabProportion
Definition: Parameter.h:257
Base class for XEMBinaryParameter(s)
Definition: BinaryParameter.h:41
void setFilename(const std::string &filename)
setFilename
Definition: Parameter.h:285
virtual void MStep()=0
Maximum a posteriori step method.
XEMCVBlock.
Definition: Util.h:393
virtual int64_t getFreeParameter() const =0
Selector.
ModelType * getModelType() const
getModelType
Definition: Parameter.h:277
bool getFreeProportion() const
getFreeProportion
Definition: Parameter.h:261
const std::string & getFilename() const
getFilename
Definition: Parameter.h:281
virtual double getPdf(int64_t iSample, int64_t kCluster) const =0
Model * getModel() const
getModel
Definition: Parameter.h:265
virtual Parameter * clone() const =0
Selector.
void setFormat(const FormatNumeric::FormatNumericFile format)
set FormatNumeric
Definition: Parameter.h:293
Base class for Partition(s)
Definition: Partition.h:39
Definition: Model.h:50
virtual void computeTikUnderflow(int64_t i, double **tabTik)
compute Tik for xi (i=0 -> _nbSample-1) when underflow
Definition: Parameter.cpp:193
Base class for XEMGaussianParameter(s)
Definition: GaussianParameter.h:42
virtual void setModel(Model *iModel)
setModel , made it virtual so that composite paramter class can override it.
Definition: Parameter.h:269
virtual ~Parameter()
Destructor.
Definition: Parameter.cpp:104
Parameter()
Default constructor.
Definition: Parameter.cpp:36
virtual void recopy(Parameter *otherParameter)=0
recopie sans faire construction / destruction
Constants definitions, various utilities to describe models, and others...
virtual bool operator==(const Parameter &param) const
Comparison operator.
Definition: Parameter.cpp:115
virtual void input(std::ifstream &fi)=0
input
virtual void initUSER(Parameter *iParam)=0
init user
Base class for Sample.
Definition: Sample.h:41
virtual void initForInitUSER_PARTITION(int64_t &nbInitializedCluster, bool *tabNotInitializedCluster, Partition *initPartition)=0
virtual double getLogLikelihoodOne() const =0
get loglikelihood with one cluster
int64_t getPbDimension() const
get pbDimension
Definition: Parameter.h:253
virtual void initForInitRANDOM()=0
initialize attributes before an InitRandom
Base class for XEMParameter(s)
Definition: Parameter.h:45
void setModelType(ModelType *iModeltype)
set modeltype
Definition: Parameter.h:273
FormatNumeric::FormatNumericFile getFormat() const
get Format
Definition: Parameter.h:289