bool KMeansQuantizer::saveSettingsToFile(fstream &file) const{
    
    if( !file.is_open() ){
        errorLog << "saveSettingsToFile(fstream &file) - The file is not open!" << endl;
        return false;
    }
    
    //First, you should add a header (with no spaces) e.g.
    file << "KMEANS_QUANTIZER_FILE_V1.0" << endl;
	
    //Second, you should save the base feature extraction settings to the file
    if( !saveBaseSettingsToFile( file ) ){
        errorLog << "saveSettingsToFile(fstream &file) - Failed to save base feature extraction settings to file!" << endl;
        return false;
    }
    
    file << "QuantizerTrained: " << quantizerTrained << endl;
    file << "NumClusters: " << numClusters << endl;
    
    if( quantizerTrained ){
        file << "Clusters: \n";
        for(UINT k=0; k<numClusters; k++){
            for(UINT j=0; j<numInputDimensions; j++){
                file << clusters[k][j];
                if( j != numInputDimensions-1 ) file << "\t";
                else file << endl;
            }
        }
    }
    
    return true;
}
Esempio n. 2
0
bool RBMQuantizer::saveModelToFile(fstream &file) const{
    
    if( !file.is_open() ){
        errorLog << "saveModelToFile(fstream &file) - The file is not open!" << endl;
        return false;
    }
    
    //Write the header
    file << "RBM_QUANTIZER_FILE_V1.0" << endl;
	
    //Save the base feature extraction settings to the file
    if( !saveBaseSettingsToFile( file ) ){
        errorLog << "saveModelToFile(fstream &file) - Failed to save base feature extraction settings to file!" << endl;
        return false;
    }
    
    file << "QuantizerTrained: " << trained << endl;
    file << "NumClusters: " << numClusters << endl;
    
    if( trained ){
        if( !rbm.saveModelToFile( file ) ){
            errorLog << "saveModelToFile(fstream &file) - Failed to save RBM settings to file!" << endl;
            return false;
        }
    }
    
    return true;
}
bool MovementTrajectoryFeatures::saveSettingsToFile(fstream &file) const{
    
    if( !file.is_open() ){
        errorLog << "saveSettingsToFile(fstream &file) - The file is not open!" << endl;
        return false;
    }
    
    //Write the file header
    file << "GRT_MOVEMENT_TRAJECTORY_FEATURES_FILE_V1.0" << endl;	
    
    //Save the base settings to the file
    if( !saveBaseSettingsToFile( file ) ){
        errorLog << "saveSettingsToFile(fstream &file) - Failed to save base feature extraction settings to file!" << endl;
        return false;
    }
    
    //Write the movement trajectory settings to the file
    file << "TrajectoryLength: " << trajectoryLength << endl;
    file << "NumCentroids: " << numCentroids << endl;
    file << "FeatureMode: " << featureMode << endl;
    file << "NumHistogramBins: " << numHistogramBins << endl;
    file << "UseTrajStartAndEndValues: " << useTrajStartAndEndValues << endl;
    file << "UseWeightedMagnitudeValues: " << useWeightedMagnitudeValues << endl;
    
    return true;
}
Esempio n. 4
0
bool FFT::saveSettingsToFile(fstream &file){
    
    if( !file.is_open() ){
        errorLog << "saveSettingsToFile(fstream &file) - The file is not open!" << endl;
        return false;
    }
    
    //Write the file header
    file << "GRT_FFT_FILE_V1.0" << endl;
    
    //Save the base settings to the file
    if( !saveBaseSettingsToFile( file ) ){
        errorLog << "saveSettingsToFile(fstream &file) - Failed to save base feature extraction settings to file!" << endl;
        return false;
    }
    
    //Write the FFT settings
    file << "HopSize: " << hopSize << endl;
    file << "FftWindowSize: " << fftWindowSize << endl;
    file << "FftWindowFunction: " << fftWindowFunction << endl;
    file << "ComputeMagnitude: " << computeMagnitude << endl;
    file << "ComputePhase: " << computePhase << endl;
    
    return true;
}
Esempio n. 5
0
bool BernoulliRBM::saveModelToFile( std::fstream &file ) const{
    
    if(!file.is_open())
	{
		errorLog <<"saveModelToFile(fstream &file) - The file is not open!" << std::endl;
		return false;
	}
    
	//Write the header info
	file<<"GRT_BERNOULLI_RBM_MODEL_FILE_V1.1\n";
    
    if( !saveBaseSettingsToFile( file ) ){
        errorLog <<"saveModelToFile(fstream &file) - Failed to save base settings to file!" << std::endl;
        return false;
    }
    
    file << "NumVisibleUnits: " << numVisibleUnits << std::endl;
    file << "NumHiddenUnits: " << numHiddenUnits << std::endl;
    file << "BatchSize: " << batchSize << std::endl;
    file << "BatchStepSize: " << batchStepSize << std::endl;
    file << "LearningRate: " << learningRate << std::endl;
    file << "LearningRateUpdate: " << learningRateUpdate << std::endl;
    file << "Momentum: " << momentum << std::endl;
    file << "RandomizeWeightsForTraining: " << randomizeWeightsForTraining << std::endl;
	
    file << "Ranges: \n";
    for(UINT n=0; n<ranges.size(); n++){
        file << ranges[n].minValue << "\t" << ranges[n].maxValue << std::endl;
    }
    
    //If the model has been trained then write the model
    if( trained ){
        file << "WeightsMatrix: " << std::endl;
        for(UINT i=0; i<weightsMatrix.getNumRows(); i++){
            for(UINT j=0; j<weightsMatrix.getNumCols(); j++){
                file << weightsMatrix[i][j];
                if( j < weightsMatrix.getNumCols()-1 ) file << " ";
            }
            file << std::endl;
        }
        
        file << "VisibleLayerBias: ";
        for(unsigned int i=0; i<visibleLayerBias.size(); i++){
            file << visibleLayerBias[i];
            if( i < visibleLayerBias.size()-1 ) file << " ";
        }
        file << std::endl;
        
        file << "HiddenLayerBias: ";
        for(unsigned int i=0; i<hiddenLayerBias.size(); i++){
            file << hiddenLayerBias[i];
            if( i < hiddenLayerBias.size()-1 ) file << " ";
        }
        file << std::endl;
    }
    
    return true;
}
bool KMeansFeatures::saveSettingsToFile(fstream &file) const{
    
    if( !file.is_open() ){
        errorLog << "saveSettingsToFile(fstream &file) - The file is not open!" << endl;
        return false;
    }
    
    //First, you should add a header (with no spaces) e.g.
    file << "KMEANS_FEATURES_FILE_V1.0" << endl;
	
    //Second, you should save the base feature extraction settings to the file
    if( !saveBaseSettingsToFile( file ) ){
        errorLog << "saveSettingsToFile(fstream &file) - Failed to save base feature extraction settings to file!" << endl;
        return false;
    }
    
    file << "NumLayers: " << getNumLayers() << endl;
    file << "NumClustersPerLayer: ";
    for(UINT i=0; i<numClustersPerLayer.size(); i++){
        file << " " << numClustersPerLayer[i];
    }
    file << endl;
    
    file << "Alpha: " << alpha << endl;
    
    if( trained ){
        file << "Ranges: ";
        for(UINT i=0; i<ranges.size(); i++){
            file << ranges[i].minValue << " " << ranges[i].maxValue << " ";
        }
        file << endl;
        
        file << "Clusters: " << endl;
        for(UINT k=0; k<clusters.size(); k++){
            file << "NumRows: " << clusters[k].getNumRows() << endl;
            file << "NumCols: " << clusters[k].getNumCols() << endl;
            for(UINT i=0; i<clusters[k].getNumRows(); i++){
                for(UINT j=0; j<clusters[k].getNumCols(); j++){
                    file << clusters[k][i][j];
                    if( j+1 < clusters[k].getNumCols() )
                        file << "\t";
                }
                file << endl;
            }
        }
    }
    
    return true;
}
bool TimeseriesBuffer::saveSettingsToFile(fstream &file) const{
    
    if( !file.is_open() ){
        errorLog << "saveSettingsToFile(fstream &file) - The file is not open!" << endl;
        return false;
    }
    
    //Write the file header
    file << "GRT_TIMESERIES_BUFFER_FILE_V1.0" << endl;
    
    //Save the base settings to the file
    if( !saveBaseSettingsToFile( file ) ){
        errorLog << "saveSettingsToFile(fstream &file) - Failed to save base feature extraction settings to file!" << endl;
        return false;
    }
    
    //Write the zero crossing counter settings
    file << "BufferSize: " << dataBuffer.getSize() << endl;
    
    return true;
}
bool MovementIndex::saveSettingsToFile(fstream &file) const{
    
    if( !file.is_open() ){
        errorLog << "saveSettingsToFile(fstream &file) - The file is not open!" << endl;
        return false;
    }
    
    //Write the file header
    file << "GRT_MOVEMENT_INDEX_FILE_V1.0" << endl;	
    
    //Save the base settings to the file
    if( !saveBaseSettingsToFile( file ) ){
        errorLog << "saveSettingsToFile(fstream &file) - Failed to save base feature extraction settings to file!" << endl;
        return false;
    }
    
    //Write the movement index settings to the file
    file << "BufferLength: " << bufferLength << endl;
    
    return true;
}