SHOGUN  v3.0.0
 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 
123  virtual float64_t get_log_derivative(
124  int32_t num_param, int32_t num_example);
125 
133  virtual float64_t get_log_likelihood_example(int32_t num_example);
134 
142  virtual float64_t get_likelihood_example(int32_t num_example);
143 
150  virtual SGVector<float64_t> get_nth_mean(int32_t num);
151 
157  virtual void set_nth_mean(SGVector<float64_t> mean, int32_t num);
158 
165  virtual SGMatrix<float64_t> get_nth_cov(int32_t num);
166 
172  virtual void set_nth_cov(SGMatrix<float64_t> cov, int32_t num);
173 
178  virtual SGVector<float64_t> get_coef();
179 
184  virtual void set_coef(const SGVector<float64_t> coefficients);
185 
190  virtual vector<CGaussian*> get_comp();
191 
196  virtual void set_comp(vector<CGaussian*> components);
197 
202  SGVector<float64_t> sample();
203 
210 
212  virtual const char* get_name() const { return "GMM"; }
213 
214  private:
221  SGMatrix<float64_t> alpha_init(SGMatrix<float64_t> init_means);
222 
224  void register_params();
225 
235  void partial_em(int32_t comp1, int32_t comp2, int32_t comp3,
236  float64_t min_cov, int32_t max_em_iter, float64_t min_change);
237 
238  protected:
240  vector<CGaussian*> m_components;
243 };
244 }
245 #endif //HAVE_LAPACK
246 #endif //_GMM_H__

SHOGUN Machine Learning Toolbox - Documentation