C++ main module for mmsd Package  1.0
MMSD_Law.h
Go to the documentation of this file.
1 #ifndef MMSD_Law_H
2 #define MMSD_Law_H
3 
4 
5 #include "MMSD_Object.h"
6 
7 #include "MMSD_DataSet.h"
8 #include "MMSD_DoubleVector.h"
10 
33 class MMSD_Law : public virtual MMSD_Object {
34  SP_OBJECT(MMSD_Law);
35  // ATTRIBUTES
36 
37 private:
38 
39  double mMinEigenValue;
40 
41  // mean vector of size P
42  // store for backup
43  MMSD_DoubleVector mMean;
44 
45  // covariance symmetric matrix of size P x P = tP . D . P
46  // store for backup
48  // store for backup
50 
51  MMSD_DoubleFullMatrix mYP; // Y.mP size N x P
52 
53 protected:
54  // METHODS
55 
56  // CONSTRUCTORS
57 
59  MMSD_Law(void);
60 
61 
62 
63  // DESTRUCTORS
64 
65 
68  virtual ~MMSD_Law(void);
69 
70 
71 
72 public:
73  //----------------
74  // NEW constructors
75  // ---------------
76 
77 
78  // -----------------
79  // SET & GET Methods
80  // -----------------
84  return mYP;
85  };
89  return mP;
90  };
94  return mD;
95  };
98  inline const MMSD_DoubleVector& getMean() const {
99  return mMean;
100  };
101 
102 
107  inline void setMinEigenValue(const double& v) {
108  mMinEigenValue=v;
109  }
114  inline double getMinEigenValue() const {
115  return mMinEigenValue;
116  }
117 
121  virtual tBoolean isOutOfBounds() const;
122 
123  // computations methods
124  // --------------------
125 
130  virtual void restore(const MMSD_DoubleFullMatrix& properties);
131 
147  virtual void initialize(const int& clusterIndex,
148  const int& samplesNumber,
149  const MMSD_IntegerVector& clustersIndex,
150  const MMSD_DoubleFullMatrix& properties);
151 
152 
160  virtual void optimizeParameters(const MMSD_DoubleFullMatrix& weights,
161  const MMSD_DoubleVector& probs,
162  const MMSD_DoubleFullMatrix& Y) {
163  // update mMean
164  updateMean(mP,mYP,weights,probs,
165  mMean);
166  // update mD
167  updateCovarianceDecompositionDiagonal(mP,mYP,mMean,weights,probs,
168  mD);
169  // update mP
170  updateCovarianceDecompositionMatrix(Y,mD,mMean,weights,probs,
171  mP,mYP);
172 
173 
174  }
175 
181  void sort(MMSD_DoubleVector& nus);
182 
183 protected:
192  virtual void updateMean(const MMSD_DoubleFullMatrix& P,
193  const MMSD_DoubleFullMatrix& YP,
194  const MMSD_DoubleFullMatrix& W,
195  const MMSD_DoubleVector& probs,
196  MMSD_DoubleVector& mean)=0;
208  const MMSD_DoubleVector& Diag,
209  const MMSD_DoubleVector& mean,
210  const MMSD_DoubleFullMatrix& W,
211  const MMSD_DoubleVector& probs,
213  MMSD_DoubleFullMatrix& YP)=0;
225  const MMSD_DoubleFullMatrix& YP, // PxP
226  const MMSD_DoubleVector& mean, // P
227  const MMSD_DoubleFullMatrix& W, // NxP
228  const MMSD_DoubleVector& probs, // N
229  MMSD_DoubleVector& D)=0;
230 
231 
232 
233  // ------------------------------
234  // SAVER & LOADER for UI class
235  // ------------------------------
238  virtual void saveToUIClass(UI_Class& mclass) const;
239 
242  virtual void loadFromUIClass(const UI_Class& mclass);
243 
244  // ----------------------
245  // String representation
246  // ----------------------
247 
250  virtual tString toString() const {
252  return ret;
253  }
254 
255 private:
256  // sort methods
259  void swapValues(MMSD_DoubleVector& nus,
260  const int& i,const int&j);
261 
262  /* sort nus & law parameters in indices [from,to]
263  */
264  void quickSort(MMSD_DoubleVector& nus,
265  const int& from,const int& to);
266 };
267 
268 #endif
virtual ~MMSD_Law(void)
destroy an object.
Definition: MMSD_Law.cpp:13
void sort(MMSD_DoubleVector &nus)
sorts the law parameters & the array in argument in order to be to the same order than the D diagonal...
Definition: MMSD_Law.cpp:134
virtual void saveToUIClass(UI_Class &mclass) const
how to save the object from a mate model class
Definition: MMSD_Law.cpp:15
DEFINE_SPTR(MMSD_Law)
virtual tBoolean isOutOfBounds() const
test if the parameters of law are out of bounds ie if (D[i] < mMinEigenValue[i])
Definition: MMSD_Law.cpp:124
This class describes the FullMatrix class.
Definition: MMSD_DoubleFullMatrix.h:17
This class describes the main interface class for a soft user interface (R,matlab,python etc...) class.
Definition: UI_Class.h:38
const MMSD_DoubleFullMatrix & getPropertiesMatrixMultByCovarianceDecompositionMatrix() const
get the properties matrix multiplied by covariance matrix decomposition matrix
Definition: MMSD_Law.h:83
virtual void loadFromUIClass(const UI_Class &mclass)
how to load the object from a Meta Model class
Definition: MMSD_Law.cpp:30
#define tBoolean
Definition: types.h:48
MMSD_Law(void)
create an object
Definition: MMSD_Law.cpp:7
void setMinEigenValue(const double &v)
set the min eigen value available be default 1.e-16 see MMSD_Law::initialize()
Definition: MMSD_Law.h:107
DEFINE_SVPTR(MMSD_Law)
virtual void updateCovarianceDecompositionMatrix(const MMSD_DoubleFullMatrix &Y, const MMSD_DoubleVector &Diag, const MMSD_DoubleVector &mean, const MMSD_DoubleFullMatrix &W, const MMSD_DoubleVector &probs, MMSD_DoubleFullMatrix &P, MMSD_DoubleFullMatrix &YP)=0
updates the matrix P of eigen value decomposition of covariance of Y
virtual void updateMean(const MMSD_DoubleFullMatrix &P, const MMSD_DoubleFullMatrix &YP, const MMSD_DoubleFullMatrix &W, const MMSD_DoubleVector &probs, MMSD_DoubleVector &mean)=0
updates the mean value
virtual void initialize(const int &clusterIndex, const int &samplesNumber, const MMSD_IntegerVector &clustersIndex, const MMSD_DoubleFullMatrix &properties)
initialization of the parameters opf the law
Definition: MMSD_Law.cpp:59
Definition: MMSD_DoubleVector.h:16
const MMSD_DoubleVector & getMean() const
get the mean of the law
Definition: MMSD_Law.h:98
virtual void restore(const MMSD_DoubleFullMatrix &properties)
restore the unstored values after a backup
Definition: MMSD_Law.cpp:50
double getMinEigenValue() const
get the min eigen value available
Definition: MMSD_Law.h:114
const MMSD_DoubleVector & getCovarianceDecompositionDiagonal() const
get the covariance matrix decomposition diagonal
Definition: MMSD_Law.h:93
Definition: MMSD_IntegerVector.h:15
#define tString
Definition: types.h:49
virtual void updateCovarianceDecompositionDiagonal(const MMSD_DoubleFullMatrix &P, const MMSD_DoubleFullMatrix &YP, const MMSD_DoubleVector &mean, const MMSD_DoubleFullMatrix &W, const MMSD_DoubleVector &probs, MMSD_DoubleVector &D)=0
updates the diagonal matrix D of eigen value decomposition of covariance of Y
const MMSD_DoubleFullMatrix & getCovarianceDecompositionMatrix() const
get the covariance matrix decomposition matrix
Definition: MMSD_Law.h:88
virtual void optimizeParameters(const MMSD_DoubleFullMatrix &weights, const MMSD_DoubleVector &probs, const MMSD_DoubleFullMatrix &Y)
optimizes the parameters of the law
Definition: MMSD_Law.h:160
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
This class is the base class of all Mixture of Multiple Scaled Distribution package.
Definition: MMSD_Object.h:20
virtual tString toString() const
turn the class into string
Definition: MMSD_Law.h:250