mog_generic.h
Go to the documentation of this file.
#ifndef MOG_GENERIC_H
#define MOG_GENERIC_H
#include <itpp/base/vec.h>
#include <itpp/base/mat.h>
#include <itpp/base/array.h>
#include <itpp/itexports.h>
#include <itpp/base/base_exports.h>
namespace itpp
{
class ITPP_EXPORT MOG_generic
{
public:
MOG_generic() { init(); }
MOG_generic(const std::string &name_in) { load(name_in); }
MOG_generic(const int &K_in, const int &D_in, bool full_in = false) { init(K_in, D_in, full_in); }
MOG_generic(Array<vec> &means_in, bool full_in = false) { init(means_in, full_in); }
MOG_generic(Array<vec> &means_in, Array<vec> &diag_covs_in, vec &weights_in) { init(means_in, diag_covs_in, weights_in); }
MOG_generic(Array<vec> &means_in, Array<mat> &full_covs_in, vec &weights_in) { init(means_in, full_covs_in, weights_in); }
virtual ~MOG_generic() { cleanup(); }
void init();
void init(const int &K_in, const int &D_in, bool full_in = false);
void init(Array<vec> &means_in, bool full_in = false);
void init(Array<vec> &means_in, Array<vec> &diag_covs_in, vec &weights_in);
void init(Array<vec> &means_in, Array<mat> &full_covs_in, vec &weights_in);
virtual void cleanup();
bool is_valid() const { return valid; }
bool is_full() const { return full; }
int get_K() const { if (valid) return(K); else return(0); }
int get_D() const { if (valid) return(D); else return(0); }
vec get_weights() const { vec tmp; if (valid) { tmp = weights; } return tmp; }
Array<vec> get_means() const { Array<vec> tmp; if (valid) { tmp = means; } return tmp; }
Array<vec> get_diag_covs() const { Array<vec> tmp; if (valid && !full) { tmp = diag_covs; } return tmp; }
Array<mat> get_full_covs() const { Array<mat> tmp; if (valid && full) { tmp = full_covs; } return tmp; }
void set_means(Array<vec> &means_in);
void set_diag_covs(Array<vec> &diag_covs_in);
void set_full_covs(Array<mat> &full_covs_in);
void set_weights(vec &weights_in);
void set_means_zero();
void set_diag_covs_unity();
void set_full_covs_unity();
void set_weights_uniform();
void set_checks(bool do_checks_in) { do_checks = do_checks_in; }
void set_paranoid(bool paranoid_in) { paranoid = paranoid_in; }
virtual void load(const std::string &name_in);
virtual void save(const std::string &name_in) const;
virtual void join(const MOG_generic &B_in);
virtual void convert_to_diag();
virtual void convert_to_full();
virtual double log_lhood_single_gaus(const vec &x_in, const int k);
virtual double log_lhood(const vec &x_in);
virtual double lhood(const vec &x_in);
virtual double avg_log_lhood(const Array<vec> &X_in);
protected:
bool do_checks;
bool valid;
bool full;
bool paranoid;
int K;
int D;
Array<vec> means;
Array<vec> diag_covs;
Array<mat> full_covs;
vec weights;
double log_max_K;
vec log_det_etc;
vec log_weights;
Array<mat> full_covs_inv;
Array<vec> diag_covs_inv_etc;
bool check_size(const vec &x_in) const;
bool check_size(const Array<vec> &X_in) const;
bool check_array_uniformity(const Array<vec> & A) const;
void set_means_internal(Array<vec> &means_in);
void set_diag_covs_internal(Array<vec> &diag_covs_in);
void set_full_covs_internal(Array<mat> &full_covs_in);
void set_weights_internal(vec &_weigths);
void set_means_zero_internal();
void set_diag_covs_unity_internal();
void set_full_covs_unity_internal();
void set_weights_uniform_internal();
void convert_to_diag_internal();
void convert_to_full_internal();
virtual void setup_means();
virtual void setup_covs();
virtual void setup_weights();
virtual void setup_misc();
virtual double log_lhood_single_gaus_internal(const vec &x_in, const int k);
virtual double log_lhood_internal(const vec &x_in);
virtual double lhood_internal(const vec &x_in);
private:
vec tmpvecD;
vec tmpvecK;
};
} // namespace itpp
#endif // #ifndef MOG_GENERIC_H
array.h
Definition of Array class (container)
base_exports.h
Import/Export definitions for some templates defined in base folder.
itpp::Array
General array class.
Definition array.h:105
itpp::MOG_generic
Generic Mixture of Gaussians (MOG) class. Used as a base for other MOG classes.
Definition mog_generic.h:58
itpp::MOG_generic::full_covs_inv
Array< mat > full_covs_inv
Pre-calcuated inverted version of each full covariance matrix.
Definition mog_generic.h:323
itpp::MOG_generic::set_checks
void set_checks(bool do_checks_in)
Enable/disable internal checks for likelihood functions.
Definition mog_generic.h:214
itpp::MOG_generic::full_covs
Array< mat > full_covs
full covariance matrices
Definition mog_generic.h:304
itpp::MOG_generic::get_K
int get_K() const
Return the number of Gaussians.
Definition mog_generic.h:160
itpp::MOG_generic::MOG_generic
MOG_generic(Array< vec > &means_in, Array< vec > &diag_covs_in, vec &weights_in)
Construct a model using user supplied parameters (diagonal covariance version)
Definition mog_generic.h:96
itpp::MOG_generic::get_means
Array< vec > get_means() const
Obtain a copy of the array of mean vectors.
Definition mog_generic.h:169
itpp::MOG_generic::MOG_generic
MOG_generic(const std::string &name_in)
Construct the MOG_generic object by loading the parameters from a model file.
Definition mog_generic.h:72
itpp::MOG_generic::MOG_generic
MOG_generic(Array< vec > &means_in, bool full_in=false)
Construct a model using user supplied mean vectors.
Definition mog_generic.h:88
itpp::MOG_generic::do_checks
bool do_checks
indicates whether checks on input data are done
Definition mog_generic.h:280
itpp::MOG_generic::K
int K
number of gaussians
Definition mog_generic.h:292
itpp::MOG_generic::get_diag_covs
Array< vec > get_diag_covs() const
Obtain a copy of the array of diagonal covariance vectors.
Definition mog_generic.h:172
itpp::MOG_generic::get_weights
vec get_weights() const
Obtain a copy of the weight vector.
Definition mog_generic.h:166
itpp::MOG_generic::get_D
int get_D() const
Return the dimensionality.
Definition mog_generic.h:163
itpp::MOG_generic::MOG_generic
MOG_generic(Array< vec > &means_in, Array< mat > &full_covs_in, vec &weights_in)
Construct a model using user supplied parameters (full covariance version)
Definition mog_generic.h:104
itpp::MOG_generic::MOG_generic
MOG_generic(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)
Definition mog_generic.h:79
itpp::MOG_generic::valid
bool valid
indicates whether the parameters are valid
Definition mog_generic.h:283
itpp::MOG_generic::weights
vec weights
weights
Definition mog_generic.h:307
itpp::MOG_generic::diag_covs
Array< vec > diag_covs
diagonal covariance matrices, stored as vectors
Definition mog_generic.h:301
itpp::MOG_generic::is_valid
bool is_valid() const
Returns true if the model's parameters are valid.
Definition mog_generic.h:154
itpp::MOG_generic::D
int D
dimensionality
Definition mog_generic.h:295
itpp::MOG_generic::is_full
bool is_full() const
Returns true if the model has full covariance matrices.
Definition mog_generic.h:157
itpp::MOG_generic::diag_covs_inv_etc
Array< vec > diag_covs_inv_etc
Pre-calcuated inverted version of each diagonal covariance vector, where the covariance elements are ...
Definition mog_generic.h:326
itpp::MOG_generic::log_weights
vec log_weights
Pre-calculated log versions of the weights.
Definition mog_generic.h:320
itpp::MOG_generic::log_det_etc
vec log_det_etc
Gaussian specific pre-calcualted constants.
Definition mog_generic.h:317
itpp::MOG_generic::means
Array< vec > means
means
Definition mog_generic.h:298
itpp::MOG_generic::full
bool full
indicates whether we are using full or diagonal covariance matrices
Definition mog_generic.h:286
itpp::MOG_generic::MOG_generic
MOG_generic()
Default constructor.
Definition mog_generic.h:67
itpp::MOG_generic::~MOG_generic
virtual ~MOG_generic()
Default destructor.
Definition mog_generic.h:107
itpp::MOG_generic::log_max_K
double log_max_K
Pre-calcualted std::log(std::numeric_limits<double>::max() / K), where K is the number of Gaussians.
Definition mog_generic.h:310
itpp::MOG_generic::set_paranoid
void set_paranoid(bool paranoid_in)
Enable/disable paranoia about numerical stability.
Definition mog_generic.h:219
itpp::MOG_generic::get_full_covs
Array< mat > get_full_covs() const
Obtain a copy of the array of full covariance matrices.
Definition mog_generic.h:175
itpp::MOG_generic::paranoid
bool paranoid
indicates whether we are paranoid about numerical stability
Definition mog_generic.h:289
mat.h
Matrix Class Definitions.
itpp
itpp namespace
Definition itmex.h:37
itpp::full
Mat< T > full(const Sparse_Mat< T > &s)
Convert a sparse matrix s into its dense representation.
Definition smat.h:998
vec.h
Templated Vector Class Definitions.

Generated on Mon Jun 10 2024 11:49:26 for IT++ by Doxygen 1.9.8