IT++ 4.3.1
gmm.h
Go to the documentation of this file.
1
28
29#ifndef GMM_H
30#define GMM_H
31
32#include <itpp/base/mat.h>
33#include <itpp/itexports.h>
34
35
36namespace itpp
37{
38
44class ITPP_EXPORT GMM
45{
46public:
47 GMM();
48 GMM(int nomix, int dim);
49 GMM(std::string filename);
50 void init_from_vq(const vec &codebook, int dim);
51 // void init(const vec &w_in, const vec &m_in, const vec &sigma_in);
52 void init(const vec &w_in, const mat &m_in, const mat &sigma_in);
53 void load(std::string filename);
54 void save(std::string filename);
55 void set_weight(const vec &weights, bool compflag = true);
56 void set_weight(int i, double weight, bool compflag = true);
57 void set_mean(const mat &m_in);
58 void set_mean(const vec &means, bool compflag = true);
59 void set_mean(int i, const vec &means, bool compflag = true);
60 void set_covariance(const mat &sigma_in);
61 void set_covariance(const vec &covariances, bool compflag = true);
62 void set_covariance(int i, const vec &covariances, bool compflag = true);
63 int get_no_mixtures();
64 int get_no_gaussians() const { return M; }
65 int get_dimension();
66 vec get_weight();
67 double get_weight(int i);
68 vec get_mean();
69 vec get_mean(int i);
70 vec get_covariance();
71 vec get_covariance(int i);
72 void marginalize(int d_new);
73 void join(const GMM &newgmm);
74 void clear();
75 double likelihood(const vec &x);
76 double likelihood_aposteriori(const vec &x, int mixture);
77 vec likelihood_aposteriori(const vec &x);
78 vec draw_sample();
79protected:
80 vec m, sigma, w;
81 int M, d;
82private:
83 void compute_internals();
84 vec normweight, normexp;
85};
86
87inline void GMM::set_weight(const vec &weights, bool compflag) {w = weights; if (compflag) compute_internals(); }
88inline void GMM::set_weight(int i, double weight, bool compflag) {w(i) = weight; if (compflag) compute_internals(); }
89inline void GMM::set_mean(const vec &means, bool compflag) {m = means; if (compflag) compute_internals(); }
90inline void GMM::set_covariance(const vec &covariances, bool compflag) {sigma = covariances; if (compflag) compute_internals(); }
91inline int GMM::get_dimension() {return d;}
92inline vec GMM::get_weight() {return w;}
93inline double GMM::get_weight(int i) {return w(i);}
94inline vec GMM::get_mean() {return m;}
95inline vec GMM::get_mean(int i) {return m.mid(i*d, d);}
96inline vec GMM::get_covariance() {return sigma;}
97inline vec GMM::get_covariance(int i) {return sigma.mid(i*d, d);}
98
99ITPP_EXPORT GMM gmmtrain(Array<vec> &TrainingData, int M, int NOITER = 30, bool VERBOSE = true);
100
102
103} // namespace itpp
104
105#endif // #ifndef GMM_H
General array class.
Definition array.h:105
Gaussian Mixture Model Class.
Definition gmm.h:45
int weight(const bvec &a)
Calculate the Hamming weight of a.
Definition commfunc.cpp:71
Matrix Class Definitions.
itpp namespace
Definition itmex.h:37