Ejemplo n.º 1
0
bool TimeseriesBuffer::load( std::fstream &file ){
    
    if( !file.is_open() ){
        errorLog << "load(fstream &file) - The file is not open!" << std::endl;
        return false;
    }
    
    std::string word;
    
    //Load the header
    file >> word;
    
    if( word != "GRT_TIMESERIES_BUFFER_FILE_V1.0" ){
        errorLog << "load(fstream &file) - Invalid file format!" << std::endl;
        return false;
    }
    
    if( !loadFeatureExtractionSettingsFromFile( file ) ){
        errorLog << "loadFeatureExtractionSettingsFromFile(fstream &file) - Failed to load base feature extraction settings from file!" << std::endl;
        return false;
    }
    
    file >> word;
    if( word != "BufferSize:" ){
        errorLog << "load(fstream &file) - Failed to read BufferSize header!" << std::endl;
        return false;
    }
    file >> bufferSize;
    
    //Init the TimeseriesBuffer module to ensure everything is initialized correctly
    return init(bufferSize,numInputDimensions);
}
Ejemplo n.º 2
0
bool MovementIndex::loadModelFromFile(fstream &file) {

    if( !file.is_open() ) {
        errorLog << "loadModelFromFile(fstream &file) - The file is not open!" << endl;
        return false;
    }

    string word;

    //Load the header
    file >> word;

    if( word != "GRT_MOVEMENT_INDEX_FILE_V1.0" ) {
        errorLog << "loadModelFromFile(fstream &file) - Invalid file format!" << endl;
        return false;
    }

    if( !loadFeatureExtractionSettingsFromFile( file ) ) {
        errorLog << "loadFeatureExtractionSettingsFromFile(fstream &file) - Failed to load base feature extraction settings from file!" << endl;
        return false;
    }

    //Load the BufferLength
    file >> word;
    if( word != "BufferLength:" ) {
        errorLog << "loadModelFromFile(fstream &file) - Failed to read BufferLength header!" << endl;
        return false;
    }
    file >> bufferLength;

    //Init the MovementIndex module to ensure everything is initialized correctly
    return init(bufferLength,numInputDimensions);
}
Ejemplo n.º 3
0
bool FFT::loadModelFromFile( std::fstream &file ){
    
    if( !file.is_open() ){
        errorLog << "loadModelFromFile(fstream &file) - The file is not open!" << std::endl;
        return false;
    }
    
    std::string word;
    
    //Load the header
    file >> word;
    
    if( word != "GRT_FFT_FILE_V1.0" ){
        errorLog << "loadModelFromFile(fstream &file) - Invalid file format!" << std::endl;
        return false;     
    }
    
    if( !loadFeatureExtractionSettingsFromFile( file ) ){
        errorLog << "loadFeatureExtractionSettingsFromFile(fstream &file) - Failed to load base feature extraction settings from file!" << std::endl;
        return false;
    }
    
    file >> word;
    if( word != "HopSize:" ){
        errorLog << "loadModelFromFile(fstream &file) - Failed to read HopSize header!" << std::endl;
        return false;     
    }
    file >> hopSize;
    
    file >> word;
    if( word != "FftWindowSize:" ){
        errorLog << "loadModelFromFile(fstream &file) - Failed to read FftWindowSize header!" << std::endl;
        return false;     
    }
    file >> fftWindowSize;
    
    file >> word;
    if( word != "FftWindowFunction:" ){
        errorLog << "loadModelFromFile(fstream &file) - Failed to read FftWindowFunction header!" << std::endl;
        return false;     
    }
    file >> fftWindowFunction;
    
    file >> word;
    if( word != "ComputeMagnitude:" ){
        errorLog << "loadModelFromFile(fstream &file) - Failed to read ComputeMagnitude header!" << std::endl;
        return false;     
    }
    file >> computeMagnitude;
    
    file >> word;
    if( word != "ComputePhase:" ){
        errorLog << "loadModelFromFile(fstream &file) - Failed to read ComputePhase header!" << std::endl;
        return false;     
    }
    file >> computePhase;
    
    //Init the FFT module to ensure everything is initialized correctly
    return init(fftWindowSize,hopSize,numInputDimensions,fftWindowFunction,computeMagnitude,computePhase);
}
Ejemplo n.º 4
0
bool KMeansQuantizer::loadModelFromFile( std::istream &file ){
    
    //Clear any previouly built model and settings
    clear();
    
    std::string word;
    
    //First, you should read and validate the header
    file >> word;
    if( word != "KMEANS_QUANTIZER_FILE_V1.0" ){
        errorLog << "loadModelFromFile(istream &file) - Invalid file format!" << std::endl;
        return false;
    }
    
    //Second, you should load the base feature extraction settings to the file
    if( !loadFeatureExtractionSettingsFromFile( file ) ){
        errorLog << "loadFeatureExtractionSettingsFromFile(istream &file) - Failed to load base feature extraction settings from file!" << std::endl;
        return false;
    }
    
    file >> word;
    if( word != "QuantizerTrained:" ){
        errorLog << "loadModelFromFile(istream &file) - Failed to load QuantizerTrained!" << std::endl;
        return false;
    }
    file >> trained;
    
    file >> word;
    if( word != "NumClusters:" ){
        errorLog << "loadModelFromFile(istream &file) - Failed to load NumClusters!" << std::endl;
        return false;
    }
    file >> numClusters;
    
    if( trained ){
        clusters.resize(numClusters, numInputDimensions);
        file >> word;
        if( word != "Clusters:" ){
            errorLog << "loadModelFromFile(istream &file) - Failed to load Clusters!" << std::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;
}
Ejemplo n.º 5
0
bool RBMQuantizer::load( std::fstream &file ){
    
    //Clear any previous model
    clear();
    
    if( !file.is_open() ){
        errorLog << "load(fstream &file) - The file is not open!" << std::endl;
        return false;
    }
    
    std::string word;
    
    //First, you should read and validate the header
    file >> word;
    if( word != "RBM_QUANTIZER_FILE_V1.0" ){
        errorLog << "load(fstream &file) - Invalid file format!" << std::endl;
        return false;
    }
    
    //Second, you should load the base feature extraction settings to the file
    if( !loadFeatureExtractionSettingsFromFile( file ) ){
        errorLog << "loadFeatureExtractionSettingsFromFile(fstream &file) - Failed to load base feature extraction settings from file!" << std::endl;
        return false;
    }
    
    file >> word;
    if( word != "QuantizerTrained:" ){
        errorLog << "load(fstream &file) - Failed to load QuantizerTrained!" << std::endl;
        return false;
    }
    file >> trained;
    
    file >> word;
    if( word != "NumClusters:" ){
        errorLog << "load(fstream &file) - Failed to load NumClusters!" << std::endl;
        return false;
    }
    file >> numClusters;
    
    if( trained ){
        if( !rbm.load( file ) ){
            errorLog << "load(fstream &file) - Failed to load SelfOrganizingMap settings from file!" << std::endl;
            return false;
        }
        initialized = true;
        featureDataReady = false;
        quantizationDistances.resize(numClusters,0);
    }
    
    return true;
}
Ejemplo n.º 6
0
bool ThresholdDetection::loadModelFromFile(fstream &file){
    
    if( !file.is_open() ){
        errorLog << "loadModelFromFile(fstream &file) - The file is not open!" << endl;
        return false;
    }
    
    string word;
    
    //Load the header
    file >> word;
    
    if( word != "GRT_THRESHOLD_DETECTION_FILE_V1.0" ){
        errorLog << "loadModelFromFile(fstream &file) - Invalid file format!" << endl;
        return false;     
    }
    
    if( !loadFeatureExtractionSettingsFromFile( file ) ){
        errorLog << "loadFeatureExtractionSettingsFromFile(fstream &file) - Failed to load base feature extraction settings from file!" << endl;
        return false;
    }
    
    //Load the BufferLength
    file >> word;
    if( word != "BufferLength:" ){
        errorLog << "loadModelFromFile(fstream &file) - Failed to read BufferLength header!" << endl;
        return false;     
    }
    file >> bufferLength;
    
    //Load the NumFrames
    file >> word;
    if( word != "Alpha:" ){
        errorLog << "loadModelFromFile(fstream &file) - Failed to read Alpha header!" << endl;
        return false;     
    }
    file >> alpha;
    
    //Load the OffsetInput
    file >> word;
    if( word != "Beta:" ){
        errorLog << "loadModelFromFile(fstream &file) - Failed to read Beta header!" << endl;
        return false;     
    }
    file >> beta;
    
    //Init the ThresholdDetection module to ensure everything is initialized correctly
    return init(bufferLength,numInputDimensions,alpha,beta);
}
Ejemplo n.º 7
0
bool ZeroCrossingCounter::loadModelFromFile( std::fstream &file ){
    
    if( !file.is_open() ){
        errorLog << "loadModelFromFile(fstream &file) - The file is not open!" << std::endl;
        return false;
    }
    
    std::string word;
    
    //Load the header
    file >> word;
    
    if( word != "GRT_ZERO_CROSSING_COUNTER_FILE_V1.0" ){
        errorLog << "loadModelFromFile(fstream &file) - Invalid file format!" << std::endl;
        return false;     
    }
    
    if( !loadFeatureExtractionSettingsFromFile( file ) ){
        errorLog << "loadFeatureExtractionSettingsFromFile(fstream &file) - Failed to load base feature extraction settings from file!" << std::endl;
        return false;
    }
    
    file >> word;
    if( word != "SearchWindowSize:" ){
        errorLog << "loadModelFromFile(fstream &file) - Failed to read SearchWindowSize header!" << std::endl;
        return false;     
    }
    file >> searchWindowSize;
    
    file >> word;
    if( word != "FeatureMode:" ){
        errorLog << "loadModelFromFile(fstream &file) - Failed to read FeatureMode header!" << std::endl;
        return false;     
    }
    file >> featureMode;
    
    file >> word;
    if( word != "DeadZoneThreshold:" ){
        errorLog << "loadModelFromFile(fstream &file) - Failed to read DeadZoneThreshold header!" << std::endl;
        return false;     
    }
    file >> deadZoneThreshold;
    
    //Init the ZeroCrossingCounter module to ensure everything is initialized correctly
    return init(searchWindowSize,deadZoneThreshold,numInputDimensions,featureMode);
}
Ejemplo n.º 8
0
bool TimeDomainFeatures::loadModelFromFile(fstream &file){
    
    if( !file.is_open() ){
        errorLog << "loadModelFromFile(fstream &file) - The file is not open!" << endl;
        return false;
    }
    
    string word;
    
    //Load the header
    file >> word;
    
    if( word != "GRT_TIME_DOMAIN_FEATURES_FILE_V1.0" ){
        errorLog << "loadModelFromFile(fstream &file) - Invalid file format!" << endl;
        return false;     
    }
    
    if( !loadFeatureExtractionSettingsFromFile( file ) ){
        errorLog << "loadFeatureExtractionSettingsFromFile(fstream &file) - Failed to load base feature extraction settings from file!" << endl;
        return false;
    }
    
    //Load the BufferLength
    file >> word;
    if( word != "BufferLength:" ){
        errorLog << "loadModelFromFile(fstream &file) - Failed to read BufferLength header!" << endl;
        return false;     
    }
    file >> bufferLength;
    
    //Load the NumFrames
    file >> word;
    if( word != "NumFrames:" ){
        errorLog << "loadModelFromFile(fstream &file) - Failed to read NumFrames header!" << endl;
        return false;     
    }
    file >> numFrames;
    
    //Load the OffsetInput
    file >> word;
    if( word != "OffsetInput:" ){
        errorLog << "loadModelFromFile(fstream &file) - Failed to read OffsetInput header!" << endl;
        return false;     
    }
    file >> offsetInput;
    
    //Load the UseMean
    file >> word;
    if( word != "UseMean:" ){
        errorLog << "loadModelFromFile(fstream &file) - Failed to read UseMean header!" << endl;
        return false;     
    }
    file >> useMean;
    
    //Load the UseStdDev
    file >> word;
    if( word != "UseStdDev:" ){
        errorLog << "loadModelFromFile(fstream &file) - Failed to read UseStdDev header!" << endl;
        return false;     
    }
    file >> useStdDev;
    
    //Load the UseEuclideanNorm
    file >> word;
    if( word != "UseEuclideanNorm:" ){
        errorLog << "loadModelFromFile(fstream &file) - Failed to read UseEuclideanNorm header!" << endl;
        return false;     
    }
    file >> useEuclideanNorm;
    
    //Load the UseRMS
    file >> word;
    if( word != "UseRMS:" ){
        errorLog << "loadModelFromFile(fstream &file) - Failed to read UseRMS header!" << endl;
        return false;
    }
    file >> useRMS;
    
    //Init the TimeDomainFeatures module to ensure everything is initialized correctly
    return init(bufferLength,numFrames,numInputDimensions,offsetInput,useMean,useStdDev,useEuclideanNorm,useRMS);
}
Ejemplo n.º 9
0
bool KMeansFeatures::loadModelFromFile(fstream &file){
    
    clear();
    
    if( !file.is_open() ){
        errorLog << "loadModelFromFile(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 << "loadModelFromFile(fstream &file) - Invalid file format!" << endl;
        return false;
    }
    
    //Second, you should load the base feature extraction settings to the file
    if( !loadFeatureExtractionSettingsFromFile( file ) ){
        errorLog << "loadFeatureExtractionSettingsFromFile(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 << "loadModelFromFile(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 << "loadModelFromFile(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 << "loadModelFromFile(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 << "loadModelFromFile(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 << "loadModelFromFile(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 << "loadModelFromFile(fstream &file) - Failed to read NumRows header!" << endl;
                return false;
            }
            file >> numRows;
            
            //Load the NumCols
            file >> word;
            if( word != "NumCols:" ){
                errorLog << "loadModelFromFile(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;
}
Ejemplo n.º 10
0
bool FFTFeatures::loadModelFromFile( std::fstream &file ){
    
    if( !file.is_open() ){
        errorLog << "loadModelFromFile(fstream &file) - The file is not open!" << std::endl;
        return false;
    }
    
    std::string word;
    
    //Load the header
    file >> word;
    
    if( word != "GRT_FFT_FEATURES_FILE_V1.0" ){
        errorLog << "loadModelFromFile(fstream &file) - Invalid file format!" << std::endl;
        return false;     
    }
    
    if( !loadFeatureExtractionSettingsFromFile( file ) ){
        errorLog << "loadFeatureExtractionSettingsFromFile(fstream &file) - Failed to load base feature extraction settings from file!" << std::endl;
        return false;
    }
    
    //Load the FFTWindowSize
    file >> word;
    if( word != "FFTWindowSize:" ){
        errorLog << "loadModelFromFile(fstream &file) - Failed to read FFTWindowSize header!" << std::endl;
        return false;     
    }
    file >> fftWindowSize;
    
    //Load the NumOutputDimensions
    file >> word;
    if( word != "NumChannelsInFFTSignal:" ){
        errorLog << "loadModelFromFile(fstream &file) - Failed to read NumChannelsInFFTSignal header!" << std::endl;
        return false;     
    }
    file >> numChannelsInFFTSignal;
    
    file >> word;
    if( word != "ComputeMaxFreqFeature:" ){
        errorLog << "loadModelFromFile(fstream &file) - Failed to read ComputeMaxFreqFeature header!" << std::endl;
        return false;     
    }
    file >> computeMaxFreqFeature;
    
    file >> word;
    if( word != "ComputeMaxFreqSpectrumRatio:" ){
        errorLog << "loadModelFromFile(fstream &file) - Failed to read ComputeMaxFreqSpectrumRatio header!" << std::endl;
        return false;     
    }
    file >> computeMaxFreqSpectrumRatio;
    
    file >> word;
    if( word != "ComputeCentroidFeature:" ){
        errorLog << "loadModelFromFile(fstream &file) - Failed to read ComputeCentroidFeature header!" << std::endl;
        return false;     
    }
    file >> computeCentroidFeature;
    
    file >> word;
    if( word != "ComputeTopNFreqFeatures:" ){
        errorLog << "loadModelFromFile(fstream &file) - Failed to read ComputeTopNFreqFeatures header!" << std::endl;
        return false;     
    }
    file >> computeTopNFreqFeatures;
    
    file >> word;
    if( word != "N:" ){
        errorLog << "loadModelFromFile(fstream &file) - Failed to read N header!" << std::endl;
        return false;     
    }
    file >> N;
    
    //Init the FFTFeatures module to ensure everything is initialized correctly
    return init(fftWindowSize,numChannelsInFFTSignal,computeMaxFreqFeature,computeMaxFreqSpectrumRatio,computeCentroidFeature,computeTopNFreqFeatures,N);
}