Esempio n. 1
0
int AbstractDecisionTree::createBootStrappedSamples(){
    try {    
        vector<bool> isInTrainingSamples(numSamples, false);
        Utils util;
        for (int i = 0; i < numSamples; i++) {
            if (m->getControl_pressed()) { return 0; }
        
            int randomIndex = util.getRandomIndex(numSamples-1);
            bootstrappedTrainingSamples.push_back(baseDataSet[randomIndex]);
            isInTrainingSamples[randomIndex] = true;
        }
        
        for (int i = 0; i < numSamples; i++) {
            if (m->getControl_pressed()) { return 0; }
            if (isInTrainingSamples[i]){ bootstrappedTrainingSampleIndices.push_back(i); }
            else{
                bootstrappedTestSamples.push_back(baseDataSet[i]);
                bootstrappedTestSampleIndices.push_back(i);
            }
        }
        
            // do the transpose of Test Samples
        for (int i = 0; i < bootstrappedTestSamples[0].size(); i++) {
            if (m->getControl_pressed()) { return 0; }
            
            vector<int> tmpFeatureVector(bootstrappedTestSamples.size(), 0);
            for (int j = 0; j < bootstrappedTestSamples.size(); j++) {
                if (m->getControl_pressed()) { return 0; }
                
                tmpFeatureVector[j] = bootstrappedTestSamples[j][i];
            }
            testSampleFeatureVectors.push_back(tmpFeatureVector);
        }
        
        return 0;
    }
	catch(exception& e) {
		m->errorOut(e, "AbstractDecisionTree", "createBootStrappedSamples");
		exit(1);
	} 
}
Esempio n. 2
0
int AbstractDecisionTree::createBootStrappedSamples(){
    try {    
        vector<bool> isInTrainingSamples(numSamples, false);
        
        for (int i = 0; i < numSamples; i++) {
            if (m->control_pressed) { return 0; }
            // TODO: optimize the rand() function call + double check if it's working properly
            int randomIndex = rand() % numSamples;
            bootstrappedTrainingSamples.push_back(baseDataSet[randomIndex]);
            isInTrainingSamples[randomIndex] = true;
        }
        
        for (int i = 0; i < numSamples; i++) {
            if (m->control_pressed) { return 0; }
            if (isInTrainingSamples[i]){ bootstrappedTrainingSampleIndices.push_back(i); }
            else{
                bootstrappedTestSamples.push_back(baseDataSet[i]);
                bootstrappedTestSampleIndices.push_back(i);
            }
        }
        
            // do the transpose of Test Samples
        for (int i = 0; i < bootstrappedTestSamples[0].size(); i++) {
            if (m->control_pressed) { return 0; }
            
            vector<int> tmpFeatureVector(bootstrappedTestSamples.size(), 0);
            for (int j = 0; j < bootstrappedTestSamples.size(); j++) {
                if (m->control_pressed) { return 0; }
                
                tmpFeatureVector[j] = bootstrappedTestSamples[j][i];
            }
            testSampleFeatureVectors.push_back(tmpFeatureVector);
        }
        
        return 0;
    }
	catch(exception& e) {
		m->errorOut(e, "AbstractDecisionTree", "createBootStrappedSamples");
		exit(1);
	} 
}