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;
118 gaussModels.resize(K);
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();
157 UINT getK()
const {
return K; }
159 UINT getClassLabel()
const {
return classLabel; }
161 Float getTrainingMu()
const {
165 Float getTrainingSigma()
const {
166 return trainingSigma;
169 Float getNullRejectionThreshold()
const {
170 return nullRejectionThreshold;
173 Float getNormalizationFactor()
const {
177 bool setClassLabel(
const UINT classLabel){
178 this->classLabel = classLabel;
182 bool setNormalizationFactor(
const Float normFactor){
183 this->normFactor = normFactor;
187 bool setTrainingMuAndSigma(
const Float trainingMu,
const Float trainingSigma){
188 this->trainingMu = trainingMu;
189 this->trainingSigma = trainingSigma;
193 bool setNullRejectionThreshold(
const Float nullRejectionThreshold){
194 this->nullRejectionThreshold = nullRejectionThreshold;
207 y = (1.0/pow(TWO_PI,N/2.0)) * (1.0/pow(det,0.5));
210 for(UINT i=0; i<N; i++){
211 for(UINT j=0; j<N; j++){
212 temp[i] += (x[j]-mu[j]) * invSigma[j][i];
214 sum += (x[i]-mu[i]) * temp[i];
217 return y*grt_exp( -0.5*sum );
222 Float nullRejectionThreshold;
233 #endif //GRT_MIXTURE_MODEL_HEADER
unsigned int getNumRows() const
unsigned int getNumCols() const