IT++ Logo
mog_generic.h
Go to the documentation of this file.
1
29#ifndef MOG_GENERIC_H
30#define MOG_GENERIC_H
31
32#include <itpp/base/vec.h>
33#include <itpp/base/mat.h>
34#include <itpp/base/array.h>
35#include <itpp/itexports.h>
37
38namespace itpp
39{
40
58{
59
60public:
61
67 MOG_generic() { init(); }
68
72 MOG_generic(const std::string &name_in) { load(name_in); }
73
79 MOG_generic(const int &K_in, const int &D_in, bool full_in = false) { init(K_in, D_in, full_in); }
80
89
97
105
107 virtual ~MOG_generic() { cleanup(); }
108
113 void init();
114
120 void init(const int &K_in, const int &D_in, bool full_in = false);
121
129 void init(Array<vec> &means_in, bool full_in = false);
130
138
146
151 virtual void cleanup();
152
154 bool is_valid() const { return valid; }
155
157 bool is_full() const { return full; }
158
160 int get_K() const { if (valid) return(K); else return(0); }
161
163 int get_D() const { if (valid) return(D); else return(0); }
164
166 vec get_weights() const { vec tmp; if (valid) { tmp = weights; } return tmp; }
167
169 Array<vec> get_means() const { Array<vec> tmp; if (valid) { tmp = means; } return tmp; }
170
172 Array<vec> get_diag_covs() const { Array<vec> tmp; if (valid && !full) { tmp = diag_covs; } return tmp; }
173
175 Array<mat> get_full_covs() const { Array<mat> tmp; if (valid && full) { tmp = full_covs; } return tmp; }
176
180 void set_means(Array<vec> &means_in);
181
185 void set_diag_covs(Array<vec> &diag_covs_in);
186
190 void set_full_covs(Array<mat> &full_covs_in);
191
195 void set_weights(vec &weights_in);
196
198 void set_means_zero();
199
201 void set_diag_covs_unity();
202
204 void set_full_covs_unity();
205
207 void set_weights_uniform();
208
214 void set_checks(bool do_checks_in) { do_checks = do_checks_in; }
215
219 void set_paranoid(bool paranoid_in) { paranoid = paranoid_in; }
220
224 virtual void load(const std::string &name_in);
225
229 virtual void save(const std::string &name_in) const;
230
247 virtual void join(const MOG_generic &B_in);
248
256 virtual void convert_to_diag();
257
263 virtual void convert_to_full();
264
266 virtual double log_lhood_single_gaus(const vec &x_in, const int k);
267
269 virtual double log_lhood(const vec &x_in);
270
272 virtual double lhood(const vec &x_in);
273
275 virtual double avg_log_lhood(const Array<vec> &X_in);
276
277protected:
278
281
283 bool valid;
284
286 bool full;
287
290
292 int K;
293
295 int D;
296
299
302
305
308
310 double log_max_K;
311
318
321
324
327
329 bool check_size(const vec &x_in) const;
330
332 bool check_size(const Array<vec> &X_in) const;
333
335 bool check_array_uniformity(const Array<vec> & A) const;
336
338 void set_means_internal(Array<vec> &means_in);
340 void set_diag_covs_internal(Array<vec> &diag_covs_in);
342 void set_full_covs_internal(Array<mat> &full_covs_in);
344 void set_weights_internal(vec &_weigths);
345
347 void set_means_zero_internal();
349 void set_diag_covs_unity_internal();
351 void set_full_covs_unity_internal();
353 void set_weights_uniform_internal();
354
356 void convert_to_diag_internal();
358 void convert_to_full_internal();
359
361 virtual void setup_means();
362
364 virtual void setup_covs();
365
367 virtual void setup_weights();
368
370 virtual void setup_misc();
371
373 virtual double log_lhood_single_gaus_internal(const vec &x_in, const int k);
375 virtual double log_lhood_internal(const vec &x_in);
377 virtual double lhood_internal(const vec &x_in);
378
379private:
380 vec tmpvecD;
381 vec tmpvecK;
382
383};
384
385} // namespace itpp
386
387#endif // #ifndef MOG_GENERIC_H
Definition of Array class (container)
Import/Export definitions for some templates defined in base folder.
General array class.
Definition array.h:105
Generic Mixture of Gaussians (MOG) class. Used as a base for other MOG classes.
Definition mog_generic.h:58
Array< mat > full_covs_inv
Pre-calcuated inverted version of each full covariance matrix.
void set_checks(bool do_checks_in)
Enable/disable internal checks for likelihood functions.
Array< mat > full_covs
full covariance matrices
int get_K() const
Return the number of Gaussians.
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
Array< vec > get_means() const
Obtain a copy of the array of mean vectors.
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
MOG_generic(Array< vec > &means_in, bool full_in=false)
Construct a model using user supplied mean vectors.
Definition mog_generic.h:88
bool do_checks
indicates whether checks on input data are done
int K
number of gaussians
Array< vec > get_diag_covs() const
Obtain a copy of the array of diagonal covariance vectors.
vec get_weights() const
Obtain a copy of the weight vector.
int get_D() const
Return the dimensionality.
MOG_generic(Array< vec > &means_in, Array< mat > &full_covs_in, vec &weights_in)
Construct a model using user supplied parameters (full covariance version)
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
bool valid
indicates whether the parameters are valid
vec weights
weights
Array< vec > diag_covs
diagonal covariance matrices, stored as vectors
bool is_valid() const
Returns true if the model's parameters are valid.
int D
dimensionality
bool is_full() const
Returns true if the model has full covariance matrices.
Array< vec > diag_covs_inv_etc
Pre-calcuated inverted version of each diagonal covariance vector, where the covariance elements are ...
vec log_weights
Pre-calculated log versions of the weights.
vec log_det_etc
Gaussian specific pre-calcualted constants.
Array< vec > means
means
bool full
indicates whether we are using full or diagonal covariance matrices
MOG_generic()
Default constructor.
Definition mog_generic.h:67
virtual ~MOG_generic()
Default destructor.
double log_max_K
Pre-calcualted std::log(std::numeric_limits<double>::max() / K), where K is the number of Gaussians.
void set_paranoid(bool paranoid_in)
Enable/disable paranoia about numerical stability.
Array< mat > get_full_covs() const
Obtain a copy of the array of full covariance matrices.
bool paranoid
indicates whether we are paranoid about numerical stability
Matrix Class Definitions.
itpp namespace
Definition itmex.h:37
Mat< T > full(const Sparse_Mat< T > &s)
Convert a sparse matrix s into its dense representation.
Definition smat.h:998
Templated Vector Class Definitions.

Generated on Tue Aug 17 2021 10:59:15 for IT++ by Doxygen 1.9.8