30 #ifndef GRT_GAUSSIAN_MIXTURE_MODELS_HEADER
31 #define GRT_GAUSSIAN_MIXTURE_MODELS_HEADER
33 #include "../../CoreModules/Clusterer.h"
114 virtual bool predict_(VectorDouble &inputVector);
151 vector< MatrixDouble >
getSigma()
const {
if( trained ){
return sigma; }
return vector< MatrixDouble >(); }
172 bool estep(
const MatrixDouble &data, VectorDouble &u, VectorDouble &v,
double &change );
174 bool computeInvAndDet();
175 inline void SWAP(UINT &a,UINT &b);
176 inline double SQR(
const double v){
return v*v; }
178 double gauss(
const VectorDouble &x,
const UINT clusterIndex,
const VectorDouble &det,
const MatrixDouble &
mu,
const vector< MatrixDouble > &invSigma){
183 const UINT N = (UINT)x.size();
184 VectorDouble temp(N,0);
187 y = (1.0/pow(TWO_PI,N/2.0)) * (1.0/pow(det[clusterIndex],0.5));
192 temp[i] += (x[j]-mu[clusterIndex][j]) * invSigma[clusterIndex][j][i];
194 sum += (x[i]-mu[clusterIndex][i]) * temp[i];
197 return ( y*exp( -0.5*sum ) );
207 vector< MatrixDouble > sigma;
208 vector< MatrixDouble > invSigma;
216 #endif //GRT_GAUSSIAN_MIXTURE_MODELS_HEADER
virtual bool saveModelToFile(string filename) const
double loglike
The current loglikelihood value of the models given the data.
GaussianMixtureModels & operator=(const GaussianMixtureModels &rhs)
virtual bool loadModelFromFile(string filename)
UINT numClusters
Number of clusters in the model.
MatrixDouble getMu() const
virtual bool deepCopyFrom(const Clusterer *clusterer)
UINT numTrainingSamples
The number of samples in the training data.
virtual ~GaussianMixtureModels()
virtual bool loadModelFromFile(fstream &file)
virtual bool train_(MatrixDouble &data)
virtual bool predict_(VectorDouble &inputVector)
VectorDouble lndets
A vector holding the log detminants of SIGMA'k.
virtual bool saveModelToFile(fstream &file) const
GaussianMixtureModels(const UINT numClusters=10, const UINT minNumEpochs=5, const UINT maxNumEpochs=1000, const double minChange=1.0e-5)
MatrixDouble getSigma(const UINT k) const
MatrixDouble mu
A matrix holding the estimated mean values of each Gaussian.
vector< MatrixDouble > getSigma() const
MatrixDouble resp
The responsibility matrix.
VectorDouble frac
A vector holding the P(k)'s.