SHOGUN  v3.2.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
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 #include <vector>
00022 
00023 using namespace std;
00024 
00025 namespace shogun
00026 {
00040 class CGMM : public CDistribution
00041 {
00042     public:
00044         CGMM();
00050         CGMM(int32_t n, ECovType cov_type=FULL);
00057         CGMM(vector<CGaussian*> components, SGVector<float64_t> coefficients,
00058                 bool copy=false);
00059         virtual ~CGMM();
00060 
00062         void cleanup();
00063 
00070         virtual bool train(CFeatures* data=NULL);
00071 
00080         float64_t train_em(float64_t min_cov=1e-9, int32_t max_iter=1000,
00081                 float64_t min_change=1e-9);
00082 
00093         float64_t train_smem(int32_t max_iter=100, int32_t max_cand=5,
00094                 float64_t min_cov=1e-9, int32_t max_em_iter=1000,
00095                 float64_t min_change=1e-9);
00096 
00102         void max_likelihood(SGMatrix<float64_t> alpha, float64_t min_cov);
00103 
00108         virtual int32_t get_num_model_parameters();
00109 
00115         virtual float64_t get_log_model_parameter(int32_t num_param);
00116 
00118         index_t get_num_components() const;
00119 
00124         CDistribution* get_component(index_t index) const;
00125 
00132         virtual float64_t get_log_derivative(
00133             int32_t num_param, int32_t num_example);
00134 
00142         virtual float64_t get_log_likelihood_example(int32_t num_example);
00143 
00151         virtual float64_t get_likelihood_example(int32_t num_example);
00152 
00159         virtual SGVector<float64_t> get_nth_mean(int32_t num);
00160 
00166         virtual void set_nth_mean(SGVector<float64_t> mean, int32_t num);
00167 
00174         virtual SGMatrix<float64_t> get_nth_cov(int32_t num);
00175 
00181         virtual void set_nth_cov(SGMatrix<float64_t> cov, int32_t num);
00182 
00187         virtual SGVector<float64_t> get_coef();
00188 
00193         virtual void set_coef(const SGVector<float64_t> coefficients);
00194 
00199         virtual vector<CGaussian*> get_comp();
00200 
00205         virtual void set_comp(vector<CGaussian*> components);
00206 
00211         SGVector<float64_t> sample();
00212 
00218         SGVector<float64_t> cluster(SGVector<float64_t> point);
00219 
00221         virtual const char* get_name() const { return "GMM"; }
00222 
00223     private:
00230         SGMatrix<float64_t> alpha_init(SGMatrix<float64_t> init_means);
00231 
00233         void register_params();
00234 
00244         void partial_em(int32_t comp1, int32_t comp2, int32_t comp3,
00245                 float64_t min_cov, int32_t max_em_iter, float64_t min_change);
00246 
00247     protected:
00249         vector<CGaussian*> m_components;
00251         SGVector<float64_t> m_coefficients;
00252 };
00253 }
00254 #endif //HAVE_LAPACK
00255 #endif //_GMM_H__
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

SHOGUN Machine Learning Toolbox - Documentation