SHOGUN  3.2.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GMM.h
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or modify
3  * it under the terms of the GNU General Public License as published by
4  * the Free Software Foundation; either version 3 of the License, or
5  * (at your option) any later version.
6  *
7  * Written (W) 2011 Alesis Novik
8  * Copyright (C) 2011 Berlin Institute of Technology and Max-Planck-Society
9  */
10 #ifndef _GMM_H__
11 #define _GMM_H__
12 
13 #include <shogun/lib/config.h>
14 
15 #ifdef HAVE_LAPACK
16 
19 #include <shogun/lib/common.h>
20 
21 #include <vector>
22 
23 using namespace std;
24 
25 namespace shogun
26 {
40 class CGMM : public CDistribution
41 {
42  public:
44  CGMM();
50  CGMM(int32_t n, ECovType cov_type=FULL);
57  CGMM(vector<CGaussian*> components, SGVector<float64_t> coefficients,
58  bool copy=false);
59  virtual ~CGMM();
60 
62  void cleanup();
63 
70  virtual bool train(CFeatures* data=NULL);
71 
80  float64_t train_em(float64_t min_cov=1e-9, int32_t max_iter=1000,
81  float64_t min_change=1e-9);
82 
93  float64_t train_smem(int32_t max_iter=100, int32_t max_cand=5,
94  float64_t min_cov=1e-9, int32_t max_em_iter=1000,
95  float64_t min_change=1e-9);
96 
102  void max_likelihood(SGMatrix<float64_t> alpha, float64_t min_cov);
103 
108  virtual int32_t get_num_model_parameters();
109 
115  virtual float64_t get_log_model_parameter(int32_t num_param);
116 
118  index_t get_num_components() const;
119 
124  CDistribution* get_component(index_t index) const;
125 
132  virtual float64_t get_log_derivative(
133  int32_t num_param, int32_t num_example);
134 
142  virtual float64_t get_log_likelihood_example(int32_t num_example);
143 
151  virtual float64_t get_likelihood_example(int32_t num_example);
152 
159  virtual SGVector<float64_t> get_nth_mean(int32_t num);
160 
166  virtual void set_nth_mean(SGVector<float64_t> mean, int32_t num);
167 
174  virtual SGMatrix<float64_t> get_nth_cov(int32_t num);
175 
181  virtual void set_nth_cov(SGMatrix<float64_t> cov, int32_t num);
182 
187  virtual SGVector<float64_t> get_coef();
188 
193  virtual void set_coef(const SGVector<float64_t> coefficients);
194 
199  virtual vector<CGaussian*> get_comp();
200 
205  virtual void set_comp(vector<CGaussian*> components);
206 
211  SGVector<float64_t> sample();
212 
219 
221  virtual const char* get_name() const { return "GMM"; }
222 
223  private:
230  SGMatrix<float64_t> alpha_init(SGMatrix<float64_t> init_means);
231 
233  void register_params();
234 
244  void partial_em(int32_t comp1, int32_t comp2, int32_t comp3,
245  float64_t min_cov, int32_t max_em_iter, float64_t min_change);
246 
247  protected:
249  vector<CGaussian*> m_components;
252 };
253 }
254 #endif //HAVE_LAPACK
255 #endif //_GMM_H__

SHOGUN Machine Learning Toolbox - Documentation