18 #define GRT_DLL_EXPORTS
27 rejectionThreshold = 0;
35 this->classLabel = rhs.classLabel;
36 this->numFeatures = rhs.numFeatures;
37 this->numClusters = rhs.numClusters;
38 this->rejectionThreshold = rhs.rejectionThreshold;
39 this->gamma = rhs.gamma;
40 this->trainingMu = rhs.trainingMu;
41 this->trainingSigma = rhs.trainingSigma;
42 this->clusters = rhs.clusters;
50 this->classLabel = rhs.classLabel;
51 this->numFeatures = rhs.numFeatures;
52 this->numClusters = rhs.numClusters;
53 this->rejectionThreshold = rhs.rejectionThreshold;
54 this->gamma = rhs.gamma;
55 this->trainingMu = rhs.trainingMu;
56 this->trainingSigma = rhs.trainingSigma;
57 this->clusters = rhs.clusters;
62 bool MinDistModel::train(UINT classLabel,
MatrixFloat &trainingData,UINT numClusters,Float minChange,UINT maxNumEpochs){
68 this->classLabel = classLabel;
70 this->numClusters = numClusters;
78 if( !kmeans.
train_(trainingData) ){
82 clusters = kmeans.getClusters();
85 rejectionThreshold = 0;
93 for(UINT i=0; i<M; i++){
96 for(UINT j=0; j<N; j++) {
97 testData[j] = trainingData[i][j];
100 predictions[i] = predict( testData );
101 trainingMu += predictions[i];
105 trainingMu /= Float(M);
108 for(UINT i=0; i<M; i++) {
109 trainingSigma += SQR( predictions[i]-trainingMu );
111 trainingSigma = sqrt( trainingSigma / (Float(M)-1.0) );
113 rejectionThreshold = trainingMu + ( trainingSigma * gamma );
118 Float MinDistModel::predict(
const VectorFloat &inputVector){
123 for(UINT k=0; k<numClusters; k++){
125 for(UINT n=0; n<numFeatures; n++){
126 dist += SQR( clusters[k][n]-inputVector[n] );
133 return sqrt( minDist );
138 void MinDistModel::recomputeThresholdValue(){
139 rejectionThreshold = trainingMu + ( trainingSigma * gamma );
142 UINT MinDistModel::getClassLabel()
const{
146 UINT MinDistModel::getNumFeatures()
const{
150 UINT MinDistModel::getNumClusters()
const{
154 Float MinDistModel::getRejectionThreshold()
const{
155 return rejectionThreshold;
158 Float MinDistModel::getGamma()
const{
162 Float MinDistModel::getTrainingMu()
const{
166 Float MinDistModel::getTrainingSigma()
const{
167 return trainingSigma;
174 bool MinDistModel::setClassLabel(UINT classLabel){
175 this->classLabel = classLabel;
179 bool MinDistModel::setClusters(
MatrixFloat &clusters){
180 this->clusters = clusters;
186 bool MinDistModel::setGamma(Float gamma){
191 bool MinDistModel::setRejectionThreshold(Float rejectionThreshold){
192 this->rejectionThreshold = rejectionThreshold;
196 bool MinDistModel::setTrainingSigma(Float trainingSigma){
197 this->trainingSigma = trainingSigma;
201 bool MinDistModel::setTrainingMu(Float trainingMu){
202 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)