GMM.h

Go to the documentation of this file.
00001 /*
00002  * This program is free software; you can redistribute it and/or modify
00003  * it under the terms of the GNU General Public License as published by
00004  * the Free Software Foundation; either version 3 of the License, or
00005  * (at your option) any later version.
00006  *
00007  * Written (W) 2011 Alesis Novik
00008  * Copyright (C) 2011 Berlin Institute of Technology and Max-Planck-Society
00009  */
00010 #ifndef _GMM_H__
00011 #define _GMM_H__
00012 
00013 #include <shogun/lib/config.h>
00014 
00015 #ifdef HAVE_LAPACK
00016 
00017 #include <shogun/distributions/Distribution.h>
00018 #include <shogun/distributions/Gaussian.h>
00019 #include <shogun/lib/common.h>
00020 
00021 namespace shogun
00022 {
00036 class CGMM : public CDistribution
00037 {
00038     public:
00040         CGMM();
00046         CGMM(int32_t n, ECovType cov_type=FULL);
00053         CGMM(SGVector<CGaussian*> components, SGVector<float64_t> coefficients,
00054                 bool copy=false);
00055         virtual ~CGMM();
00056 
00058         void cleanup();
00059 
00066         virtual bool train(CFeatures* data=NULL);
00067 
00076         float64_t train_em(float64_t min_cov=1e-9, int32_t max_iter=1000,
00077                 float64_t min_change=1e-9);
00078 
00089         float64_t train_smem(int32_t max_iter=100, int32_t max_cand=5,
00090                 float64_t min_cov=1e-9, int32_t max_em_iter=1000,
00091                 float64_t min_change=1e-9);
00092 
00098         void max_likelihood(SGMatrix<float64_t> alpha, float64_t min_cov);
00099 
00104         virtual int32_t get_num_model_parameters();
00105 
00111         virtual float64_t get_log_model_parameter(int32_t num_param);
00112 
00119         virtual float64_t get_log_derivative(
00120             int32_t num_param, int32_t num_example);
00121 
00129         virtual float64_t get_log_likelihood_example(int32_t num_example);
00130 
00138         virtual float64_t get_likelihood_example(int32_t num_example);
00139 
00146         virtual SGVector<float64_t> get_nth_mean(int32_t num);
00147 
00153         virtual void set_nth_mean(SGVector<float64_t> mean, int32_t num);
00154 
00161         virtual SGMatrix<float64_t> get_nth_cov(int32_t num);
00162 
00168         virtual void set_nth_cov(SGMatrix<float64_t> cov, int32_t num);
00169 
00174         virtual SGVector<float64_t> get_coef();
00175 
00180         virtual void set_coef(SGVector<float64_t> coefficients);
00181 
00186         virtual SGVector<CGaussian*> get_comp();
00187 
00192         virtual void set_comp(SGVector<CGaussian*> components);
00193 
00198         SGVector<float64_t> sample();
00199 
00205         SGVector<float64_t> cluster(SGVector<float64_t> point);
00206 
00208         inline virtual const char* get_name() const { return "GMM"; }
00209 
00210     private:
00217         SGMatrix<float64_t> alpha_init(SGMatrix<float64_t> init_means);
00218 
00220         void register_params();
00221 
00231         void partial_em(int32_t comp1, int32_t comp2, int32_t comp3,
00232                 float64_t min_cov, int32_t max_em_iter, float64_t min_change);
00233 
00234     protected:
00236         SGVector<CGaussian*> m_components;
00238         SGVector<float64_t> m_coefficients;
00239 };
00240 }
00241 #endif //HAVE_LAPACK
00242 #endif //_GMM_H__
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

SHOGUN Machine Learning Toolbox - Documentation