Exemplo n.º 1
0
bool FFT::loadSettingsFromFile(fstream &file){
    
    if( !file.is_open() ){
        errorLog << "loadSettingsFromFile(fstream &file) - The file is not open!" << endl;
        return false;
    }
    
    string word;
    
    //Load the header
    file >> word;
    
    if( word != "GRT_FFT_FILE_V1.0" ){
        errorLog << "loadSettingsFromFile(fstream &file) - Invalid file format!" << endl;
        return false;     
    }
    
    if( !loadBaseSettingsFromFile( file ) ){
        errorLog << "loadBaseSettingsFromFile(fstream &file) - Failed to load base feature extraction settings from file!" << endl;
        return false;
    }
    
    file >> word;
    if( word != "HopSize:" ){
        errorLog << "loadSettingsFromFile(fstream &file) - Failed to read HopSize header!" << endl;
        return false;     
    }
    file >> hopSize;
    
    file >> word;
    if( word != "FftWindowSize:" ){
        errorLog << "loadSettingsFromFile(fstream &file) - Failed to read FftWindowSize header!" << endl;
        return false;     
    }
    file >> fftWindowSize;
    
    file >> word;
    if( word != "FftWindowFunction:" ){
        errorLog << "loadSettingsFromFile(fstream &file) - Failed to read FftWindowFunction header!" << endl;
        return false;     
    }
    file >> fftWindowFunction;
    
    file >> word;
    if( word != "ComputeMagnitude:" ){
        errorLog << "loadSettingsFromFile(fstream &file) - Failed to read ComputeMagnitude header!" << endl;
        return false;     
    }
    file >> computeMagnitude;
    
    file >> word;
    if( word != "ComputePhase:" ){
        errorLog << "loadSettingsFromFile(fstream &file) - Failed to read ComputePhase header!" << endl;
        return false;     
    }
    file >> computePhase;
    
    //Init the FFT module to ensure everything is initialized correctly
    return init(fftWindowSize,hopSize,numInputDimensions,fftWindowFunction,computeMagnitude,computePhase);
}
Exemplo n.º 2
0
bool RBMQuantizer::loadModelFromFile(fstream &file){
    
    //Clear any previous model
    clear();
    
    if( !file.is_open() ){
        errorLog << "loadModelFromFile(fstream &file) - The file is not open!" << endl;
        return false;
    }
    
    string word;
    
    //First, you should read and validate the header
    file >> word;
    if( word != "RBM_QUANTIZER_FILE_V1.0" ){
        errorLog << "loadModelFromFile(fstream &file) - Invalid file format!" << endl;
        return false;
    }
    
    //Second, you should load the base feature extraction settings to the file
    if( !loadBaseSettingsFromFile( file ) ){
        errorLog << "loadModelFromFile(fstream &file) - Failed to load base feature extraction settings from file!" << endl;
        return false;
    }
    
    file >> word;
    if( word != "QuantizerTrained:" ){
        errorLog << "loadModelFromFile(fstream &file) - Failed to load QuantizerTrained!" << endl;
        return false;
    }
    file >> trained;
    
    file >> word;
    if( word != "NumClusters:" ){
        errorLog << "loadModelFromFile(fstream &file) - Failed to load NumClusters!" << endl;
        return false;
    }
    file >> numClusters;
    
    if( trained ){
        if( !rbm.loadModelFromFile( file ) ){
            errorLog << "loadModelFromFile(fstream &file) - Failed to load SelfOrganizingMap settings from file!" << endl;
            return false;
        }
        initialized = true;
        featureDataReady = false;
        quantizationDistances.resize(numClusters,0);
    }
    
    return true;
}
bool KMeansQuantizer::loadSettingsFromFile(fstream &file){
    
    initialized = false;
    numClusters = 0;
    clusters.clear();
    quantizationDistances.clear();
    
    if( !file.is_open() ){
        errorLog << "loadSettingsFromFile(fstream &file) - The file is not open!" << endl;
        return false;
    }
    
    string word;
    
    //First, you should read and validate the header
    file >> word;
    if( word != "KMEANS_QUANTIZER_FILE_V1.0" ){
        errorLog << "loadSettingsFromFile(fstream &file) - Invalid file format!" << endl;
        return false;
    }
    
    //Second, you should load the base feature extraction settings to the file
    if( !loadBaseSettingsFromFile( file ) ){
        errorLog << "loadBaseSettingsFromFile(fstream &file) - Failed to load base feature extraction settings from file!" << endl;
        return false;
    }
    
    file >> word;
    if( word != "QuantizerTrained:" ){
        errorLog << "loadSettingsFromFile(fstream &file) - Failed to load QuantizerTrained!" << endl;
        return false;
    }
    file >> quantizerTrained;
    
    file >> word;
    if( word != "NumClusters:" ){
        errorLog << "loadSettingsFromFile(fstream &file) - Failed to load NumClusters!" << endl;
        return false;
    }
    file >> numClusters;
    
    if( quantizerTrained ){
        clusters.resize(numClusters, numInputDimensions);
        file >> word;
        if( word != "Clusters:" ){
            errorLog << "loadSettingsFromFile(fstream &file) - Failed to load Clusters!" << endl;
            return false;
        }
        
        for(UINT k=0; k<numClusters; k++){
            for(UINT j=0; j<numInputDimensions; j++){
                file >> clusters[k][j];
            }
        }
    }
    
    initialized = true;
    featureDataReady = false;
    quantizationDistances.resize(numClusters,0);
    return true;
}
Exemplo n.º 4
0
bool BernoulliRBM::loadLegacyModelFromFile( std::fstream &file ){
    
    std::string word;
    UINT numGibbsSteps = 0;
    
    if( !loadBaseSettingsFromFile( file ) ){
        errorLog <<"loadModelFromFile(fstream &file) - Failed to load base settings to file!" << std::endl;
        return false;
    }
    
    //Read the number of visible units
    file >> word;
    if( word != "NumVisibleUnits:" ){
        errorLog <<"loadModelFromFile(fstream &file) - Failed to read NumVisibleUnits header!" << std::endl;
        return false;
    }
    file >> numVisibleUnits;
    
    //Read the number of hidden units
    file >> word;
    if( word != "NumHiddenUnits:" ){
        errorLog <<"loadModelFromFile(fstream &file) - Failed to read NumHiddenUnits header!" << std::endl;
        return false;
    }
    file >> numHiddenUnits;
    
    //Read the number of training epochs
    file >> word;
    if( word != "NumTrainingEpochs:" ){
        errorLog <<"loadModelFromFile(fstream &file) - Failed to read NumTrainingEpochs header!" << std::endl;
        return false;
    }
    file >> maxNumEpochs;
    
    //Read the number of gibbs steps
    file >> word;
    if( word != "NumGibbsSteps:" ){
        errorLog <<"loadModelFromFile(fstream &file) - Failed to read NumGibbsSteps header!" << std::endl;
        return false;
    }
    file >> numGibbsSteps;
    
    //Read the learning rate
    file >> word;
    if( word != "LearningRate:" ){
        errorLog <<"loadModelFromFile(fstream &file) - Failed to read LearningRate header!" << std::endl;
        return false;
    }
    file >> learningRate;
    
    //Read the learning rate update
    file >> word;
    if( word != "LearningRateUpdate:" ){
        errorLog <<"loadModelFromFile(fstream &file) - Failed to read LearningRateUpdate header!" << std::endl;
        return false;
    }
    file >> learningRateUpdate;
    
    //Read the momentum
    file >> word;
    if( word != "Momentum:" ){
        errorLog <<"loadModelFromFile(fstream &file) - Failed to read Momentum header!" << std::endl;
        return false;
    }
    file >> momentum;
    
    //Read the randomizeWeightsForTraining
    file >> word;
    if( word != "RandomizeWeightsForTraining:" ){
        errorLog <<"loadModelFromFile(fstream &file) - Failed to read RandomizeWeightsForTraining header!" << std::endl;
        return false;
    }
    file >> randomizeWeightsForTraining;
    
    //Read the ranges
    file >> word;
    if( word != "Ranges:" ){
        errorLog <<"loadModelFromFile(fstream &file) - Failed to read Ranges header!" << std::endl;
        return false;
    }
    ranges.resize(numInputDimensions);
    for(UINT n=0; n<ranges.size(); n++){
        file >> ranges[n].minValue;
        file >> ranges[n].maxValue;
    }
    
    //If the model has been trained then load the model
    if( trained ){
        
        //Load the weights matrix
        file >> word;
        if( word != "WeightsMatrix:" ){
            errorLog <<"loadModelFromFile(fstream &file) - Failed to read WeightsMatrix header!" << std::endl;
            return false;
        }
        weightsMatrix.resize(numHiddenUnits, numVisibleUnits);
        
        for(UINT i=0; i<weightsMatrix.getNumRows(); i++){
            for(UINT j=0; j<weightsMatrix.getNumCols(); j++){
                file >> weightsMatrix[i][j];
            }
        }
        
        //Load the VisibleLayerBias
        file >> word;
        if( word != "VisibleLayerBias:" ){
            errorLog <<"loadModelFromFile(fstream &file) - Failed to read VisibleLayerBias header!" << std::endl;
            return false;
        }
        visibleLayerBias.resize(numVisibleUnits);
        
        for(unsigned int i=0; i<visibleLayerBias.getSize(); i++){
            file >> visibleLayerBias[i];
        }
        
        //Load the HiddenLayerBias
        file >> word;
        if( word != "HiddenLayerBias:" ){
            errorLog <<"loadModelFromFile(fstream &file) - Failed to read HiddenLayerBias header!" << std::endl;
            return false;
        }
        hiddenLayerBias.resize(numHiddenUnits);
        
        for(unsigned int i=0; i<hiddenLayerBias.getSize(); i++){
            file >> hiddenLayerBias[i];
        }
    }
    
    return true;
}
Exemplo n.º 5
0
bool BernoulliRBM::loadModelFromFile( std::fstream &file ){
    
    if(!file.is_open())
    {
        errorLog <<"loadModelFromFile(fstream &file) - The file is not open!" << std::endl;
        return false;
    }
    
    std::string word;
    
    //Read the header info
    file >> word;
    
    if( word == "GRT_BERNOULLI_RBM_MODEL_FILE_V1.0" ){
        return loadLegacyModelFromFile( file );
    }
    
    if( word != "GRT_BERNOULLI_RBM_MODEL_FILE_V1.1" ){
        errorLog <<"loadModelFromFile(fstream &file) - Failed to read file header!" << std::endl;
        return false;
    }
    
    if( !loadBaseSettingsFromFile( file ) ){
        errorLog <<"loadModelFromFile(fstream &file) - Failed to load base settings to file!" << std::endl;
        return false;
    }
    
    //Read the number of visible units
    file >> word;
    if( word != "NumVisibleUnits:" ){
        errorLog <<"loadModelFromFile(fstream &file) - Failed to read NumVisibleUnits header!" << std::endl;
        return false;
    }
    file >> numVisibleUnits;
    
    //Read the number of hidden units
    file >> word;
    if( word != "NumHiddenUnits:" ){
        errorLog <<"loadModelFromFile(fstream &file) - Failed to read NumHiddenUnits header!" << std::endl;
        return false;
    }
    file >> numHiddenUnits;
    
    //Read the batch size
    file >> word;
    if( word != "BatchSize:" ){
        errorLog <<"loadModelFromFile(fstream &file) - Failed to read BatchSize header!" << std::endl;
        return false;
    }
    file >> batchSize;
    
    //Read the batch step size
    file >> word;
    if( word != "BatchStepSize:" ){
        errorLog <<"loadModelFromFile(fstream &file) - Failed to read BatchStepSize header!" << std::endl;
        return false;
    }
    file >> batchStepSize;
    
    //Read the learning rate
    file >> word;
    if( word != "LearningRate:" ){
        errorLog <<"loadModelFromFile(fstream &file) - Failed to read LearningRate header!" << std::endl;
        return false;
    }
    file >> learningRate;
    
    //Read the learning rate update
    file >> word;
    if( word != "LearningRateUpdate:" ){
        errorLog <<"loadModelFromFile(fstream &file) - Failed to read LearningRateUpdate header!" << std::endl;
        return false;
    }
    file >> learningRateUpdate;
    
    //Read the momentum
    file >> word;
    if( word != "Momentum:" ){
        errorLog <<"loadModelFromFile(fstream &file) - Failed to read Momentum header!" << std::endl;
        return false;
    }
    file >> momentum;
    
    //Read the randomizeWeightsForTraining
    file >> word;
    if( word != "RandomizeWeightsForTraining:" ){
        errorLog <<"loadModelFromFile(fstream &file) - Failed to read RandomizeWeightsForTraining header!" << std::endl;
        return false;
    }
    file >> randomizeWeightsForTraining;
    
    //Read the ranges
    file >> word;
    if( word != "Ranges:" ){
        errorLog <<"loadModelFromFile(fstream &file) - Failed to read Ranges header!" << std::endl;
        return false;
    }
    ranges.resize(numInputDimensions);
    for(UINT n=0; n<ranges.size(); n++){
        file >> ranges[n].minValue;
        file >> ranges[n].maxValue;
    }
    
    //If the model has been trained then load the model
    if( trained ){
        
        //Load the weights matrix
        file >> word;
        if( word != "WeightsMatrix:" ){
            errorLog <<"loadModelFromFile(fstream &file) - Failed to read WeightsMatrix header!" << std::endl;
            return false;
        }
        weightsMatrix.resize(numHiddenUnits, numVisibleUnits);
        
        for(UINT i=0; i<weightsMatrix.getNumRows(); i++){
            for(UINT j=0; j<weightsMatrix.getNumCols(); j++){
                file >> weightsMatrix[i][j];
            }
        }
        
        //Load the VisibleLayerBias
        file >> word;
        if( word != "VisibleLayerBias:" ){
            errorLog <<"loadModelFromFile(fstream &file) - Failed to read VisibleLayerBias header!" << std::endl;
            return false;
        }
        visibleLayerBias.resize(numVisibleUnits);

        for(unsigned int i=0; i<visibleLayerBias.size(); i++){
            file >> visibleLayerBias[i];
        }
        
        //Load the HiddenLayerBias
        file >> word;
        if( word != "HiddenLayerBias:" ){
            errorLog <<"loadModelFromFile(fstream &file) - Failed to read HiddenLayerBias header!" << std::endl;
            return false;
        }
        hiddenLayerBias.resize(numHiddenUnits);
        
        for(unsigned int i=0; i<hiddenLayerBias.size(); i++){
            file >> hiddenLayerBias[i];
        }
    }
    
    return true;
}
bool KMeansFeatures::loadSettingsFromFile(fstream &file){
    
    clear();
    
    if( !file.is_open() ){
        errorLog << "loadSettingsFromFile(fstream &file) - The file is not open!" << endl;
        return false;
    }
    
    string word;
    UINT numLayers = 0;
    UINT numRows = 0;
    UINT numCols = 0;
    
    //First, you should read and validate the header
    file >> word;
    if( word != "KMEANS_FEATURES_FILE_V1.0" ){
        errorLog << "loadSettingsFromFile(fstream &file) - Invalid file format!" << endl;
        return false;
    }
    
    //Second, you should load the base feature extraction settings to the file
    if( !loadBaseSettingsFromFile( file ) ){
        errorLog << "loadSettingsFromFile(fstream &file) - Failed to load base feature extraction settings from file!" << endl;
        return false;
    }
    
    //Load the number of layers
    file >> word;
    if( word != "NumLayers:" ){
        errorLog << "loadSettingsFromFile(fstream &file) - Failed to read NumLayers header!" << endl;
        return false;
    }
    file >> numLayers;
    numClustersPerLayer.resize( numLayers );
    
    //Load the number clusters per layer
    file >> word;
    if( word != "NumClustersPerLayer:" ){
        errorLog << "loadSettingsFromFile(fstream &file) - Failed to read NumClustersPerLayer header!" << endl;
        return false;
    }
    for(UINT i=0; i<numClustersPerLayer.size(); i++){
        file >> numClustersPerLayer[i];
    }
    
    //Load the alpha parameter
    file >> word;
    if( word != "Alpha:" ){
        errorLog << "loadSettingsFromFile(fstream &file) - Failed to read Alpha header!" << endl;
        return false;
    }
    file >> alpha;
    
    //If the model has been trained then load it
    if( trained ){
        
        //Load the Ranges
        file >> word;
        if( word != "Ranges:" ){
            errorLog << "loadSettingsFromFile(fstream &file) - Failed to read Ranges header!" << endl;
            return false;
        }
        ranges.resize(numInputDimensions);
        for(UINT i=0; i<ranges.size(); i++){
            file >> ranges[i].minValue;
            file >> ranges[i].maxValue;
        }
        
        //Load the Clusters
        file >> word;
        if( word != "Clusters:" ){
            errorLog << "loadSettingsFromFile(fstream &file) - Failed to read Clusters header!" << endl;
            return false;
        }
        clusters.resize( numLayers );
        
        for(UINT k=0; k<clusters.size(); k++){
            
            //Load the NumRows
            file >> word;
            if( word != "NumRows:" ){
                errorLog << "loadSettingsFromFile(fstream &file) - Failed to read NumRows header!" << endl;
                return false;
            }
            file >> numRows;
            
            //Load the NumCols
            file >> word;
            if( word != "NumCols:" ){
                errorLog << "loadSettingsFromFile(fstream &file) - Failed to read NumCols header!" << endl;
                return false;
            }
            file >> numCols;
            
            clusters[k].resize(numRows, numCols);
            for(UINT i=0; i<clusters[k].getNumRows(); i++){
                for(UINT j=0; j<clusters[k].getNumCols(); j++){
                    file >> clusters[k][i][j];
                }
            }
        }
    }
    
    return true;
}
bool MovementTrajectoryFeatures::loadSettingsFromFile(fstream &file){
    
    if( !file.is_open() ){
        errorLog << "loadSettingsFromFile(fstream &file) - The file is not open!" << endl;
        return false;
    }
    
    string word;
    
    //Load the header
    file >> word;
    
    if( word != "GRT_MOVEMENT_TRAJECTORY_FEATURES_FILE_V1.0" ){
        errorLog << "loadSettingsFromFile(fstream &file) - Invalid file format!" << endl;
        return false;     
    }
    
    if( !loadBaseSettingsFromFile( file ) ){
        errorLog << "loadBaseSettingsFromFile(fstream &file) - Failed to load base feature extraction settings from file!" << endl;
        return false;
    }
    
    //Load the TrajectoryLength
    file >> word;
    if( word != "TrajectoryLength:" ){
        errorLog << "loadSettingsFromFile(fstream &file) - Failed to read TrajectoryLength header!" << endl;
        return false;     
    }
    file >> trajectoryLength;
    
    //Load the NumCentroids
    file >> word;
    if( word != "NumCentroids:" ){
        errorLog << "loadSettingsFromFile(fstream &file) - Failed to read NumCentroids header!" << endl;
        return false;     
    }
    file >> numCentroids;
    
    //Load the FeatureMode
    file >> word;
    if( word != "FeatureMode:" ){
        errorLog << "loadSettingsFromFile(fstream &file) - Failed to read FeatureMode header!" << endl;
        return false;     
    }
    file >> featureMode;
    
    //Load the NumHistogramBins
    file >> word;
    if( word != "NumHistogramBins:" ){
        errorLog << "loadSettingsFromFile(fstream &file) - Failed to read NumHistogramBins header!" << endl;
        return false;     
    }
    file >> numHistogramBins;
    
    //Load the UseTrajStartAndEndValues
    file >> word;
    if( word != "UseTrajStartAndEndValues:" ){
        errorLog << "loadSettingsFromFile(fstream &file) - Failed to read UseTrajStartAndEndValues header!" << endl;
        return false;     
    }
    file >> useTrajStartAndEndValues;
    
    //Load the UseWeightedMagnitudeValues
    file >> word;
    if( word != "UseWeightedMagnitudeValues:" ){
        errorLog << "loadSettingsFromFile(fstream &file) - Failed to read UseWeightedMagnitudeValues header!" << endl;
        return false;     
    }
    file >> useWeightedMagnitudeValues;
    
    //Init the ZeroCrossingCounter module to ensure everything is initialized correctly
    return init(trajectoryLength,numCentroids,featureMode,numHistogramBins,numInputDimensions,useTrajStartAndEndValues,useWeightedMagnitudeValues);
}