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

Base class for all Mixture densities. More...

#include <STK_IMixtureDensity.h>

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

Public Types

typedef hidden::MixtureTraits< Derived >::Array Array
 
typedef hidden::MixtureTraits< Derived >::Parameters Parameters
 
typedef hidden::Traits< Array >::Type Type
 

Public Member Functions

 ~IMixtureDensity ()
 destructor
 
int nbCluster () const
 
int nbSample () const
 
Real lnNbSample () const
 
Array const *constp_data () const
 
Parameters constparam () const
 
void setData (Array const &data)
 Set the data set.
 
void setData (Array const &data, int nbRow, int nbCol, bool byRow=true)
 Set the data set and give dimensions.
 
bool initializeStep ()
 This function will be called at the beginning of the estimation process once the model is created and data is set.
 
void setParametersStep ()
 set the parameters obtained with the intermediate results and release the intermediate results.
 
void finalizeStep ()
 This function will be called once the model is estimated.
 
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.
 

Protected Member Functions

 IMixtureDensity (int nbCluster)
 Default constructor.
 
 IMixtureDensity (IMixtureDensity const &model)
 copy constructor.
 
void initializeModel ()
 Initialize the model before its first use.
 
bool initializeStepImpl ()
 default implementation of initializeStepImpl (do nothing and return true)
 
void finalizeStepImpl ()
 default implementation of finalizeStepImpl (do nothing)
 
void setNbSample (int nbSample)
 Set the number of sample of the model (needed by kernel models)
 
- Protected Member Functions inherited from STK::IRecursiveTemplate< Derived >
 IRecursiveTemplate ()
 constructor.
 
 ~IRecursiveTemplate ()
 destructor.
 

Protected Attributes

Parameters param_
 parameters of the derived mixture model.
 

Private Attributes

int nbCluster_
 number of cluster.
 
int nbSample_
 total available samples
 
Array constp_dataij_
 pointer on the data set
 

Detailed Description

template<class Derived>
class STK::IMixtureDensity< Derived >

Base class for all Mixture densities.

Let X be an arbitrary measurable space and let $ \mathbf{x} =\{{\mathbf x}_1,...,{\mathbf x}_n\}$ be n independent vectors in X. If each ${\mathbf x}_i$ arises from a probability distribution with density

\[
   f({\mathbf x}_i|\theta) = \sum_{k=1}^K p_k h({\mathbf x}_{i}| \lambda_{k},\alpha)
 \]

where the $p_k$'s are the mixing proportions, $h(\cdot| \lambda_{k},\alpha)$ denotes a distribution parameterized by $\lambda_k$ and $\alpha$, it is said that we observe a mixture model.

This interface class is the base class for all distributions part of a mixture model.

See also
IMixture, IMixtureBridge, MixtureComposer

At this level the Parameters struct is created.

A call to setData trigger a call to initializeModel which itself trigger a call to initializeModelImpl. This last method can be re-implemented by derived class.

The pseudo virtual methods (needed by IMixtureBridge) to implement in concrete derived classes are

// return an imputed value for (i,j). In case of
template<class Weights>
Type impute(int i, int j, Weights const& pk) const;
// return a random value for (i,j)
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;
void initializeModelImpl();
hidden::Traits< Array >::Type Type
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 re-implement if needed in derived classes are

// default implementation "do nothing" provided to all these methods
bool initializeStepImpl(); // return true by default
void finalizeStepImpl()
default implementation of finalizeStepImpl (do nothing)
bool initializeStepImpl()
default implementation of initializeStepImpl (do nothing and return true)

Definition at line 99 of file STK_IMixtureDensity.h.

Member Typedef Documentation

◆ Array

template<class Derived >
typedef hidden::MixtureTraits<Derived>::Array STK::IMixtureDensity< Derived >::Array

Definition at line 102 of file STK_IMixtureDensity.h.

◆ Parameters

template<class Derived >
typedef hidden::MixtureTraits<Derived>::Parameters STK::IMixtureDensity< Derived >::Parameters

Definition at line 103 of file STK_IMixtureDensity.h.

◆ Type

template<class Derived >
typedef hidden::Traits<Array>::Type STK::IMixtureDensity< Derived >::Type

Definition at line 104 of file STK_IMixtureDensity.h.

Constructor & Destructor Documentation

◆ IMixtureDensity() [1/2]

template<class Derived >
STK::IMixtureDensity< Derived >::IMixtureDensity ( int  nbCluster)
protected

Default constructor.

Parameters
nbClusterthe number of cluster

Definition at line 219 of file STK_IMixtureDensity.h.

222 , nbSample_(0)
223 , p_dataij_(0)
224{}
Parameters param_
parameters of the derived mixture model.
int nbCluster_
number of cluster.
int nbSample_
total available samples
Array const * p_dataij_
pointer on the data set

◆ IMixtureDensity() [2/2]

template<class Derived >
STK::IMixtureDensity< Derived >::IMixtureDensity ( IMixtureDensity< Derived > const model)
protected

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 232 of file STK_IMixtureDensity.h.

233 : param_(model.param_)
234 , nbCluster_(model.nbCluster_)
235 , nbSample_(model.nbSample_)
236 , p_dataij_(model.p_dataij_)
237{}

◆ ~IMixtureDensity()

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

destructor

Definition at line 121 of file STK_IMixtureDensity.h.

121{}

Member Function Documentation

◆ finalizeStep()

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

This function will be called once the model is estimated.

perform specific model finalization stuff

Definition at line 165 of file STK_IMixtureDensity.h.

165{ 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::IMixtureDensity< Derived >::finalizeStepImpl ( )
inlineprotected

default implementation of finalizeStepImpl (do nothing)

Definition at line 197 of file STK_IMixtureDensity.h.

197{/* do nothing*/}

◆ initializeModel()

template<class Derived >
void STK::IMixtureDensity< Derived >::initializeModel ( )
protected

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 of the mixture model
  • call the derived class implemented method
    initializeModelImpl()
    for initialization of the specific model parameters if needed.

Definition at line 272 of file STK_IMixtureDensity.h.

273{
274 // set dimensions
275 this->setNbSample(p_dataij_->sizeRows());
276 // call specific model initialization stuff
277 this->asDerived().initializeModelImpl();
278}
void setNbSample(int nbSample)
Set the number of sample of the model (needed by kernel models)

◆ initializeStep()

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

This function will be called at the beginning of the estimation process 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 155 of file STK_IMixtureDensity.h.

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

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

◆ initializeStepImpl()

template<class Derived >
bool STK::IMixtureDensity< Derived >::initializeStepImpl ( )
inlineprotected

default implementation of initializeStepImpl (do nothing and return true)

Definition at line 195 of file STK_IMixtureDensity.h.

195{ return true;/* do nothing*/}

◆ lnNbSample()

template<class Derived >
Real STK::IMixtureDensity< Derived >::lnNbSample ( ) const
inline
Returns
the Log of the total available observations

Definition at line 128 of file STK_IMixtureDensity.h.

129 { return (nbSample_ <= 0) ? -Arithmetic<Real>::infinity() : std::log((Real)nbSample_);}

References STK::IMixtureDensity< Derived >::nbSample_.

◆ nbCluster()

◆ nbSample()

template<class Derived >
int STK::IMixtureDensity< Derived >::nbSample ( ) const
inline
Returns
the total available observations

Definition at line 126 of file STK_IMixtureDensity.h.

126{ return nbSample_;}

References STK::IMixtureDensity< Derived >::nbSample_.

Referenced by STK::IMixtureDensity< Derived >::setNbSample().

◆ p_data()

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

Definition at line 131 of file STK_IMixtureDensity.h.

131{ return p_dataij_;}

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

◆ param()

template<class Derived >
Parameters const & STK::IMixtureDensity< Derived >::param ( ) const
inline
Returns
a constant reference on the current parameter struct

Definition at line 133 of file STK_IMixtureDensity.h.

133{return param_;}

References STK::IMixtureDensity< Derived >::param_.

◆ sample()

template<class Derived >
template<class Weights >
Type STK::IMixtureDensity< 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 172 of file STK_IMixtureDensity.h.

173 { 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() [1/2]

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

Set the data set.

Setting a (new) data set will trigger the initializeModel() method.

Parameters
datathe data set to set

Definition at line 244 of file STK_IMixtureDensity.h.

245{
246 p_dataij_ = &data;
248}
void initializeModel()
Initialize the model before its first use.

◆ setData() [2/2]

template<class Derived >
void STK::IMixtureDensity< Derived >::setData ( Array const data,
int  nbRow,
int  nbCol,
bool  byRow = true 
)

Set the data set and give dimensions.

Setting a (new) data set will trigger the initializeModel() method.

Parameters
datathe data set to set
nbRownumber of rows of the data set
nbColnumber of columns of the data set
byRowis data vectorized by row or by column ?
Note
this method is used for matrix valued data sets where data are vectorized

Definition at line 254 of file STK_IMixtureDensity.h.

255{
256 p_dataij_ = &data;
258}

◆ setNbSample()

template<class Derived >
void STK::IMixtureDensity< Derived >::setNbSample ( int  nbSample)
inlineprotected

Set the number of sample of the model (needed by kernel models)

Parameters
nbSamplenumber of sample of the model
Note
to use when data set is not available but only the dimensions

Definition at line 203 of file STK_IMixtureDensity.h.

References STK::IMixtureDensity< Derived >::nbSample(), and STK::IMixtureDensity< Derived >::nbSample_.

◆ setParametersStep()

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

set the parameters obtained with the intermediate results and release the intermediate results.

Definition at line 158 of file STK_IMixtureDensity.h.

159 {
160 param_.setParametersStep();
161 this->asDerived().setParametersImpl();
162 }

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

Member Data Documentation

◆ nbCluster_

template<class Derived >
int STK::IMixtureDensity< Derived >::nbCluster_
private

number of cluster.

Definition at line 207 of file STK_IMixtureDensity.h.

Referenced by STK::IMixtureDensity< Derived >::nbCluster().

◆ nbSample_

template<class Derived >
int STK::IMixtureDensity< Derived >::nbSample_
private

◆ p_dataij_

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

pointer on the data set

Definition at line 211 of file STK_IMixtureDensity.h.

Referenced by STK::IMixtureDensity< Derived >::p_data(), and STK::KmmBase< Derived >::setData().

◆ param_

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

parameters of the derived mixture model.

Should be an instance of the STK::ModelParameters struct.

See also
STK::ModelParameters

Definition at line 180 of file STK_IMixtureDensity.h.

Referenced by STK::IMixtureDensity< Derived >::param(), and STK::IMixtureDensity< Derived >::setParametersStep().


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