30 this->numClusters = numClusters;
31 classType =
"RBMQuantizer";
32 featureExtractionType = classType;
33 debugLog.setProceedingText(
"[DEBUG RBMQuantizer]");
34 errorLog.setProceedingText(
"[ERROR RBMQuantizer]");
35 warningLog.setProceedingText(
"[WARNING RBMQuantizer]");
40 classType =
"RBMQuantizer";
41 featureExtractionType = classType;
42 debugLog.setProceedingText(
"[DEBUG RBMQuantizer]");
43 errorLog.setProceedingText(
"[ERROR RBMQuantizer]");
44 warningLog.setProceedingText(
"[WARNING RBMQuantizer]");
55 this->numClusters = rhs.numClusters;
57 this->quantizationDistances = rhs.quantizationDistances;
67 if( featureExtraction == NULL )
return false;
77 errorLog <<
"clone(FeatureExtraction *featureExtraction) - FeatureExtraction Types Do Not Match!" << std::endl;
97 std::fill(quantizationDistances.begin(),quantizationDistances.end(),0);
109 quantizationDistances.clear();
117 file.open(filename.c_str(), std::ios::out);
131 file.open(filename.c_str(), std::ios::in);
145 if( !file.is_open() ){
146 errorLog <<
"saveModelToFile(fstream &file) - The file is not open!" << std::endl;
151 file <<
"RBM_QUANTIZER_FILE_V1.0" << std::endl;
155 errorLog <<
"saveFeatureExtractionSettingsToFile(fstream &file) - Failed to save base feature extraction settings to file!" << std::endl;
159 file <<
"QuantizerTrained: " << trained << std::endl;
160 file <<
"NumClusters: " << numClusters << std::endl;
164 errorLog <<
"saveModelToFile(fstream &file) - Failed to save RBM settings to file!" << std::endl;
177 if( !file.is_open() ){
178 errorLog <<
"loadModelFromFile(fstream &file) - The file is not open!" << std::endl;
186 if( word !=
"RBM_QUANTIZER_FILE_V1.0" ){
187 errorLog <<
"loadModelFromFile(fstream &file) - Invalid file format!" << std::endl;
193 errorLog <<
"loadFeatureExtractionSettingsFromFile(fstream &file) - Failed to load base feature extraction settings from file!" << std::endl;
198 if( word !=
"QuantizerTrained:" ){
199 errorLog <<
"loadModelFromFile(fstream &file) - Failed to load QuantizerTrained!" << std::endl;
205 if( word !=
"NumClusters:" ){
206 errorLog <<
"loadModelFromFile(fstream &file) - Failed to load NumClusters!" << std::endl;
213 errorLog <<
"loadModelFromFile(fstream &file) - Failed to load SelfOrganizingMap settings from file!" << std::endl;
217 featureDataReady =
false;
218 quantizationDistances.
resize(numClusters,0);
250 errorLog <<
"train_(MatrixFloat &trainingData) - Failed to train quantizer, the training data is empty!" << std::endl;
255 rbm.setNumHiddenUnits( numClusters );
261 if( !rbm.
train_( trainingData ) ){
262 errorLog <<
"train_(MatrixFloat &trainingData) - Failed to train quantizer!" << std::endl;
269 numInputDimensions = trainingData.
getNumCols();
270 numOutputDimensions = 1;
271 featureVector.
resize(numOutputDimensions,0);
272 quantizationDistances.
resize(numClusters,0);
284 errorLog <<
"quantize(const VectorFloat &inputVector) - The quantizer model has not been trained!" << std::endl;
288 if( inputVector.
getSize() != numInputDimensions ){
289 errorLog <<
"quantize(const VectorFloat &inputVector) - The size of the inputVector (" << inputVector.
getSize() <<
") does not match that of the filter (" << numInputDimensions <<
")!" << std::endl;
293 if( !rbm.
predict( inputVector ) ){
294 errorLog <<
"quantize(const VectorFloat &inputVector) - Failed to quantize input!" << std::endl;
298 quantizationDistances = rbm.getOutputData();
301 UINT quantizedValue = 0;
303 for(UINT k=0; k<numClusters; k++){
304 if( quantizationDistances[k] > maxValue ){
305 maxValue = quantizationDistances[k];
310 featureVector[0] = quantizedValue;
311 featureDataReady =
true;
313 return quantizedValue;
325 return (trained ? static_cast<UINT>(featureVector[0]) : 0);
329 return quantizationDistances;
338 this->numClusters = numClusters;
bool setLearningRate(const Float learningRate)
virtual bool predict(VectorFloat inputVector)
virtual bool deepCopyFrom(const FeatureExtraction *featureExtraction)
virtual bool loadModelFromFile(std::fstream &file)
UINT getNumClusters() const
virtual bool loadModelFromFile(std::string filename)
MatrixFloat getDataAsMatrixFloat() const
virtual bool resize(const unsigned int size)
UINT quantize(const Float inputValue)
RBMQuantizer & operator=(const RBMQuantizer &rhs)
BernoulliRBM getBernoulliRBM() const
virtual bool saveModelToFile(std::string filename) const
VectorFloat getQuantizationDistances() const
bool setNumClusters(const UINT numClusters)
bool setMinChange(const Float minChange)
unsigned int getSize() const
virtual bool computeFeatures(const VectorFloat &inputVector)
virtual bool train_(ClassificationData &trainingData)
MatrixFloat getDataAsMatrixFloat() const
unsigned int getNumRows() const
MatrixFloat getDataAsMatrixFloat() const
unsigned int getNumCols() const
The SOMQuantizer module quantizes the N-dimensional input vector to a 1-dimensional discrete value...
bool setMinNumEpochs(const UINT minNumEpochs)
UINT getQuantizedValue() const
virtual bool saveModelToFile(std::fstream &file) const
MatrixFloat getDataAsMatrixFloat() const
virtual bool train_(MatrixFloat &data)
bool getQuantizerTrained() const
bool setMaxNumEpochs(const UINT maxNumEpochs)
RBMQuantizer(const UINT numClusters=10)