32 #ifndef GRT_MIXTURE_MODEL_HEADER
33 #define GRT_MIXTURE_MODEL_HEADER
35 #include "../../CoreModules/Classifier.h"
36 #include "../../ClusteringModules/GaussianMixtureModels/GaussianMixtureModels.h"
50 bool printModelValues()
const{
51 if( mu.size() == 0 )
return false;
53 cout <<
"Determinate: " << det << endl;
55 for(UINT i=0; i<mu.size(); i++)
56 cout << mu[i] <<
"\t";
62 cout << sigma[i][j] <<
"\t";
66 cout <<
"InvSigma: \n";
69 cout << invSigma[i][j] <<
"\t";
88 nullRejectionThreshold = 0;
98 return gaussModels[i];
101 inline const GuassModel& operator[](
const UINT i)
const{
102 return gaussModels[i];
105 double computeMixtureLikelihood(
const vector<double> &x){
107 for(UINT k=0; k<K; k++){
108 sum += gauss(x,gaussModels[k].det,gaussModels[k].mu,gaussModels[k].invSigma);
111 return sum/normFactor;
118 gaussModels.resize(K);
124 bool recomputeNullRejectionThreshold(
double gamma){
125 double newRejectionThreshold = 0;
127 newRejectionThreshold = trainingMu - (trainingSigma*gamma);
128 newRejectionThreshold = 0.02;
131 if( newRejectionThreshold > 0 ){
133 this->nullRejectionThreshold = newRejectionThreshold;
139 bool recomputeNormalizationFactor(){
141 for(UINT k=0; k<K; k++){
142 normFactor += gauss(gaussModels[k].mu,gaussModels[k].det,gaussModels[k].mu,gaussModels[k].invSigma);
147 bool printModelValues()
const{
148 if( gaussModels.size() > 0 ){
149 for(UINT k=0; k<gaussModels.size(); k++){
150 gaussModels[k].printModelValues();
156 UINT getK()
const {
return K; }
158 UINT getClassLabel()
const {
return classLabel; }
160 double getTrainingMu()
const {
164 double getTrainingSigma()
const {
165 return trainingSigma;
168 double getNullRejectionThreshold()
const {
169 return nullRejectionThreshold;
172 double getNormalizationFactor()
const {
176 bool setClassLabel(
const UINT classLabel){
177 this->classLabel = classLabel;
181 bool setNormalizationFactor(
const double normFactor){
182 this->normFactor = normFactor;
186 bool setTrainingMuAndSigma(
const double trainingMu,
const double trainingSigma){
187 this->trainingMu = trainingMu;
188 this->trainingSigma = trainingSigma;
192 bool setNullRejectionThreshold(
const double nullRejectionThreshold){
193 this->nullRejectionThreshold = nullRejectionThreshold;
198 double gauss(
const VectorDouble &x,
double det,
const VectorDouble &mu,
const MatrixDouble &invSigma){
202 const UINT N = (UINT)x.size();
203 VectorDouble temp(N,0);
206 y = (1.0/pow(TWO_PI,N/2.0)) * (1.0/pow(det,0.5));
209 for(UINT i=0; i<N; i++){
210 for(UINT j=0; j<N; j++){
211 temp[i] += (x[j]-mu[j]) * invSigma[j][i];
213 sum += (x[i]-mu[i]) * temp[i];
216 return ( y*exp( -0.5*sum ) );
221 double nullRejectionThreshold;
224 double trainingSigma;
226 vector< GuassModel > gaussModels;
232 #endif //GRT_MIXTURE_MODEL_HEADER
unsigned int getNumCols() const
unsigned int getNumRows() const