Regressifier* Regressifier::deepCopy() const{
    
    Regressifier *newInstance = createInstanceFromString( regressifierType );
    
    if( newInstance == NULL ) return NULL;
    
    if( !newInstance->deepCopyFrom( this ) ){
        delete newInstance;
        return NULL;
    }
    return newInstance;
}
示例#2
0
Node* Node::createNewInstance() const{
    return createInstanceFromString( type );
}
bool MultidimensionalRegression::loadLegacyModelFromFile( fstream &file ){
    
    string word;
    
    file >> word;
    if(word != "NumFeatures:"){
        errorLog << "loadModelFromFile(string filename) - Could not find NumFeatures!" << endl;
        return false;
    }
    file >> numInputDimensions;
    
    file >> word;
    if(word != "NumOutputDimensions:"){
        errorLog << "loadModelFromFile(string filename) - Could not find NumOutputDimensions!" << endl;
        return false;
    }
    file >> numOutputDimensions;
    
    file >> word;
    if(word != "UseScaling:"){
        errorLog << "loadModelFromFile(string filename) - Could not find UseScaling!" << endl;
        return false;
    }
    file >> useScaling;
    
    ///Read the ranges if needed
    if( useScaling ){
        //Resize the ranges buffer
        inputVectorRanges.resize(numInputDimensions);
        targetVectorRanges.resize(numOutputDimensions);
        
        //Load the ranges
        file >> word;
        if(word != "InputVectorRanges:"){
            file.close();
            errorLog << "loadModelFromFile(string filename) - Failed to find InputVectorRanges!" << endl;
            return false;
        }
        for(UINT j=0; j<inputVectorRanges.size(); j++){
            file >> inputVectorRanges[j].minValue;
            file >> inputVectorRanges[j].maxValue;
        }
        
        file >> word;
        if(word != "OutputVectorRanges:"){
            file.close();
            errorLog << "loadModelFromFile(string filename) - Failed to find OutputVectorRanges!" << endl;
            return false;
        }
        for(UINT j=0; j<targetVectorRanges.size(); j++){
            file >> targetVectorRanges[j].minValue;
            file >> targetVectorRanges[j].maxValue;
        }
    }
    
    file >> word;
    if( word != "Regressifier:" ){
        errorLog << "loadModelFromFile(string filename) - Failed to find Regressifier!" << endl;
        return false;
    }
    
    //Load the regressifier type
    string regressifierType;
    file >> regressifierType;
    if( regressifierType == "NOT_SET" ){
        return true;
    }
    
    //Create the regressifer
    regressifier = createInstanceFromString( regressifierType );
    
    if( regressifier == NULL ){
        errorLog << "loadModelFromFile(fstream &file) - Failed to create regression instance from string!" << endl;
        return false;
    }
    
    if( !regressifier->loadModelFromFile( file ) ){
        errorLog <<"loadModelFromFile(fstream &file) - Failed to load regressifier!" << endl;
        return false;
    }
    
    if( numOutputDimensions > 0 ){
        //Initialize the regression modules
        regressionModules.resize(numOutputDimensions, NULL);
        
        for(UINT i=0; i<regressionModules.size(); i++){
            regressionModules[i] = createInstanceFromString( regressifierType );
            if( !regressionModules[i]->loadModelFromFile( file ) ){
                errorLog << "loadModelFromFile(fstream &file) - Failed to load regression module " << i << endl;
                return false;
            }
        }
        
        //Resize the regression data vector
        regressionData.resize(numOutputDimensions,0);
        
        //Flag that the model has been trained
        trained = true;
    }

    return true;
}
PreProcessing* PreProcessing::createNewInstance() const{
    return createInstanceFromString(preProcessingType);
}
Context* Context::createNewInstance() const{
    return createInstanceFromString( contextType );
}
Regressifier* Regressifier::createNewInstance() const{
    return createInstanceFromString( regressifierType );
}
示例#7
0
文件: BAG.cpp 项目: eboix/Myo-Gesture
bool BAG::loadModelFromFile(fstream &file){
    
    clear();
    UINT ensembleSize = 0;
    
    if(!file.is_open())
    {
        errorLog << "loadModelFromFile(string filename) - Could not open file to load model" << endl;
        return false;
    }
    
    std::string word;
    file >> word;
    
    //Check to see if we should load a legacy file
    if( word == "GRT_BAG_MODEL_FILE_V1.0" ){
        return loadLegacyModelFromFile( file );
    }
    
    //Find the file type header
    if(word != "GRT_BAG_MODEL_FILE_V2.0"){
        errorLog << "loadModelFromFile(string filename) - Could not find Model File Header" << endl;
        return false;
    }
    
    //Load the base settings from the file
    if( !Classifier::loadBaseSettingsFromFile(file) ){
        errorLog << "loadModelFromFile(string filename) - Failed to load base settings from file!" << endl;
        return false;
    }
    
    if( trained ){
        
        //Load the ensemble size
        file >> word;
        if(word != "EnsembleSize:"){
            errorLog << "loadModelFromFile(string filename) - Could not find the EnsembleSize!" << endl;
            return false;
        }
        file >> ensembleSize;
        
        //Load the weights
        weights.resize( ensembleSize );
        
        file >> word;
        if(word != "Weights:"){
            errorLog << "loadModelFromFile(string filename) - Could not find the Weights!" << endl;
            return false;
        }
        for(UINT i=0; i<ensembleSize; i++){
            file >> weights[i];
        }
        
        //Load the classifier types
        vector< string > classifierTypes( ensembleSize );
        
        file >> word;
        if(word != "ClassifierTypes:"){
            errorLog << "loadModelFromFile(string filename) - Could not find the ClassifierTypes!" << endl;
            return false;
        }
        for(UINT i=0; i<ensembleSize; i++){
            file >> classifierTypes[i];
        }
        
        //Load the ensemble
        file >> word;
        if(word != "Ensemble:"){
            errorLog << "loadModelFromFile(string filename) - Could not find the Ensemble!" << endl;
            return false;
        }
        ensemble.resize(ensembleSize,NULL);
        for(UINT i=0; i<ensembleSize; i++){
            ensemble[i] = createInstanceFromString( classifierTypes[i] );
            
            if( ensemble[i] == NULL ){
                errorLog << "loadModelFromFile(string filename) - Could not create a new classifier instance from the classifierType: " << classifierTypes[i] << endl;
                clearEnsemble();
                return false;
            }
            
            if( !ensemble[i]->loadModelFromFile( file ) ){
                errorLog << "loadModelFromFile(string filename) - Failed to load ensemble classifier: " << i << endl;
                clearEnsemble();
                return false;
            }
        }
        
        //Recompute the null rejection thresholds
        recomputeNullRejectionThresholds();
        
        //Resize the prediction results to make sure it is setup for realtime prediction
        maxLikelihood = DEFAULT_NULL_LIKELIHOOD_VALUE;
        bestDistance = DEFAULT_NULL_DISTANCE_VALUE;
        classLikelihoods.resize(numClasses,DEFAULT_NULL_LIKELIHOOD_VALUE);
        classDistances.resize(numClasses,DEFAULT_NULL_DISTANCE_VALUE);
    }
    
    return true;
}
示例#8
0
Classifier* Classifier::createNewInstance() const{
    return createInstanceFromString( classifierType );
}
bool MultidimensionalRegression::loadModelFromFile( std::fstream &file ){
    
    trained = false;
    numInputDimensions = 0;
    deleteAll();
    
    if(!file.is_open())
    {
        errorLog << "loadModelFromFile(string filename) - Could not open file to load model" << std::endl;
        return false;
    }
    
    std::string word;
    
    //Find the file type header
    file >> word;
    
    //Check to see if we should load a legacy file
    if( word == "GRT_MULTIDIMENSIONAL_REGRESSION_MODEL_FILE_V1.0" ){
        return loadLegacyModelFromFile( file );
    }
    
    if( word != "GRT_MULTIDIMENSIONAL_REGRESSION_MODEL_FILE_V2.0" ){
        errorLog << "loadModelFromFile( fstream &file ) - Could not find Model File Header" << std::endl;
        return false;
    }
    
    //Load the regressifier settings from the file
    if( !Regressifier::loadBaseSettingsFromFile(file) ){
        errorLog <<"loadModelFromFile( fstream &file ) - Failed to save Regressifier base settings to file!" << std::endl;
		return false;
    }
    
    file >> word;
    if( word != "Regressifier:" ){
        errorLog << "loadModelFromFile(string filename) - Failed to find Regressifier!" << std::endl;
        return false;
    }
    
    //Load the regressifier type
    std::string regressifierType;
    file >> regressifierType;
    if( regressifierType == "NOT_SET" ){
        return true;
    }
    
    //Create the regressifer
    regressifier = createInstanceFromString( regressifierType );
    
    if( regressifier == NULL ){
        errorLog << "loadModelFromFile(fstream &file) - Failed to create regression instance from string!" << std::endl;
        return false;
    }
    
    if( !regressifier->loadModelFromFile( file ) ){
        errorLog <<"loadModelFromFile(fstream &file) - Failed to load regressifier!" << std::endl;
        return false;
    }
    
    if( numOutputDimensions > 0 ){
        //Initialize the regression modules
        regressionModules.resize(numOutputDimensions, NULL);
        
        for(UINT i=0; i<regressionModules.getSize(); i++){
            regressionModules[i] = createInstanceFromString( regressifierType );
            if( !regressionModules[i]->loadModelFromFile( file ) ){
                errorLog << "loadModelFromFile(fstream &file) - Failed to load regression module " << i << std::endl;
                return false;
            }
        }
    }
    
    return true;
}
示例#10
0
FeatureExtraction* FeatureExtraction::createNewInstance() const{
    return createInstanceFromString(featureExtractionType);
}
示例#11
0
文件: BAG.cpp 项目: pixelmaid/evodraw
bool BAG::loadModelFromFile(fstream &file){
    
    trained = false;
    numFeatures = 0;
    numClasses = 0;
    classLabels.clear();
    clearEnsemble();
    UINT ensembleSize = 0;
    
    if(!file.is_open())
    {
        errorLog << "loadModelFromFile(string filename) - Could not open file to load model" << endl;
        return false;
    }
    
    std::string word;
    
    //Find the file type header
    file >> word;
    if(word != "GRT_BAG_MODEL_FILE_V1.0"){
        errorLog << "loadModelFromFile(string filename) - Could not find Model File Header" << endl;
        return false;
    }
    
    file >> word;
    if(word != "Trained:"){
        errorLog << "loadModelFromFile(string filename) - Could not find Trained Header" << endl;
        return false;
    }
    file >> trained;
    
    file >> word;
    if(word != "NumFeatures:"){
        errorLog << "loadModelFromFile(string filename) - Could not find NumFeatures!" << endl;
        return false;
    }
    file >> numFeatures;
    
    file >> word;
    if(word != "NumClasses:"){
        errorLog << "loadModelFromFile(string filename) - Could not find NumClasses!" << endl;
        return false;
    }
    file >> numClasses;
    
    file >> word;
    if(word != "UseScaling:"){
        errorLog << "loadModelFromFile(string filename) - Could not find UseScaling!" << endl;
        return false;
    }
    file >> useScaling;
    
    file >> word;
    if(word != "UseNullRejection:"){
        errorLog << "loadModelFromFile(string filename) - Could not find UseNullRejection!" << endl;
        return false;
    }
    file >> useNullRejection;
    
    ///Read the ranges if needed
    if( useScaling ){
        //Resize the ranges buffer
        ranges.resize(numFeatures);
        
        file >> word;
        if(word != "Ranges:"){
            errorLog << "loadModelFromFile(string filename) - Could not find the Ranges!" << endl;
            return false;
        }
        for(UINT n=0; n<ranges.size(); n++){
            file >> ranges[n].minValue;
            file >> ranges[n].maxValue;
        }
    }
    
    //Resize the buffer
    classLabels.resize(numClasses);
    
    //Load the class labels
    file >> word;
    if(word != "ClassLabels:"){
        errorLog << "loadModelFromFile(string filename) - Could not find the ClassLabels!" << endl;
        return false;
    }
    for(UINT i=0; i<numClasses; i++){
        file >> classLabels[i];
    }
    
    //Load the ensemble size
    file >> word;
    if(word != "EnsembleSize:"){
        errorLog << "loadModelFromFile(string filename) - Could not find the EnsembleSize!" << endl;
        return false;
    }
    file >> ensembleSize;
    
    if( ensembleSize > 0 ){
        
        //Load the weights
        weights.resize( ensembleSize );
        
        file >> word;
        if(word != "Weights:"){
            errorLog << "loadModelFromFile(string filename) - Could not find the Weights!" << endl;
            return false;
        }
        for(UINT i=0; i<ensembleSize; i++){
            file >> weights[i];
        }
        
        //Load the classifier types
        vector< string > classifierTypes( ensembleSize );
        
        file >> word;
        if(word != "ClassifierTypes:"){
            errorLog << "loadModelFromFile(string filename) - Could not find the ClassifierTypes!" << endl;
            return false;
        }
        for(UINT i=0; i<ensembleSize; i++){
            file >> classifierTypes[i];
        }
        
        //Load the ensemble
        file >> word;
        if(word != "Ensemble:"){
            errorLog << "loadModelFromFile(string filename) - Could not find the Ensemble!" << endl;
            return false;
        }
        ensemble.resize(ensembleSize,NULL);
        for(UINT i=0; i<ensembleSize; i++){
            ensemble[i] = createInstanceFromString( classifierTypes[i] );
            
            if( ensemble[i] == NULL ){
                errorLog << "loadModelFromFile(string filename) - Could not create a new classifier instance from the classifierType: " << classifierTypes[i] << endl;
                clearEnsemble();
                return false;
            }
            
            if( !ensemble[i]->loadModelFromFile( file ) ){
                errorLog << "loadModelFromFile(string filename) - Failed to load ensemble classifier: " << i << endl;
                clearEnsemble();
                return false;
            }
        }
        
    }