예제 #1
0
파일: BAG.cpp 프로젝트: eboix/Myo-Gesture
BAG& BAG::operator=(const BAG &rhs){
	if( this != &rhs ){
        //Clear any previous ensemble
        clearEnsemble();
        
        //Copy the weights
        this->weights = rhs.weights;
        
        //Deep copy each classifier in the ensemble
        for(UINT i=0; i<rhs.getEnsembleSize(); i++){
            addClassifierToEnsemble( *(rhs.ensemble[i]) );
        }
        //Copy the base classifier variables
        copyBaseVariables( (Classifier*)&rhs );
	}
	return *this;
}
예제 #2
0
파일: gui.cpp 프로젝트: AlbrechtL/dab-rpi
//	One can imagine that the band of operation is just selected
//	by the "ini" file, it is pretty unlikely that one changes
//	the band during operation
void	RadioInterface::set_bandSelect (QString s) {

	if (running) {
	   running	= false;
	   inputDevice	-> stopReader ();
	   inputDevice	-> resetBuffer ();
	   soundOut	-> stop ();
	   usleep (100);
	   clearEnsemble ();
	}

	if (s == "BAND III")
	   dabBand	= BAND_III;
	else
	   dabBand	= L_BAND;
    //setupChannels (channelSelector, dabBand);
}
예제 #3
0
파일: gui.cpp 프로젝트: AlbrechtL/dab-rpi
/**
  *	\brief setStart is a function that is called after pushing
  *	the start button.
  *	if "autoStart" == true, then the initializer will start
  *
  */
void	RadioInterface::setStart	(void) {
bool	r = 0;
	if (running)		// only listen when not running yet
	   return;
//
	r = inputDevice		-> restartReader ();
	qDebug ("Starting %d\n", r);
    if (!r) {
       qDebug ("Opening  input stream failed\n");
	   return;
    }
//
//	Of course, starting the machine will generate a new instance
//	of the ensemble, so the listing - if any - should be cleared
	clearEnsemble ();		// the display
//
///	this does not hurt
	soundOut	-> restart ();
	running = true;
}
예제 #4
0
파일: BAG.cpp 프로젝트: eboix/Myo-Gesture
bool BAG::deepCopyFrom(const Classifier *classifier){
    
    if( classifier == NULL ) return false;
    
    if( this->getClassifierType() == classifier->getClassifierType() ){
        BAG *ptr = (BAG*)classifier;
        
        //Clear any previous ensemble
        clearEnsemble();
        
        //Copy the weights
        this->weights = ptr->weights;
        
        //Deep copy each classifier in the ensemble
        for(UINT i=0; i<ptr->getEnsembleSize(); i++){
            addClassifierToEnsemble( *(ptr->ensemble[i]) );
        }
        //Copy the base classifier variables
        return copyBaseVariables( classifier );
    }
    return false;
}
예제 #5
0
파일: BAG.cpp 프로젝트: eboix/Myo-Gesture
BAG::~BAG(void)
{
    clearEnsemble();
}
예제 #6
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;
}
예제 #7
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;
            }
        }
        
    }