IT++ Logo

gmm.h

Go to the documentation of this file.
00001 
00030 #ifndef GMM_H
00031 #define GMM_H
00032 
00033 #include <itpp/base/mat.h>
00034 
00035 
00036 namespace itpp {
00037 
00039 
00045   class GMM {
00046   public:
00047     GMM();
00048     GMM(int nomix, int dim);
00049     GMM(std::string filename);
00050     void init_from_vq(const vec &codebook, int dim);
00051     //  void init(const vec &w_in, const vec &m_in, const vec &sigma_in);
00052     void init(const vec &w_in, const mat &m_in, const mat &sigma_in);
00053     void load(std::string filename);
00054     void save(std::string filename);
00055     void set_weight(const vec &weights, bool compflag=true);
00056     void set_weight(int i, double weight, bool compflag=true);
00057     void set_mean(const mat &m_in);
00058     void set_mean(const vec &means, bool compflag=true);
00059     void set_mean(int i, const vec &means, bool compflag=true);
00060     void set_covariance(const mat &sigma_in);
00061     void set_covariance(const vec &covariances, bool compflag=true);
00062     void set_covariance(int i, const vec &covariances, bool compflag=true);
00063     int get_no_mixtures();
00064     int get_no_gaussians() const { return M; }
00065     int get_dimension();
00066     vec get_weight();
00067     double get_weight(int i);
00068     vec get_mean();
00069     vec get_mean(int i);
00070     vec get_covariance();
00071     vec get_covariance(int i);
00072     void marginalize(int d_new);
00073     void join(const GMM &newgmm);
00074     void clear();
00075     double likelihood(const vec &x);
00076     double likelihood_aposteriori(const vec &x, int mixture);
00077     vec likelihood_aposteriori(const vec &x);
00078     vec draw_sample();
00079   protected:
00080     vec     m,sigma,w;
00081     int     M,d;
00082   private:
00083     void    compute_internals();
00084     vec     normweight,normexp;
00085   };
00086 
00087   inline void GMM::set_weight(const vec &weights, bool compflag) {w=weights; if (compflag) compute_internals(); }
00088   inline void GMM::set_weight(int i, double weight, bool compflag) {w(i)=weight; if (compflag) compute_internals(); }
00089   inline void GMM::set_mean(const vec &means, bool compflag) {m=means; if (compflag) compute_internals(); }
00090   inline void GMM::set_covariance(const vec &covariances, bool compflag) {sigma=covariances; if (compflag) compute_internals(); }
00091   inline int GMM::get_no_mixtures()
00092   {
00093     it_warning("GMM::get_no_mixtures(): This function is depreceted and might be removed from feature releases. Please use get_no_gaussians() instead.");
00094     return M;
00095   }
00096   inline int GMM::get_dimension() {return d;}
00097   inline vec GMM::get_weight() {return w;}
00098   inline double GMM::get_weight(int i) {return w(i);}
00099   inline vec GMM::get_mean() {return m;}
00100   inline vec GMM::get_mean(int i) {return m.mid(i*d,d);}
00101   inline vec GMM::get_covariance() {return sigma;}
00102   inline vec GMM::get_covariance(int i) {return sigma.mid(i*d,d);}
00103 
00104   GMM gmmtrain(Array<vec> &TrainingData, int M, int NOITER=30, bool VERBOSE=true);
00105 
00107 
00108 } // namespace itpp
00109 
00110 #endif // #ifndef GMM_H
SourceForge Logo

Generated on Sun Sep 14 18:57:06 2008 for IT++ by Doxygen 1.5.6