C++ main module for mmsd Package  1.0
MMSD_Cluster.h
Go to the documentation of this file.
1 #ifndef MMSD_Cluster_H
2 #define MMSD_Cluster_H
3 
4 
5 #include "MMSD_Object.h"
6 
7 #include "MMSD_Law.h"
8 #include "MMSD_DoubleVector.h"
10 #include "STAT_GammaDistribution.h"
11 
36 class MMSD_Cluster : public virtual MMSD_Object {
37  SP_OBJECT(MMSD_Cluster);
38  // ATTRIBUTES
39 
40 private:
41  // type of initilizatio of the weight
42  static const tFlag CONSTANT_WEIGHT_INITIALIZATION;
43  static const tFlag GAMMA_WEIGHT_INITIALIZATION;
44  static const double EMPTY_LIMIT;
45 
46  tFlag mWeightInitializationType;
47  double mWeightShapeInitialization;
48  double mWeightRateInitialization;
49 
50  // weights of property p in [0,P[ in sample i in [0,N[, size N x P
51  MMSD_DoubleFullMatrix mWeights;
52 
53  // freedom degree of the properties p in [0,P[ of size P
54  // to store for backup
55  MMSD_DoubleVector mFreedomDegrees;
56  double mMaxFreedomDegreeValue;
57 
58 
59  // true if the cluster is empty
60  // depending on mRate
61  tBoolean mIsEmpty;
62 
63  // rate of the cluster
64  // store for backup
65  double mRate;
66 
67  //laws of the cluster
68  SP::MMSD_Law mLaw;
69 
70 
71 protected:
72  // METHODS
73 
74  // CONSTRUCTORS
75 
77  MMSD_Cluster(void);
78 
79 
80 
81  // DESTRUCTORS
82 
83 
86  virtual ~MMSD_Cluster(void);
87 
88 
89 
90 public:
91  //----------------
92  // NEW constructors
93  // ---------------
94 
95 
96  // -----------------
97  // SET & GET Methods
98  // -----------------
99 public:
100 
108  inline void setWeightInitializationType(const tString& type,
109  const double& shape,
110  const double& rate) {
111 
113  if (t.compare("gamma")==0) {
114  setWeightInitializationType(GAMMA_WEIGHT_INITIALIZATION,
115  shape,rate);
116  } else {
117  setWeightInitializationType(CONSTANT_WEIGHT_INITIALIZATION,
118  shape,rate);
119  }
120  }
121 
128  inline void setWeightInitializationType(const tFlag& t,
129  const double& shape,
130  const double& rate) {
131  mWeightInitializationType=t;
132  mWeightShapeInitialization=shape;
133  mWeightRateInitialization=rate;
134 
135  }
139  inline void setWeightInitializationType(const tFlag& t) {
141  }
142 
148  inline void setMaxFreedomDegreeValue(const double& v) {
149  mMaxFreedomDegreeValue=v;
150  }
153  inline double getMaxFreedomDegreeValue() const {
154  return mMaxFreedomDegreeValue;
155  }
156 
159  inline double getRate() const {
160  return mRate;
161  }
162 
165  inline const MMSD_DoubleFullMatrix& getWeights() const {
166  return mWeights;
167  };
168 
171  inline const MMSD_DoubleVector& getFreedomDegrees() const {
172  return mFreedomDegrees;
173  };
174 
175 
178  inline void setLaw(SP::MMSD_Law law) {
179  mLaw=law;
180  }
183  inline const MMSD_Law* getLaw() const {
184  return mLaw.get();
185  };
186 
187 
190  inline tBoolean isEmpty() const {
191  return mIsEmpty;
192  }
193 
200  virtual void restore(const MMSD_DoubleFullMatrix& properties);
201 
215  virtual void initialize(const int& clusterIndex,
216  const MMSD_IntegerVector& clusterIndexSamples,
217  const MMSD_DoubleFullMatrix& properties);
218 
219 
223  void updateRate(const MMSD_DoubleVector& clusterProbabilitiesSamples);
224 
225 
228  void updateWeights(const MMSD_DoubleVector& probs) {
229  updateWeights(mLaw->getPropertiesMatrixMultByCovarianceDecompositionMatrix(),
230  mLaw->getCovarianceDecompositionMatrix(),
231  mLaw->getCovarianceDecompositionDiagonal(),
232  mLaw->getMean(),
233  mFreedomDegrees,
234  probs,
235  mWeights);
236  }
237 
240  void updateLaw(const MMSD_DoubleFullMatrix& properties,const MMSD_DoubleVector& probs) {
241  mLaw->optimizeParameters(mWeights,probs,properties);
242  }
243 
247  updateFreedomDegrees(mWeights,probs,mMaxFreedomDegreeValue,
248  mFreedomDegrees);
249  }
250 
251 
254  inline void sort() {
255  mLaw->sort(mFreedomDegrees);
256  };
257 
260  void computeMultivariateDensity(double* Pk) const {
261  computeMultivariateDensity(mLaw->getPropertiesMatrixMultByCovarianceDecompositionMatrix(),
262  mLaw->getCovarianceDecompositionMatrix(),
263  mLaw->getCovarianceDecompositionDiagonal(),
264  mLaw->getMean(),
265  mFreedomDegrees,
266  Pk);
267 
268  };
272  Pk.setSize(mLaw->getPropertiesMatrixMultByCovarianceDecompositionMatrix().getRowsNumber());
273 
274  computeMultivariateDensity(mLaw->getPropertiesMatrixMultByCovarianceDecompositionMatrix(),
275  mLaw->getCovarianceDecompositionMatrix(),
276  mLaw->getCovarianceDecompositionDiagonal(),
277  mLaw->getMean(),
278  mFreedomDegrees,
279  Pk.getValues());
280 
281  };
282 
283 
284 protected:
296  virtual void computeMultivariateDensity(const MMSD_DoubleFullMatrix& YP, //size N x P
297  const MMSD_DoubleFullMatrix& P, // size P x P
298  const MMSD_DoubleVector& D, // size P
299  const MMSD_DoubleVector& mean, // size P
300  const MMSD_DoubleVector& nu, // size P
301  double* Pk) const=0;
302 
313  virtual void updateWeights(const MMSD_DoubleFullMatrix& YP, // N x P
314  const MMSD_DoubleFullMatrix& P, // P x P
315  const MMSD_DoubleVector& D, // P
316  const MMSD_DoubleVector& mean, // P
317  const MMSD_DoubleVector& nu, // P
318  const MMSD_DoubleVector& probs, // N
319  MMSD_DoubleFullMatrix& W) const=0;
320 
329  virtual void updateFreedomDegrees(const MMSD_DoubleFullMatrix& W,
330  const MMSD_DoubleVector& probs,
331  const double& maxFD,
332  MMSD_DoubleVector& nus)=0;
333 
334  // ------------------------------
335  // SAVER & LOADER for UI class
336  // ------------------------------
339  virtual void saveToUIClass(UI_Class& mclass) const;
340 
343  virtual void loadFromUIClass(const UI_Class& mclass);
344 
345  // ----------------------
346  // String representation
347  // ----------------------
348 public:
351  virtual tString toString() const {
353  return ret;
354  };
355 
356 
357 };
358 
359 #endif
double getRate() const
get rate of the cluster which is the percent of samples in this cluster.
Definition: MMSD_Cluster.h:159
void updateLaw(const MMSD_DoubleFullMatrix &properties, const MMSD_DoubleVector &probs)
update the law parameters
Definition: MMSD_Cluster.h:240
double getMaxFreedomDegreeValue() const
get the max freedom degree value
Definition: MMSD_Cluster.h:153
const MMSD_DoubleVector & getFreedomDegrees() const
get the freedom degree of property of size P
Definition: MMSD_Cluster.h:171
void updateFreedomDegrees(const MMSD_DoubleVector &probs)
update the freedom degrees
Definition: MMSD_Cluster.h:246
This class describes the FullMatrix class.
Definition: MMSD_DoubleFullMatrix.h:17
virtual tString toString() const
turn the class into string
Definition: MMSD_Cluster.h:351
This class describes the main interface class for a soft user interface (R,matlab,python etc...) class.
Definition: UI_Class.h:38
void sort()
sort the freedom degrees with respect to the law
Definition: MMSD_Cluster.h:254
virtual void restore(const MMSD_DoubleFullMatrix &properties)
restore the unstored values after a backup
Definition: MMSD_Cluster.cpp:72
DEFINE_SVPTR(MMSD_Cluster)
void toLower()
turn the string to lower case
Definition: CORE_String.h:295
#define tBoolean
Definition: types.h:48
void setWeightInitializationType(const tFlag &t, const double &shape, const double &rate)
set the weight initialization type
Definition: MMSD_Cluster.h:128
void setWeightInitializationType(const tFlag &t)
set the weight initialization type
Definition: MMSD_Cluster.h:139
void setLaw(SP::MMSD_Law law)
set the law
Definition: MMSD_Cluster.h:178
MMSD_Cluster(void)
create an object
Definition: MMSD_Cluster.cpp:14
void setMaxFreedomDegreeValue(const double &v)
set the max freedom degree value
Definition: MMSD_Cluster.h:148
Definition: MMSD_DoubleVector.h:16
const MMSD_Law * getLaw() const
get the law
Definition: MMSD_Cluster.h:183
virtual const T * getValues() const
get the values for reading
Definition: LAP_Vector.h:497
virtual void initialize(const int &clusterIndex, const MMSD_IntegerVector &clusterIndexSamples, const MMSD_DoubleFullMatrix &properties)
initialize the cluster
Definition: MMSD_Cluster.cpp:85
Definition: MMSD_IntegerVector.h:15
tBoolean isEmpty() const
return true is the cluster is empty
Definition: MMSD_Cluster.h:190
void setWeightInitializationType(const tString &type, const double &shape, const double &rate)
set the weight initialization type
Definition: MMSD_Cluster.h:108
virtual ~MMSD_Cluster(void)
destroy an object.
Definition: MMSD_Cluster.cpp:25
void computeMultivariateDensity(double *Pk) const
compute the probabities of samples to be in cluster This
Definition: MMSD_Cluster.h:260
void updateRate(const MMSD_DoubleVector &clusterProbabilitiesSamples)
update the rate of the cluster
Definition: MMSD_Cluster.cpp:152
#define tString
Definition: types.h:49
void computeMultivariateDensity(MMSD_DoubleVector &Pk) const
compute the probabities of samples to be in cluster This
Definition: MMSD_Cluster.h:271
DEFINE_SPTR(MMSD_Cluster)
virtual void loadFromUIClass(const UI_Class &mclass)
how to load the object from a Meta Model class
Definition: MMSD_Cluster.cpp:50
This class is a geneal MMSD Cluster.
Definition: MMSD_Cluster.h:36
virtual void saveToUIClass(UI_Class &mclass) const
how to save the object from a mate model class
Definition: MMSD_Cluster.cpp:27
void updateWeights(const MMSD_DoubleVector &probs)
update the weights of the cluster
Definition: MMSD_Cluster.h:228
This class is a geneal MMSD Law.
Definition: MMSD_Law.h:33
virtual tString toString() const
return the string representation of the object node
Definition: CORE_Object.cpp:102
const MMSD_DoubleFullMatrix & getWeights() const
get the weight of sample 's property of size NxP
Definition: MMSD_Cluster.h:165
void setSize(const tLVectorIndex &n)
set the view to [0,n[ by 1 increment if values is too small, re-alocate it
Definition: LAP_Vector.h:360
This class is the base class of all Mixture of Multiple Scaled Distribution package.
Definition: MMSD_Object.h:20
#define tFlag
Definition: types.h:14