21 #define GRT_DLL_EXPORTS
31 this->numClusters = numClusters;
32 classType =
"RBMQuantizer";
33 featureExtractionType = classType;
34 debugLog.setProceedingText(
"[DEBUG RBMQuantizer]");
35 errorLog.setProceedingText(
"[ERROR RBMQuantizer]");
36 warningLog.setProceedingText(
"[WARNING RBMQuantizer]");
41 classType =
"RBMQuantizer";
42 featureExtractionType = classType;
43 debugLog.setProceedingText(
"[DEBUG RBMQuantizer]");
44 errorLog.setProceedingText(
"[ERROR RBMQuantizer]");
45 warningLog.setProceedingText(
"[WARNING RBMQuantizer]");
56 this->numClusters = rhs.numClusters;
58 this->quantizationDistances = rhs.quantizationDistances;
68 if( featureExtraction == NULL )
return false;
78 errorLog <<
"clone(FeatureExtraction *featureExtraction) - FeatureExtraction Types Do Not Match!" << std::endl;
98 std::fill(quantizationDistances.begin(),quantizationDistances.end(),0);
110 quantizationDistances.clear();
117 if( !file.is_open() ){
118 errorLog <<
"save(fstream &file) - The file is not open!" << std::endl;
123 file <<
"RBM_QUANTIZER_FILE_V1.0" << std::endl;
127 errorLog <<
"saveFeatureExtractionSettingsToFile(fstream &file) - Failed to save base feature extraction settings to file!" << std::endl;
131 file <<
"QuantizerTrained: " << trained << std::endl;
132 file <<
"NumClusters: " << numClusters << std::endl;
135 if( !rbm.
save( file ) ){
136 errorLog <<
"save(fstream &file) - Failed to save RBM settings to file!" << std::endl;
149 if( !file.is_open() ){
150 errorLog <<
"load(fstream &file) - The file is not open!" << std::endl;
158 if( word !=
"RBM_QUANTIZER_FILE_V1.0" ){
159 errorLog <<
"load(fstream &file) - Invalid file format!" << std::endl;
165 errorLog <<
"loadFeatureExtractionSettingsFromFile(fstream &file) - Failed to load base feature extraction settings from file!" << std::endl;
170 if( word !=
"QuantizerTrained:" ){
171 errorLog <<
"load(fstream &file) - Failed to load QuantizerTrained!" << std::endl;
177 if( word !=
"NumClusters:" ){
178 errorLog <<
"load(fstream &file) - Failed to load NumClusters!" << std::endl;
184 if( !rbm.
load( file ) ){
185 errorLog <<
"load(fstream &file) - Failed to load SelfOrganizingMap settings from file!" << std::endl;
189 featureDataReady =
false;
190 quantizationDistances.
resize(numClusters,0);
222 errorLog <<
"train_(MatrixFloat &trainingData) - Failed to train quantizer, the training data is empty!" << std::endl;
227 rbm.setNumHiddenUnits( numClusters );
233 if( !rbm.
train_( trainingData ) ){
234 errorLog <<
"train_(MatrixFloat &trainingData) - Failed to train quantizer!" << std::endl;
241 numInputDimensions = trainingData.
getNumCols();
242 numOutputDimensions = 1;
243 featureVector.
resize(numOutputDimensions,0);
244 quantizationDistances.
resize(numClusters,0);
256 errorLog <<
"quantize(const VectorFloat &inputVector) - The quantizer model has not been trained!" << std::endl;
260 if( inputVector.
getSize() != numInputDimensions ){
261 errorLog <<
"quantize(const VectorFloat &inputVector) - The size of the inputVector (" << inputVector.
getSize() <<
") does not match that of the filter (" << numInputDimensions <<
")!" << std::endl;
265 if( !rbm.
predict( inputVector ) ){
266 errorLog <<
"quantize(const VectorFloat &inputVector) - Failed to quantize input!" << std::endl;
270 quantizationDistances = rbm.getOutputData();
273 UINT quantizedValue = 0;
275 for(UINT k=0; k<numClusters; k++){
276 if( quantizationDistances[k] > maxValue ){
277 maxValue = quantizationDistances[k];
282 featureVector[0] = quantizedValue;
283 featureDataReady =
true;
285 return quantizedValue;
297 return (trained ? static_cast<UINT>(featureVector[0]) : 0);
301 return quantizationDistances;
310 this->numClusters = numClusters;
bool setLearningRate(const Float learningRate)
virtual bool predict(VectorFloat inputVector)
virtual bool save(std::fstream &file) const
virtual bool deepCopyFrom(const FeatureExtraction *featureExtraction)
UINT getNumClusters() const
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 load(std::fstream &file)
VectorFloat getQuantizationDistances() const
bool setNumClusters(const UINT numClusters)
virtual bool save(std::fstream &file) const
bool setMinChange(const Float minChange)
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 load(std::fstream &file)
MatrixFloat getDataAsMatrixFloat() const
virtual bool train_(MatrixFloat &data)
bool getQuantizerTrained() const
bool setMaxNumEpochs(const UINT maxNumEpochs)
RBMQuantizer(const UINT numClusters=10)