26 rejectionThreshold = 0;
34 this->classLabel = rhs.classLabel;
35 this->numFeatures = rhs.numFeatures;
36 this->numClusters = rhs.numClusters;
37 this->rejectionThreshold = rhs.rejectionThreshold;
38 this->gamma = rhs.gamma;
39 this->trainingMu = rhs.trainingMu;
40 this->trainingSigma = rhs.trainingSigma;
41 this->clusters = rhs.clusters;
49 this->classLabel = rhs.classLabel;
50 this->numFeatures = rhs.numFeatures;
51 this->numClusters = rhs.numClusters;
52 this->rejectionThreshold = rhs.rejectionThreshold;
53 this->gamma = rhs.gamma;
54 this->trainingMu = rhs.trainingMu;
55 this->trainingSigma = rhs.trainingSigma;
56 this->clusters = rhs.clusters;
61 bool MinDistModel::train(UINT classLabel,
MatrixFloat &trainingData,UINT numClusters,Float minChange,UINT maxNumEpochs){
67 this->classLabel = classLabel;
69 this->numClusters = numClusters;
77 if( !kmeans.
train_(trainingData) ){
81 clusters = kmeans.getClusters();
84 rejectionThreshold = 0;
92 for(UINT i=0; i<M; i++){
95 for(UINT j=0; j<N; j++) {
96 testData[j] = trainingData[i][j];
99 predictions[i] = predict( testData );
100 trainingMu += predictions[i];
104 trainingMu /= Float(M);
107 for(UINT i=0; i<M; i++) {
108 trainingSigma += SQR( predictions[i]-trainingMu );
110 trainingSigma = sqrt( trainingSigma / (Float(M)-1.0) );
112 rejectionThreshold = trainingMu + ( trainingSigma * gamma );
117 Float MinDistModel::predict(
const VectorFloat &inputVector){
122 for(UINT k=0; k<numClusters; k++){
124 for(UINT n=0; n<numFeatures; n++){
125 dist += SQR( clusters[k][n]-inputVector[n] );
132 return sqrt( minDist );
137 void MinDistModel::recomputeThresholdValue(){
138 rejectionThreshold = trainingMu + ( trainingSigma * gamma );
141 UINT MinDistModel::getClassLabel()
const{
145 UINT MinDistModel::getNumFeatures()
const{
149 UINT MinDistModel::getNumClusters()
const{
153 Float MinDistModel::getRejectionThreshold()
const{
154 return rejectionThreshold;
157 Float MinDistModel::getGamma()
const{
161 Float MinDistModel::getTrainingMu()
const{
165 Float MinDistModel::getTrainingSigma()
const{
166 return trainingSigma;
173 bool MinDistModel::setClassLabel(UINT classLabel){
174 this->classLabel = classLabel;
178 bool MinDistModel::setClusters(
MatrixFloat &clusters){
179 this->clusters = clusters;
185 bool MinDistModel::setGamma(Float gamma){
190 bool MinDistModel::setRejectionThreshold(Float rejectionThreshold){
191 this->rejectionThreshold = rejectionThreshold;
195 bool MinDistModel::setTrainingSigma(Float trainingSigma){
196 this->trainingSigma = trainingSigma;
200 bool MinDistModel::setTrainingMu(Float trainingMu){
201 this->trainingMu = trainingMu;
virtual bool train_(MatrixFloat &data)
bool setMinChange(const Float minChange)
This class implements the MinDist classifier algorithm.
unsigned int getNumRows() const
unsigned int getNumCols() const
MinDistModel & operator=(const MinDistModel &rhs)
bool setMaxNumEpochs(const UINT maxNumEpochs)
bool setNumClusters(const UINT numClusters)