21 #define GRT_DLL_EXPORTS 27 std::string RBMQuantizer::id =
"RBMQuantizer";
35 this->numClusters = numClusters;
49 this->numClusters = rhs.numClusters;
51 this->quantizationDistances = rhs.quantizationDistances;
61 if( featureExtraction == NULL )
return false;
63 if( this->
getId() == featureExtraction->
getId() ){
66 *
this = *
dynamic_cast<const RBMQuantizer*
>(featureExtraction);
71 errorLog <<
"deepCopyFrom(FeatureExtraction *featureExtraction) - FeatureExtraction Types Do Not Match!" << std::endl;
91 std::fill(quantizationDistances.begin(),quantizationDistances.end(),0);
103 quantizationDistances.clear();
110 if( !file.is_open() ){
111 errorLog <<
"save(fstream &file) - The file is not open!" << std::endl;
116 file <<
"RBM_QUANTIZER_FILE_V1.0" << std::endl;
120 errorLog <<
"saveFeatureExtractionSettingsToFile(fstream &file) - Failed to save base feature extraction settings to file!" << std::endl;
124 file <<
"QuantizerTrained: " << trained << std::endl;
125 file <<
"NumClusters: " << numClusters << std::endl;
128 if( !rbm.
save( file ) ){
129 errorLog <<
"save(fstream &file) - Failed to save RBM settings to file!" << std::endl;
142 if( !file.is_open() ){
143 errorLog <<
"load(fstream &file) - The file is not open!" << std::endl;
151 if( word !=
"RBM_QUANTIZER_FILE_V1.0" ){
152 errorLog <<
"load(fstream &file) - Invalid file format!" << std::endl;
158 errorLog <<
"loadFeatureExtractionSettingsFromFile(fstream &file) - Failed to load base feature extraction settings from file!" << std::endl;
163 if( word !=
"QuantizerTrained:" ){
164 errorLog <<
"load(fstream &file) - Failed to load QuantizerTrained!" << std::endl;
170 if( word !=
"NumClusters:" ){
171 errorLog <<
"load(fstream &file) - Failed to load NumClusters!" << std::endl;
177 if( !rbm.
load( file ) ){
178 errorLog <<
"load(fstream &file) - Failed to load SelfOrganizingMap settings from file!" << std::endl;
182 featureDataReady =
false;
183 quantizationDistances.
resize(numClusters,0);
215 errorLog <<
"train_(MatrixFloat &trainingData) - Failed to train quantizer, the training data is empty!" << std::endl;
220 rbm.setNumHiddenUnits( numClusters );
226 if( !rbm.
train_( trainingData ) ){
227 errorLog <<
"train_(MatrixFloat &trainingData) - Failed to train quantizer!" << std::endl;
234 numInputDimensions = trainingData.
getNumCols();
235 numOutputDimensions = 1;
236 featureVector.
resize(numOutputDimensions,0);
237 quantizationDistances.
resize(numClusters,0);
249 errorLog <<
"quantize(const VectorFloat &inputVector) - The quantizer model has not been trained!" << std::endl;
253 if( inputVector.
getSize() != numInputDimensions ){
254 errorLog <<
"quantize(const VectorFloat &inputVector) - The size of the inputVector (" << inputVector.
getSize() <<
") does not match that of the filter (" << numInputDimensions <<
")!" << std::endl;
258 if( !rbm.
predict( inputVector ) ){
259 errorLog <<
"quantize(const VectorFloat &inputVector) - Failed to quantize input!" << std::endl;
263 quantizationDistances = rbm.getOutputData();
266 UINT quantizedValue = 0;
268 for(UINT k=0; k<numClusters; k++){
269 if( quantizationDistances[k] > maxValue ){
270 maxValue = quantizationDistances[k];
275 featureVector[0] = quantizedValue;
276 featureDataReady =
true;
278 return quantizedValue;
290 return (trained ? static_cast<UINT>(featureVector[0]) : 0);
294 return quantizationDistances;
303 this->numClusters = numClusters;
bool setLearningRate(const Float learningRate)
std::string getId() const
static std::string getId()
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)