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>
36 #include <itpp/base/base_exports.h>
37 
38 namespace itpp
39 {
40 
57 class ITPP_EXPORT MOG_generic
58 {
59 
60 public:
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 
88  MOG_generic(Array<vec> &means_in, bool full_in = false) { init(means_in, full_in); }
89 
96  MOG_generic(Array<vec> &means_in, Array<vec> &diag_covs_in, vec &weights_in) { init(means_in, diag_covs_in, weights_in); }
97 
104  MOG_generic(Array<vec> &means_in, Array<mat> &full_covs_in, vec &weights_in) { init(means_in, full_covs_in, weights_in); }
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 
137  void init(Array<vec> &means_in, Array<vec> &diag_covs_in, vec &weights_in);
138 
145  void init(Array<vec> &means_in, Array<mat> &full_covs_in, vec &weights_in);
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 
277 protected:
278 
280  bool do_checks;
281 
283  bool valid;
284 
286  bool full;
287 
289  bool paranoid;
290 
292  int K;
293 
295  int D;
296 
299 
302 
305 
307  vec weights;
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 
379 private:
380  vec tmpvecD;
381  vec tmpvecK;
382 
383 };
384 
385 } // namespace itpp
386 
387 #endif // #ifndef MOG_GENERIC_H
bool is_full() const
Returns true if the model has full covariance matrices.
Definition: mog_generic.h:157
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
Array< mat > get_full_covs() const
Obtain a copy of the array of full covariance matrices.
Definition: mog_generic.h:175
int D
dimensionality
Definition: mog_generic.h:295
Array< vec > get_means() const
Obtain a copy of the array of mean vectors.
Definition: mog_generic.h:169
Array< vec > get_diag_covs() const
Obtain a copy of the array of diagonal covariance vectors.
Definition: mog_generic.h:172
Array< vec > means
means
Definition: mog_generic.h:298
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
void set_paranoid(bool paranoid_in)
Enable/disable paranoia about numerical stability.
Definition: mog_generic.h:219
bool is_valid() const
Returns true if the model&#39;s parameters are valid.
Definition: mog_generic.h:154
Array< mat > full_covs
full covariance matrices
Definition: mog_generic.h:304
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
Definition of Array class (container)
Import/Export definitions for some templates defined in base folder.
Matrix Class Definitions.
vec log_weights
Pre-calculated log versions of the weights.
Definition: mog_generic.h:320
bool full
indicates whether we are using full or diagonal covariance matrices
Definition: mog_generic.h:286
Generic Mixture of Gaussians (MOG) class. Used as a base for other MOG classes.
Definition: mog_generic.h:57
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
bool do_checks
indicates whether checks on input data are done
Definition: mog_generic.h:280
int get_D() const
Return the dimensionality.
Definition: mog_generic.h:163
Mat< T > full(const Sparse_Mat< T > &s)
Convert a sparse matrix s into its dense representation.
Definition: smat.h:998
itpp namespace
Definition: itmex.h:36
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
Array< mat > full_covs_inv
Pre-calcuated inverted version of each full covariance matrix.
Definition: mog_generic.h:323
void set_checks(bool do_checks_in)
Enable/disable internal checks for likelihood functions.
Definition: mog_generic.h:214
MOG_generic(Array< vec > &means_in, bool full_in=false)
Construct a model using user supplied mean vectors.
Definition: mog_generic.h:88
vec log_det_etc
Gaussian specific pre-calcualted constants.
Definition: mog_generic.h:317
bool paranoid
indicates whether we are paranoid about numerical stability
Definition: mog_generic.h:289
int K
number of gaussians
Definition: mog_generic.h:292
vec get_weights() const
Obtain a copy of the weight vector.
Definition: mog_generic.h:166
virtual ~MOG_generic()
Default destructor.
Definition: mog_generic.h:107
bool valid
indicates whether the parameters are valid
Definition: mog_generic.h:283
Array< vec > diag_covs
diagonal covariance matrices, stored as vectors
Definition: mog_generic.h:301
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
vec weights
weights
Definition: mog_generic.h:307
int get_K() const
Return the number of Gaussians.
Definition: mog_generic.h:160
MOG_generic()
Default constructor.
Definition: mog_generic.h:67
Templated Vector Class Definitions.

Generated on Thu Jun 21 2018 16:06:18 for IT++ by Doxygen 1.8.13