This class implements the Gaussian Mixture Model Classifier algorithm. The Gaussian Mixture Model Classifier (GMM) is basic but useful classification algorithm that can be used to classify an N-dimensional signal.
- Note
- The GMM algorithm can fail to train on some occasions, if this happens just try and run the training algorithm again and it should eventially converge.
using namespace std;
int main (int argc, const char * argv[])
{
if( argc != 2 ){
cout << "Error: failed to parse data filename from command line. You should run this example with one argument pointing to the data filename!\n";
return EXIT_FAILURE;
}
const string filename = argv[1];
if( !trainingData.
load( filename ) ){
cout << "Failed to load training data!\n";
return EXIT_FAILURE;
}
if( !gmm.
train( trainingData ) ){
cout << "Failed to train classifier!\n";
return EXIT_FAILURE;
}
if( !gmm.
save(
"GMMModel.grt") ){
cout << "Failed to save the classifier model!\n";
return EXIT_FAILURE;
}
if( !gmm.
load(
"GMMModel.grt") ){
cout << "Failed to load the classifier model!\n";
return EXIT_FAILURE;
}
double accuracy = 0;
UINT classLabel = testData[i].getClassLabel();
bool predictSuccess = gmm.
predict( inputVector );
if( !predictSuccess ){
cout << "Failed to perform prediction for test sampel: " << i <<"\n";
return EXIT_FAILURE;
}
if( classLabel == predictedClassLabel ) accuracy++;
cout << "TestSample: " << i << " ClassLabel: " << classLabel << " PredictedClassLabel: " << predictedClassLabel << endl;
}
cout <<
"Test Accuracy: " << accuracy/double(testData.
getNumSamples())*100.0 <<
"%" << endl;
return EXIT_SUCCESS;
}