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 std::cout <<
"Determinate: " << det << std::endl;
55 for(UINT i=0; i<mu.
getSize(); i++)
56 std::cout << mu[i] <<
"\t";
57 std::cout << std::endl;
59 std::cout <<
"Sigma: \n";
62 std::cout << sigma[i][j] <<
"\t";
63 }std::cout << std::endl;
64 }std::cout << std::endl;
66 std::cout <<
"InvSigma: \n";
69 std::cout << invSigma[i][j] <<
"\t";
70 }std::cout << std::endl;
71 }std::cout << std::endl;
88 nullRejectionThreshold = 0;
98 return gaussModels[i];
101 inline const GuassModel& operator[](
const UINT i)
const{
102 return gaussModels[i];
105 Float computeMixtureLikelihood(
const VectorFloat &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;
124 bool recomputeNullRejectionThreshold(Float gamma){
125 Float 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.
getSize() > 0 ){
149 for(UINT k=0; k<gaussModels.
getSize(); k++){
150 gaussModels[k].printModelValues();
156 UINT getK()
const {
return K; }
158 UINT getClassLabel()
const {
return classLabel; }
160 Float getTrainingMu()
const {
164 Float getTrainingSigma()
const {
165 return trainingSigma;
168 Float getNullRejectionThreshold()
const {
169 return nullRejectionThreshold;
172 Float getNormalizationFactor()
const {
176 bool setClassLabel(
const UINT classLabel){
177 this->classLabel = classLabel;
181 bool setNormalizationFactor(
const Float normFactor){
182 this->normFactor = normFactor;
186 bool setTrainingMuAndSigma(
const Float trainingMu,
const Float trainingSigma){
187 this->trainingMu = trainingMu;
188 this->trainingSigma = trainingSigma;
192 bool setNullRejectionThreshold(
const Float nullRejectionThreshold){
193 this->nullRejectionThreshold = nullRejectionThreshold;
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*grt_exp( -0.5*sum ) );
221 Float nullRejectionThreshold;
232 #endif //GRT_MIXTURE_MODEL_HEADER
virtual bool resize(const unsigned int size)
unsigned int getSize() const
unsigned int getNumRows() const
unsigned int getNumCols() const