STK++ 0.9.13
STK::IMixtureModel< Derived > Class Template Reference

Main interface class for mixture models. More...

#include <STK_IMixtureModel.h>

Inheritance diagram for STK::IMixtureModel< Derived >:
Inheritance graph

Public Types

typedef Clust::MixtureTraits< Derived >::Array Array
 
typedef Clust::MixtureTraits< Derived >::Parameters Parameters
 
typedef Array::Type Type
 

Public Member Functions

 ~IMixtureModel ()
 destructor
 
IMixtureModelcreate () const
 create pattern.
 
Array constp_data () const
 
void setData (Array const &data)
 Set the data set.
 
bool initializeStep ()
 This function will be called once the model is created and data is set.
 
void setParametersStep ()
 set the parameters stored in stat_proba_ and release stat_proba_.
 
void finalizeStep ()
 This function will be called once the model is estimated.
 
void initializeModelImpl ()
 default implementation of initializeModelImpl (do nothing)
 
bool initializeStepImpl ()
 default implementation of initializeStepImpl (return true)
 
void finalizeStepImpl ()
 default implementation of finalizeStepImpl (do nothing)
 
template<class Weights >
Type sample (int i, int j, Weights const &tk) const
 
- Public Member Functions inherited from STK::IRecursiveTemplate< Derived >
Derived & asDerived ()
 static cast : return a reference of this with a cast to the derived class.
 
Derived constasDerived () const
 static cast : return a const reference of this with a cast to the derived class.
 
Derived * asPtrDerived ()
 static cast : return a ptr on a Derived of this with a cast to the derived class.
 
Derived constasPtrDerived () const
 static cast : return a ptr on a constant Derived of this with a cast to the derived class.
 
Derived * clone () const
 create a leaf using the copy constructor of the Derived class.
 
Derived * clone (bool isRef) const
 create a leaf using the copy constructor of the Derived class and a flag determining if the clone is a reference or not.
 
- Public Member Functions inherited from STK::IMixtureModelBase
 IMixtureModelBase (int nbCluster)
 default constructor
 
 IMixtureModelBase (IMixtureModelBase const &model)
 copy constructor.
 
 ~IMixtureModelBase ()
 destructor
 
int nbCluster () const
 
int nbSample () const
 
Real lnNbSample () const
 

Protected Member Functions

 IMixtureModel (int nbCluster)
 Default constructor.
 
 IMixtureModel (IMixtureModel const &model)
 copy constructor.
 
void initializeModel ()
 Initialize the model before its first use.
 
- Protected Member Functions inherited from STK::IRecursiveTemplate< Derived >
 IRecursiveTemplate ()
 constructor.
 
 ~IRecursiveTemplate ()
 destructor.
 
- Protected Member Functions inherited from STK::IMixtureModelBase
void setNbSample (int nbSample)
 Set the number of sample of the model.
 

Protected Attributes

Parameters param_
 parameters of the derived mixture model
 

Private Attributes

Array constp_dataij_
 pointer on the data set
 

Detailed Description

template<class Derived>
class STK::IMixtureModel< Derived >

Main interface class for mixture models.

At this level we create the Parameters struct. The call to setData trigger the call to initializeModel which itself trigger a call to initializeModelImpl to the derived class.

The methods to implement in derived classes are

template<class Weights>
Type impute(int i, int j, Weights const& pk) const;
Type rand(int i, int j, int k) const;
Real lnComponentProbability(int i, int k) const;
void randomInit( CArrayXX const* const& p_tik, CPointX const* const& p_tk) ;
bool run( CArrayXX const* const& p_tik, CPointX const* const& p_tk) ;
int computeNbFreeParameters() const;
The MultidimRegression class allows to regress a multidimensional output variable among a multivariat...
double Real
STK fundamental type of Real values.

The pseudo virtual methods to implement if needed in derived classes are

// default implementation (do nothing) provided to all these methods
bool initializeStepImpl(); // return true by default
void initializeModelImpl()
default implementation of initializeModelImpl (do nothing)
void finalizeStepImpl()
default implementation of finalizeStepImpl (do nothing)
bool initializeStepImpl()
default implementation of initializeStepImpl (return true)
See also
IMixtureModelBase, IRecursiveTemplate

Definition at line 93 of file STK_IMixtureModel.h.

Member Typedef Documentation

◆ Array

template<class Derived >
typedef Clust::MixtureTraits<Derived>::Array STK::IMixtureModel< Derived >::Array

Definition at line 96 of file STK_IMixtureModel.h.

◆ Parameters

template<class Derived >
typedef Clust::MixtureTraits<Derived>::Parameters STK::IMixtureModel< Derived >::Parameters

Definition at line 97 of file STK_IMixtureModel.h.

◆ Type

template<class Derived >
typedef Array::Type STK::IMixtureModel< Derived >::Type

Definition at line 98 of file STK_IMixtureModel.h.

Constructor & Destructor Documentation

◆ IMixtureModel() [1/2]

template<class Derived >
STK::IMixtureModel< Derived >::IMixtureModel ( int  nbCluster)
inlineprotected

Default constructor.

Parameters
nbClusterthe number of cluster

Definition at line 104 of file STK_IMixtureModel.h.

107 , p_dataij_(0)
108 {}
IMixtureModelBase(int nbCluster)
default constructor
Parameters param_
parameters of the derived mixture model
Array const * p_dataij_
pointer on the data set

◆ IMixtureModel() [2/2]

template<class Derived >
STK::IMixtureModel< Derived >::IMixtureModel ( IMixtureModel< Derived > const model)
inlineprotected

copy constructor.

  • The Parameter class is copied using the copy constructor.
  • The pointer on the data set is copied as-is. Check if you should not change it on the copied object.
    Parameters
    modelthe model to copy

Definition at line 115 of file STK_IMixtureModel.h.

116 : IMixtureModelBase(model)
117 , param_(model.param_)
118 , p_dataij_(model.p_dataij_)
119 {}

◆ ~IMixtureModel()

template<class Derived >
STK::IMixtureModel< Derived >::~IMixtureModel ( )
inline

destructor

Definition at line 123 of file STK_IMixtureModel.h.

123{}

Member Function Documentation

◆ create()

template<class Derived >
IMixtureModel * STK::IMixtureModel< Derived >::create ( ) const
inline

create pattern.


Definition at line 125 of file STK_IMixtureModel.h.

125{ return new Derived(this->nbCluster());}

References STK::IMixtureModelBase::nbCluster().

◆ finalizeStep()

template<class Derived >
void STK::IMixtureModel< Derived >::finalizeStep ( )
inline

This function will be called once the model is estimated.

perform specific model finalization stuff

Definition at line 151 of file STK_IMixtureModel.h.

151{ this->asDerived().finalizeStepImpl();}
Derived & asDerived()
static cast : return a reference of this with a cast to the derived class.

References STK::IRecursiveTemplate< Derived >::asDerived().

◆ finalizeStepImpl()

template<class Derived >
void STK::IMixtureModel< Derived >::finalizeStepImpl ( )
inline

default implementation of finalizeStepImpl (do nothing)

Definition at line 159 of file STK_IMixtureModel.h.

159{}

◆ initializeModel()

template<class Derived >
void STK::IMixtureModel< Derived >::initializeModel ( )
inlineprotected

Initialize the model before its first use.

This function is triggered when data set is set. In this interface, the initializeModel() method

  • set the number of samples and variables of the mixture model
  • call the derived class implemented method for initialization of the specific model parameters if needed.

Definition at line 180 of file STK_IMixtureModel.h.

181 {
182 // set dimensions
183 this->setNbSample(p_dataij_->sizeRows());
184 this->setNbVariable(p_dataij_->sizeCols());
185 // call specific model initialization stuff
186 this->asDerived().initializeModelImpl();
187 }
void setNbSample(int nbSample)
Set the number of sample of the model.

References STK::IRecursiveTemplate< Derived >::asDerived(), STK::IMixtureModel< Derived >::p_dataij_, and STK::IMixtureModelBase::setNbSample().

Referenced by STK::IMixtureModel< Derived >::setData().

◆ initializeModelImpl()

template<class Derived >
void STK::IMixtureModel< Derived >::initializeModelImpl ( )
inline

default implementation of initializeModelImpl (do nothing)

Definition at line 155 of file STK_IMixtureModel.h.

155{}

◆ initializeStep()

template<class Derived >
bool STK::IMixtureModel< Derived >::initializeStep ( )
inline

This function will be called once the model is created and data is set.

Note
a stk++ mixture create and initialize all the containers when the data is set. Thus the default behavior is return true.

Definition at line 142 of file STK_IMixtureModel.h.

142{ return this->asDerived().initializeStepImpl();}

References STK::IRecursiveTemplate< Derived >::asDerived().

◆ initializeStepImpl()

template<class Derived >
bool STK::IMixtureModel< Derived >::initializeStepImpl ( )
inline

default implementation of initializeStepImpl (return true)

Definition at line 157 of file STK_IMixtureModel.h.

157{ return true;}

◆ p_data()

template<class Derived >
Array const * STK::IMixtureModel< Derived >::p_data ( ) const
inline
Returns
a pointer on the current data set

Definition at line 127 of file STK_IMixtureModel.h.

127{ return p_dataij_;}

References STK::IMixtureModel< Derived >::p_dataij_.

◆ sample()

template<class Derived >
template<class Weights >
Type STK::IMixtureModel< Derived >::sample ( int  i,
int  j,
Weights const tk 
) const
inline
Returns
a simulated value for the jth variable of the ith sample
Parameters
i,jindexes of the data to impute
tkthe probabilities of each class for the ith individual

Definition at line 166 of file STK_IMixtureModel.h.

167 { return this->asDerived().rand(i, j, Law::Categorical::rand(tk));}
virtual int rand() const

References STK::IRecursiveTemplate< Derived >::asDerived(), and STK::Law::Categorical::rand().

◆ setData()

template<class Derived >
void STK::IMixtureModel< Derived >::setData ( Array const data)
inline

Set the data set.

Setting a (new) data set will trigger the initialization process of the model.

Parameters
datathe data set to set

Definition at line 133 of file STK_IMixtureModel.h.

134 {
135 p_dataij_ = &data;
137 }
void initializeModel()
Initialize the model before its first use.

References STK::IMixtureModel< Derived >::initializeModel(), and STK::IMixtureModel< Derived >::p_dataij_.

◆ setParametersStep()

template<class Derived >
void STK::IMixtureModel< Derived >::setParametersStep ( )
inline

set the parameters stored in stat_proba_ and release stat_proba_.

Definition at line 144 of file STK_IMixtureModel.h.

145 {
146 param_.setParametersStep();
147 this->asDerived().setParametersImpl();
148 }

References STK::IRecursiveTemplate< Derived >::asDerived(), and STK::IMixtureModel< Derived >::param_.

Member Data Documentation

◆ p_dataij_

template<class Derived >
Array const* STK::IMixtureModel< Derived >::p_dataij_
private

◆ param_

template<class Derived >
Parameters STK::IMixtureModel< Derived >::param_
protected

parameters of the derived mixture model

Definition at line 189 of file STK_IMixtureModel.h.

Referenced by STK::IMixtureModel< Derived >::setParametersStep().


The documentation for this class was generated from the following file: