IT++ Logo
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 
36 
37 namespace itpp
38 {
39 
57 {
58 
59 public:
60 
66  MOG_generic() { init(); }
67 
71  MOG_generic(const std::string &name_in) { load(name_in); }
72 
78  MOG_generic(const int &K_in, const int &D_in, bool full_in = false) { init(K_in, D_in, full_in); }
79 
87  MOG_generic(Array<vec> &means_in, bool full_in = false) { init(means_in, full_in); }
88 
95  MOG_generic(Array<vec> &means_in, Array<vec> &diag_covs_in, vec &weights_in) { init(means_in, diag_covs_in, weights_in); }
96 
103  MOG_generic(Array<vec> &means_in, Array<mat> &full_covs_in, vec &weights_in) { init(means_in, full_covs_in, weights_in); }
104 
106  virtual ~MOG_generic() { cleanup(); }
107 
112  void init();
113 
119  void init(const int &K_in, const int &D_in, bool full_in = false);
120 
128  void init(Array<vec> &means_in, bool full_in = false);
129 
136  void init(Array<vec> &means_in, Array<vec> &diag_covs_in, vec &weights_in);
137 
144  void init(Array<vec> &means_in, Array<mat> &full_covs_in, vec &weights_in);
145 
150  virtual void cleanup();
151 
153  bool is_valid() const { return valid; }
154 
156  bool is_full() const { return full; }
157 
159  int get_K() const { if (valid) return(K); else return(0); }
160 
162  int get_D() const { if (valid) return(D); else return(0); }
163 
165  vec get_weights() const { vec tmp; if (valid) { tmp = weights; } return tmp; }
166 
168  Array<vec> get_means() const { Array<vec> tmp; if (valid) { tmp = means; } return tmp; }
169 
171  Array<vec> get_diag_covs() const { Array<vec> tmp; if (valid && !full) { tmp = diag_covs; } return tmp; }
172 
174  Array<mat> get_full_covs() const { Array<mat> tmp; if (valid && full) { tmp = full_covs; } return tmp; }
175 
179  void set_means(Array<vec> &means_in);
180 
184  void set_diag_covs(Array<vec> &diag_covs_in);
185 
189  void set_full_covs(Array<mat> &full_covs_in);
190 
194  void set_weights(vec &weights_in);
195 
197  void set_means_zero();
198 
200  void set_diag_covs_unity();
201 
203  void set_full_covs_unity();
204 
206  void set_weights_uniform();
207 
213  void set_checks(bool do_checks_in) { do_checks = do_checks_in; }
214 
218  void set_paranoid(bool paranoid_in) { paranoid = paranoid_in; }
219 
223  virtual void load(const std::string &name_in);
224 
228  virtual void save(const std::string &name_in) const;
229 
246  virtual void join(const MOG_generic &B_in);
247 
255  virtual void convert_to_diag();
256 
262  virtual void convert_to_full();
263 
265  virtual double log_lhood_single_gaus(const vec &x_in, const int k);
266 
268  virtual double log_lhood(const vec &x_in);
269 
271  virtual double lhood(const vec &x_in);
272 
274  virtual double avg_log_lhood(const Array<vec> &X_in);
275 
276 protected:
277 
279  bool do_checks;
280 
282  bool valid;
283 
285  bool full;
286 
288  bool paranoid;
289 
291  int K;
292 
294  int D;
295 
298 
301 
304 
306  vec weights;
307 
309  double log_max_K;
310 
317 
320 
323 
326 
328  bool check_size(const vec &x_in) const;
329 
331  bool check_size(const Array<vec> &X_in) const;
332 
334  bool check_array_uniformity(const Array<vec> & A) const;
335 
337  void set_means_internal(Array<vec> &means_in);
339  void set_diag_covs_internal(Array<vec> &diag_covs_in);
341  void set_full_covs_internal(Array<mat> &full_covs_in);
343  void set_weights_internal(vec &_weigths);
344 
353 
358 
360  virtual void setup_means();
361 
363  virtual void setup_covs();
364 
366  virtual void setup_weights();
367 
369  virtual void setup_misc();
370 
372  virtual double log_lhood_single_gaus_internal(const vec &x_in, const int k);
374  virtual double log_lhood_internal(const vec &x_in);
376  virtual double lhood_internal(const vec &x_in);
377 
378 private:
379  vec tmpvecD;
380  vec tmpvecK;
381 
382 };
383 
384 } // namespace itpp
385 
386 #endif // #ifndef MOG_GENERIC_H
SourceForge Logo

Generated on Fri Mar 21 2014 17:14:14 for IT++ by Doxygen 1.8.1.2