Gaussian.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 
00011 #ifndef _GAUSSIAN_H__
00012 #define _GAUSSIAN_H__
00013 
00014 #include <shogun/lib/config.h>
00015 
00016 #ifdef HAVE_LAPACK
00017 
00018 #include <shogun/distributions/Distribution.h>
00019 #include <shogun/features/DotFeatures.h>
00020 #include <shogun/lib/common.h>
00021 #include <shogun/mathematics/lapack.h>
00022 #include <shogun/mathematics/Math.h>
00023 
00024 namespace shogun
00025 {
00026 class CDotFeatures;
00027 
00029 enum ECovType
00030 {
00032     FULL,
00034     DIAG,
00036     SPHERICAL
00037 };
00038 
00046 class CGaussian : public CDistribution
00047 {
00048     public:
00050         CGaussian();
00057         CGaussian(const SGVector<float64_t> mean, SGMatrix<float64_t> cov, ECovType cov_type=FULL);
00058         virtual ~CGaussian();
00059 
00061         void init();
00062 
00069         virtual bool train(CFeatures* data=NULL);
00070 
00075         virtual int32_t get_num_model_parameters();
00076 
00082         virtual float64_t get_log_model_parameter(int32_t num_param);
00083 
00090         virtual float64_t get_log_derivative(
00091             int32_t num_param, int32_t num_example);
00092 
00100         virtual float64_t get_log_likelihood_example(int32_t num_example);
00101 
00107         virtual float64_t compute_PDF(SGVector<float64_t> point)
00108         {
00109             return CMath::exp(compute_log_PDF(point));
00110         }
00111 
00117         virtual float64_t compute_log_PDF(SGVector<float64_t> point);
00118 
00123         virtual SGVector<float64_t> get_mean();
00124 
00129         virtual void set_mean(const SGVector<float64_t> mean);
00130 
00135         virtual SGMatrix<float64_t> get_cov();
00136 
00143         virtual void set_cov(SGMatrix<float64_t> cov);
00144 
00149         inline ECovType get_cov_type()
00150         {
00151             return m_cov_type;
00152         }
00153 
00160         inline void set_cov_type(ECovType cov_type)
00161         {
00162             m_cov_type = cov_type;
00163         }
00164 
00169         inline SGVector<float64_t> get_d()
00170         {
00171             return m_d;
00172         }
00173 
00178         void set_d(const SGVector<float64_t> d);
00179 
00184         inline SGMatrix<float64_t> get_u()
00185         {
00186             return m_u;
00187         }
00188 
00193         inline void set_u(SGMatrix<float64_t> u)
00194         {
00195             m_u = u;
00196         }
00197 
00202         SGVector<float64_t> sample();
00203 
00205         virtual const char* get_name() const { return "Gaussian"; }
00206 
00207     private:
00209         void register_params();
00210 
00215         void decompose_cov(SGMatrix<float64_t> cov);
00216 
00217     protected:
00219         float64_t m_constant;
00221         SGVector<float64_t> m_d;
00223         SGMatrix<float64_t> m_u;
00225         SGVector<float64_t> m_mean;
00227         ECovType m_cov_type;
00228 };
00229 }
00230 #endif //HAVE_LAPACK
00231 #endif //_GAUSSIAN_H__
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

SHOGUN Machine Learning Toolbox - Documentation