IT++ Logo
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
itpp::MOG_diag Class Reference

Diagonal Mixture of Gaussians (MOG) class. More...

#include <itpp/stat/mog_diag.h>

Inheritance diagram for itpp::MOG_diag:
itpp::MOG_generic itpp::MOG_diag_EM_sup itpp::MOG_diag_kmeans_sup

Public Member Functions

 MOG_diag ()
 Default constructor.
 
 MOG_diag (const std::string &name)
 Construct the MOG_diag object by loading the parameters from a model file.
 
 MOG_diag (const int &K_in, const int &D_in, bool full_in=false)
 construct a default model (all Gaussians have zero mean and unit variance for all dimensions)
 
 MOG_diag (Array< vec > &means_in, bool)
 Construct a model using user supplied mean vectors.
 
 MOG_diag (Array< vec > &means_in, Array< vec > &diag_covs_in, vec &weights_in)
 Construct a model using user supplied parameters (diagonal covariance version)
 
 MOG_diag (Array< vec > &means_in, Array< mat > &full_covs_in, vec &weights_in)
 Construct a model using user supplied parameters (full covariance version)
 
 ~MOG_diag ()
 Default destructor.
 
void cleanup ()
 Release memory used by the model. The model will be empty.
 
void load (const std::string &name_in)
 Initialise the model by loading the parameters from a model file.
 
void convert_to_full ()
 Do nothing. Present for compatability with the MOG_generic class.
 
double log_lhood_single_gaus (const double *c_x_in, const int k) const
 calculate the log likelihood of C vector c_x_in using only Gaussian k
 
double log_lhood_single_gaus (const vec &x_in, const int k) const
 calculate the log likelihood of IT++ vector x_in using only Gaussian k
 
double log_lhood (const double *c_x_in)
 calculate the log likelihood of C vector c_x_in
 
double log_lhood (const vec &x_in)
 calculate the log likelihood of IT++ vector x_in
 
double lhood (const double *c_x_in)
 calculate the likelihood of C vector c_x_in
 
double lhood (const vec &x_in)
 calculate the likelihood of IT++ vector x_in
 
double avg_log_lhood (const double **c_x_in, int N)
 calculate the average log likelihood of an array of C vectors ( c_x_in )
 
double avg_log_lhood (const Array< vec > &X_in)
 calculate the average log likelihood of an array of IT++ vectors ( X_in )
 
void init ()
 Initialise the model to be empty.
 
void init (const int &K_in, const int &D_in, bool full_in=false)
 initialise the model so that all Gaussians have zero mean and unit variance for all dimensions
 
void init (Array< vec > &means_in, bool full_in=false)
 Initialise the model using user supplied mean vectors.
 
void init (Array< vec > &means_in, Array< vec > &diag_covs_in, vec &weights_in)
 Initialise the model using user supplied parameters (diagonal covariance version)
 
void init (Array< vec > &means_in, Array< mat > &full_covs_in, vec &weights_in)
 Initialise the model using user supplied parameters (full covariance version)
 
bool is_valid () const
 Returns true if the model's parameters are valid.
 
bool is_full () const
 Returns true if the model has full covariance matrices.
 
int get_K () const
 Return the number of Gaussians.
 
int get_D () const
 Return the dimensionality.
 
vec get_weights () const
 Obtain a copy of the weight vector.
 
Array< vec > get_means () const
 Obtain a copy of the array of mean vectors.
 
Array< vec > get_diag_covs () const
 Obtain a copy of the array of diagonal covariance vectors.
 
Array< mat > get_full_covs () const
 Obtain a copy of the array of full covariance matrices.
 
void set_means (Array< vec > &means_in)
 Set the means of the model.
 
void set_diag_covs (Array< vec > &diag_covs_in)
 Set the diagonal covariance vectors of the model.
 
void set_full_covs (Array< mat > &full_covs_in)
 Set the full covariance matrices of the model.
 
void set_weights (vec &weights_in)
 Set the weight vector of the model.
 
void set_means_zero ()
 Set the means in the model to be zero.
 
void set_diag_covs_unity ()
 Set the diagonal covariance vectors to be unity.
 
void set_full_covs_unity ()
 Set the full covariance matrices to be unity.
 
void set_weights_uniform ()
 Set all the weights to 1/K, where K is the number of Gaussians.
 
void set_checks (bool do_checks_in)
 Enable/disable internal checks for likelihood functions.
 
void set_paranoid (bool paranoid_in)
 Enable/disable paranoia about numerical stability.
 
virtual void save (const std::string &name_in) const
 Save the model's parameters to a model file.
 
virtual void join (const MOG_generic &B_in)
 Mathematically join the model with a user supplied model.
 
virtual void convert_to_diag ()
 Convert the model to use diagonal covariances.
 
virtual double log_lhood_single_gaus (const vec &x_in, const int k)
 calculate the log likelihood of vector x_in using only Gaussian k
 

Protected Member Functions

void setup_means ()
 additional processing of mean vectors, done as the last step of mean initialisation
 
void setup_covs ()
 additional processing of covariance vectors/matrices, done as the last step of covariance initialisation
 
void setup_weights ()
 additional processing of the weight vector, done as the last step of weight initialisation
 
void setup_misc ()
 additional processing of miscellaneous parameters, done as the last step of overall initialisation
 
double log_lhood_single_gaus_internal (const double *c_x_in, const int k) const
 ADD DOCUMENTATION HERE.
 
double log_lhood_single_gaus_internal (const vec &x_in, const int k) const
 ADD DOCUMENTATION HERE.
 
double log_lhood_internal (const double *c_x_in)
 ADD DOCUMENTATION HERE.
 
double log_lhood_internal (const vec &x_in)
 ADD DOCUMENTATION HERE.
 
double lhood_internal (const double *c_x_in)
 ADD DOCUMENTATION HERE.
 
double lhood_internal (const vec &x_in)
 ADD DOCUMENTATION HERE.
 
double ** enable_c_access (Array< vec > &A_in)
 Enable C style access to an Array of vectors (vec)
 
int ** enable_c_access (Array< ivec > &A_in)
 Enable C style access to an Array of vectors (ivec)
 
double * enable_c_access (vec &v_in)
 Enable C style access to a vector (vec)
 
int * enable_c_access (ivec &v_in)
 Enable C style access to a vector (ivec)
 
double ** disable_c_access (double **A_in)
 Disable C style access to an Array of vectors (vec)
 
int ** disable_c_access (int **A_in)
 Disable C style access to an Array of vectors (ivec)
 
double * disable_c_access (double *v_in)
 Disable C style access to a vector (vec)
 
int * disable_c_access (int *v_in)
 Disable C style access to a vector (ivec)
 
void zero_all_ptrs ()
 ADD DOCUMENTATION HERE.
 
void free_all_ptrs ()
 ADD DOCUMENTATION HERE.
 
bool check_size (const vec &x_in) const
 Check if vector x_in has the same dimensionality as the model.
 
bool check_size (const Array< vec > &X_in) const
 Check if all vectors in Array X_in have the same dimensionality as the model.
 
bool check_array_uniformity (const Array< vec > &A) const
 Check if all vectors in Array X_in have the same dimensionality.
 
void set_means_internal (Array< vec > &means_in)
 ADD DOCUMENTATION HERE.
 
void set_diag_covs_internal (Array< vec > &diag_covs_in)
 ADD DOCUMENTATION HERE.
 
void set_full_covs_internal (Array< mat > &full_covs_in)
 ADD DOCUMENTATION HERE.
 
void set_weights_internal (vec &_weigths)
 ADD DOCUMENTATION HERE.
 
void set_means_zero_internal ()
 ADD DOCUMENTATION HERE.
 
void set_diag_covs_unity_internal ()
 ADD DOCUMENTATION HERE.
 
void set_full_covs_unity_internal ()
 ADD DOCUMENTATION HERE.
 
void set_weights_uniform_internal ()
 ADD DOCUMENTATION HERE.
 
void convert_to_diag_internal ()
 ADD DOCUMENTATION HERE.
 
void convert_to_full_internal ()
 ADD DOCUMENTATION HERE.
 
virtual double log_lhood_single_gaus_internal (const vec &x_in, const int k)
 ADD DOCUMENTATION HERE.
 

Protected Attributes

double ** c_means
 pointers to the mean vectors
 
double ** c_diag_covs
 pointers to the covariance vectors
 
double ** c_diag_covs_inv_etc
 pointers to the inverted covariance vectors
 
double * c_weights
 pointer to the weight vector
 
double * c_log_weights
 pointer to the log version of the weight vector
 
double * c_log_det_etc
 pointer to the log_det_etc vector
 
bool do_checks
 indicates whether checks on input data are done
 
bool valid
 indicates whether the parameters are valid
 
bool full
 indicates whether we are using full or diagonal covariance matrices
 
bool paranoid
 indicates whether we are paranoid about numerical stability
 
int K
 number of gaussians
 
int D
 dimensionality
 
Array< vec > means
 means
 
Array< vec > diag_covs
 diagonal covariance matrices, stored as vectors
 
Array< mat > full_covs
 full covariance matrices
 
vec weights
 weights
 
double log_max_K
 Pre-calcualted std::log(std::numeric_limits<double>::max() / K), where K is the number of Gaussians.
 
vec log_det_etc
 Gaussian specific pre-calcualted constants.
 
vec log_weights
 Pre-calculated log versions of the weights.
 
Array< mat > full_covs_inv
 Pre-calcuated inverted version of each full covariance matrix.
 
Array< vec > diag_covs_inv_etc
 Pre-calcuated inverted version of each diagonal covariance vector, where the covariance elements are first multiplied by two.
 

Detailed Description

Diagonal Mixture of Gaussians (MOG) class.

Author
Conrad Sanderson

Used for representing a statistical distribution as a convex combination of multi-variate Gaussian functions. Also known as a Gaussian Mixture Model. This class allows loading and saving of the MOG's parameters, as well as calculation of likelihoods. The parameters are set by the user or an optimisation algorithm (for example, see the MOG_diag_EM class).

Note
This class is optimised for diagonal covariance matrices. For speed reasons it uses C style arrays for direct access to memory.

Definition at line 55 of file mog_diag.h.

Constructor & Destructor Documentation

itpp::MOG_diag::MOG_diag ( )
inline

Default constructor.

Note
An empty model is created. The likelihood functions are not useable until the model's parameters are set

Definition at line 65 of file mog_diag.h.

itpp::MOG_diag::MOG_diag ( const std::string &  name)
inline

Construct the MOG_diag object by loading the parameters from a model file.

Parameters
nameThe model's filename

Definition at line 70 of file mog_diag.h.

itpp::MOG_diag::MOG_diag ( const int &  K_in,
const int &  D_in,
bool  full_in = false 
)
inline

construct a default model (all Gaussians have zero mean and unit variance for all dimensions)

Parameters
K_inNumber of Gaussians
D_inDimensionality
full_inIgnored. Present for compatability with the MOG_generic class

Definition at line 77 of file mog_diag.h.

itpp::MOG_diag::MOG_diag ( Array< vec > &  means_in,
bool   
)
inline

Construct a model using user supplied mean vectors.

Parameters
means_inArray of mean vectors
Note
The number of mean vectors specifies the number of Gaussians. The covariance matrices are in effect set equal to the identity matrix. The weights for all Gaussians are the same, equal to 1/K, where K is the number of Gaussians

Definition at line 85 of file mog_diag.h.

itpp::MOG_diag::MOG_diag ( Array< vec > &  means_in,
Array< vec > &  diag_covs_in,
vec &  weights_in 
)
inline

Construct a model using user supplied parameters (diagonal covariance version)

Parameters
means_inArray of mean vectors
diag_covs_inArray of vectors representing diagonal covariances
weights_invector of weights
Note
The number of mean vectors, covariance vectors and weights must be the same

Definition at line 93 of file mog_diag.h.

itpp::MOG_diag::MOG_diag ( Array< vec > &  means_in,
Array< mat > &  full_covs_in,
vec &  weights_in 
)
inline

Construct a model using user supplied parameters (full covariance version)

Parameters
means_inArray of mean vectors
full_covs_inArray of full covariance matrices
weights_invector of weights
Note
The full covariance matrices are converted to be diagonal. The number of mean vectors, covariance matrices and weights must be the same.

Definition at line 102 of file mog_diag.h.

Member Function Documentation

void itpp::MOG_diag::cleanup ( )
inlinevirtual

Release memory used by the model. The model will be empty.

Note
The likelihood functions are not useable until the model's parameters are re-initialised

Reimplemented from itpp::MOG_generic.

Definition at line 111 of file mog_diag.h.

References itpp::MOG_generic::cleanup().

Referenced by itpp::MOG_diag_EM_sup::ml(), and itpp::MOG_diag_kmeans_sup::run().

void itpp::MOG_diag::load ( const std::string &  name_in)
virtual

Initialise the model by loading the parameters from a model file.

Parameters
name_inThe model's filename
Note
If the model file contains a full covariance matrix model, the covariance matrices will be converted to be diagonal after loading.

Reimplemented from itpp::MOG_generic.

Definition at line 277 of file mog_diag.cpp.

References itpp::MOG_generic::convert_to_diag(), itpp::MOG_generic::full, and itpp::MOG_generic::load().

void itpp::MOG_generic::init ( )
inherited

Initialise the model to be empty.

Note
The likelihood functions are not useable until the model's parameters are set

Definition at line 43 of file mog_generic.cpp.

References itpp::MOG_generic::cleanup().

Referenced by itpp::MOG_generic::join(), itpp::MOG_generic::load(), itpp::MOG_diag_EM_sup::ml(), and itpp::MOG_diag_kmeans_sup::run().

void itpp::MOG_generic::init ( const int &  K_in,
const int &  D_in,
bool  full_in = false 
)
inherited

initialise the model so that all Gaussians have zero mean and unit variance for all dimensions

Parameters
K_inNumber of Gaussians
D_inDimensionality
full_inIf true, use full covariance matrices; if false, use diagonal covariance matrices. Default = false.

Definition at line 46 of file mog_generic.cpp.

References itpp::MOG_generic::D, itpp::MOG_generic::do_checks, itpp::MOG_generic::full, it_assert, itpp::MOG_generic::K, itpp::MOG_generic::paranoid, itpp::MOG_generic::set_diag_covs_unity_internal(), itpp::MOG_generic::set_full_covs_unity_internal(), itpp::MOG_generic::set_means_zero_internal(), itpp::MOG_generic::set_weights_uniform_internal(), itpp::MOG_generic::setup_misc(), and itpp::MOG_generic::valid.

void itpp::MOG_generic::init ( Array< vec > &  means_in,
bool  full_in = false 
)
inherited

Initialise the model using user supplied mean vectors.

Parameters
means_inArray of mean vectors
full_inIf true, use full covariance matrices; if false, use diagonal covariance matrices. Default = false.
Note
The number of mean vectors specifies the number of Gaussians. The covariance matrices are set to the identity matrix. The weights for all Gaussians are the same, equal to 1/K, where K is the number of Gaussians

Definition at line 69 of file mog_generic.cpp.

References itpp::MOG_generic::check_array_uniformity(), itpp::MOG_generic::D, itpp::MOG_generic::do_checks, itpp::MOG_generic::full, it_assert, itpp::MOG_generic::K, itpp::MOG_generic::paranoid, itpp::MOG_generic::set_diag_covs_unity_internal(), itpp::MOG_generic::set_full_covs_unity_internal(), itpp::MOG_generic::set_means(), itpp::MOG_generic::set_weights_uniform_internal(), itpp::MOG_generic::setup_misc(), itpp::Array< T >::size(), and itpp::MOG_generic::valid.

void itpp::MOG_generic::init ( Array< vec > &  means_in,
Array< vec > &  diag_covs_in,
vec &  weights_in 
)
inherited

Initialise the model using user supplied parameters (diagonal covariance version)

Parameters
means_inArray of mean vectors
diag_covs_inArray of vectors representing diagonal covariances
weights_invector of weights
Note
The number of mean vectors, covariance vectors and weights must be the same

Definition at line 89 of file mog_generic.cpp.

References itpp::MOG_generic::check_array_uniformity(), itpp::MOG_generic::D, itpp::MOG_generic::do_checks, itpp::MOG_generic::full, it_assert, itpp::MOG_generic::K, itpp::MOG_generic::paranoid, itpp::MOG_generic::set_diag_covs_internal(), itpp::MOG_generic::set_means_internal(), itpp::MOG_generic::set_weights_internal(), itpp::MOG_generic::setup_misc(), itpp::Array< T >::size(), and itpp::MOG_generic::valid.

void itpp::MOG_generic::init ( Array< vec > &  means_in,
Array< mat > &  full_covs_in,
vec &  weights_in 
)
inherited

Initialise the model using user supplied parameters (full covariance version)

Parameters
means_inArray of mean vectors
full_covs_inArray of covariance matrices
weights_invector of weights
Note
The number of mean vectors, covariance matrices and weights must be the same

Definition at line 110 of file mog_generic.cpp.

References itpp::MOG_generic::check_array_uniformity(), itpp::MOG_generic::D, itpp::MOG_generic::do_checks, itpp::MOG_generic::full, it_assert, itpp::MOG_generic::K, itpp::MOG_generic::paranoid, itpp::MOG_generic::set_full_covs_internal(), itpp::MOG_generic::set_means_internal(), itpp::MOG_generic::set_weights_internal(), itpp::MOG_generic::setup_misc(), itpp::Array< T >::size(), and itpp::MOG_generic::valid.

void itpp::MOG_generic::set_means ( Array< vec > &  means_in)
inherited

Set the means of the model.

Note
The number of means must match the number of Gaussians in the model

Definition at line 351 of file mog_generic.cpp.

References itpp::MOG_generic::set_means_internal(), and itpp::MOG_generic::valid.

Referenced by itpp::MOG_generic::init().

void itpp::MOG_generic::set_diag_covs ( Array< vec > &  diag_covs_in)
inherited

Set the diagonal covariance vectors of the model.

Note
The number of diagonal covariance vectors must match the number of Gaussians in the model

Definition at line 365 of file mog_generic.cpp.

References itpp::MOG_generic::set_diag_covs_internal(), and itpp::MOG_generic::valid.

void itpp::MOG_generic::set_full_covs ( Array< mat > &  full_covs_in)
inherited

Set the full covariance matrices of the model.

Note
The number of covariance matrices must match the number of Gaussians in the model

Definition at line 372 of file mog_generic.cpp.

References itpp::MOG_generic::set_full_covs_internal(), and itpp::MOG_generic::valid.

void itpp::MOG_generic::set_weights ( vec &  weights_in)
inherited

Set the weight vector of the model.

Note
The number of elements in the weight vector must match the number of Gaussians in the model

Definition at line 379 of file mog_generic.cpp.

References itpp::MOG_generic::set_weights_internal(), and itpp::MOG_generic::valid.

void itpp::MOG_generic::set_checks ( bool  do_checks_in)
inlineinherited

Enable/disable internal checks for likelihood functions.

Parameters
do_checks_inIf true, checks are enabled; if false, checks are disabled
Note
Disabling checks will provide a speedup in the likelihood functions. Disable them only when you're happy that everything is working correctly.

Definition at line 214 of file mog_generic.h.

void itpp::MOG_generic::set_paranoid ( bool  paranoid_in)
inlineinherited

Enable/disable paranoia about numerical stability.

Parameters
paranoid_inIf true, calculate likelihoods using a safer, but slower method.

Definition at line 219 of file mog_generic.h.

void itpp::MOG_generic::save ( const std::string &  name_in) const
virtualinherited

Save the model's parameters to a model file.

Parameters
name_inThe model's filename

Definition at line 438 of file mog_generic.cpp.

References itpp::it_file::close(), itpp::MOG_generic::diag_covs, itpp::MOG_generic::full, itpp::MOG_generic::full_covs, itpp::MOG_generic::means, itpp::MOG_generic::valid, and itpp::MOG_generic::weights.

void itpp::MOG_generic::join ( const MOG_generic B_in)
virtualinherited

Mathematically join the model with a user supplied model.

\param B_in user supplied model
\note The Arrays of mean vectors and covariance vectors/matrices from the two models
      are simply concatenated, while the weights of the resultant model are a function
      of the original weights and numbers of Gaussians from both models.
      Specifically,

$ w_{new} = [ \alpha \cdot w_{A} ~~~ \beta \cdot w_{B} ]^T $, where $ w_{new} $ is the new weight vector, $ w_{A} $ and $ w_{B} $ are the weight vectors from model A and B, while $ \alpha = K_A / (K_A + KB_in) $ and $ \beta = 1-\alpha $. In turn, $ K_A $ and $ KB_in $ are the numbers of Gaussians in model A and B, respectively.

See On transforming statistical models... for more information.

Definition at line 453 of file mog_generic.cpp.

References itpp::concat(), itpp::MOG_generic::D, itpp::MOG_generic::diag_covs, itpp::MOG_generic::full, itpp::MOG_generic::full_covs, itpp::MOG_generic::get_D(), itpp::MOG_generic::get_diag_covs(), itpp::MOG_generic::get_full_covs(), itpp::MOG_generic::get_K(), itpp::MOG_generic::get_means(), itpp::MOG_generic::get_weights(), itpp::MOG_generic::init(), itpp::MOG_generic::is_full(), itpp::MOG_generic::is_valid(), it_assert, itpp::MOG_generic::K, itpp::MOG_generic::means, itpp::MOG_generic::valid, and itpp::MOG_generic::weights.

void itpp::MOG_generic::convert_to_diag ( )
virtualinherited

Convert the model to use diagonal covariances.

Note
If the model is already diagonal, nothing is done. If the model has full covariance matrices, this results in irreversible information loss (in effect the off-diagonal covariance elements are now zero)

Definition at line 499 of file mog_generic.cpp.

References itpp::MOG_generic::convert_to_diag_internal(), and itpp::MOG_generic::valid.

Referenced by load().

Member Data Documentation

vec itpp::MOG_generic::log_det_etc
protectedinherited

Gaussian specific pre-calcualted constants.

Note
Vector of pre-calculated $ -\frac{D}{2}\log(2\pi) -\frac{1}{2}\log(|\Sigma|) $ for each Gaussian, where $ D $ is the dimensionality and $ |\Sigma| $ is the determinant for the Gaussian's covariance matrix $ \Sigma $.

Definition at line 317 of file mog_generic.h.

Referenced by itpp::MOG_generic::cleanup(), itpp::MOG_generic::log_lhood_single_gaus_internal(), setup_covs(), and itpp::MOG_generic::setup_covs().


The documentation for this class was generated from the following files:
SourceForge Logo

Generated on Sat Jul 6 2013 10:54:35 for IT++ by Doxygen 1.8.2