18 #define GRT_DLL_EXPORTS 27 rejectionThreshold = 0;
31 trainingLoggingEnabled =
true;
36 this->classLabel = rhs.classLabel;
37 this->numFeatures = rhs.numFeatures;
38 this->numClusters = rhs.numClusters;
39 this->rejectionThreshold = rhs.rejectionThreshold;
40 this->gamma = rhs.gamma;
41 this->trainingMu = rhs.trainingMu;
42 this->trainingSigma = rhs.trainingSigma;
43 this->clusters = rhs.clusters;
44 this->trainingLoggingEnabled = rhs.trainingLoggingEnabled;
52 this->classLabel = rhs.classLabel;
53 this->numFeatures = rhs.numFeatures;
54 this->numClusters = rhs.numClusters;
55 this->rejectionThreshold = rhs.rejectionThreshold;
56 this->gamma = rhs.gamma;
57 this->trainingMu = rhs.trainingMu;
58 this->trainingSigma = rhs.trainingSigma;
59 this->clusters = rhs.clusters;
60 this->trainingLoggingEnabled = rhs.trainingLoggingEnabled;
65 bool MinDistModel::train(UINT classLabel,
MatrixFloat &trainingData,UINT numClusters,Float minChange,UINT maxNumEpochs){
71 this->classLabel = classLabel;
73 this->numClusters = numClusters;
82 if( !kmeans.
train_(trainingData) ){
86 clusters = kmeans.getClusters();
89 rejectionThreshold = 0;
97 for(UINT i=0; i<M; i++){
100 for(UINT j=0; j<N; j++) {
101 testData[j] = trainingData[i][j];
104 predictions[i] = predict( testData );
105 trainingMu += predictions[i];
109 trainingMu /= Float(M);
112 for(UINT i=0; i<M; i++) {
113 trainingSigma += SQR( predictions[i]-trainingMu );
115 trainingSigma = sqrt( trainingSigma / (Float(M)-1.0) );
117 rejectionThreshold = trainingMu + ( trainingSigma * gamma );
122 Float MinDistModel::predict(
const VectorFloat &inputVector){
127 for(UINT k=0; k<numClusters; k++){
129 for(UINT n=0; n<numFeatures; n++){
130 dist += SQR( clusters[k][n]-inputVector[n] );
137 return sqrt( minDist );
142 void MinDistModel::recomputeThresholdValue(){
143 rejectionThreshold = trainingMu + ( trainingSigma * gamma );
146 UINT MinDistModel::getClassLabel()
const{
150 UINT MinDistModel::getNumFeatures()
const{
154 UINT MinDistModel::getNumClusters()
const{
158 Float MinDistModel::getRejectionThreshold()
const{
159 return rejectionThreshold;
162 Float MinDistModel::getGamma()
const{
166 Float MinDistModel::getTrainingMu()
const{
170 Float MinDistModel::getTrainingSigma()
const{
171 return trainingSigma;
178 bool MinDistModel::setClassLabel(UINT classLabel){
179 this->classLabel = classLabel;
183 bool MinDistModel::setClusters(
MatrixFloat &clusters){
184 this->clusters = clusters;
190 bool MinDistModel::setGamma(Float gamma){
195 bool MinDistModel::setRejectionThreshold(Float rejectionThreshold){
196 this->rejectionThreshold = rejectionThreshold;
200 bool MinDistModel::setTrainingSigma(Float trainingSigma){
201 this->trainingSigma = trainingSigma;
205 bool MinDistModel::setTrainingMu(Float trainingMu){
206 this->trainingMu = trainingMu;
210 bool MinDistModel::setTrainingLoggingEnabled(
bool enabled){
211 this->trainingLoggingEnabled = enabled;
bool setTrainingLoggingEnabled(const bool loggingEnabled)
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)