2 // abstractrandomforest.cpp
5 // Created by Sarah Westcott on 10/1/12.
6 // Copyright (c) 2012 Schloss Lab. All rights reserved.
9 #include "abstractrandomforest.hpp"
11 /***********************************************************************/
12 AbstractRandomForest::AbstractRandomForest(const std::vector < std::vector<int> > dataSet,
13 const int numDecisionTrees,
14 const string treeSplitCriterion = "informationGain")
16 numDecisionTrees(numDecisionTrees),
17 numSamples((int)dataSet.size()),
18 numFeatures((int)(dataSet[0].size() - 1)),
19 globalDiscardedFeatureIndices(getGlobalDiscardedFeatureIndices()),
20 globalVariableImportanceList(numFeatures, 0),
21 treeSplitCriterion(treeSplitCriterion) {
22 m = MothurOut::getInstance();
23 // TODO: double check if the implemenatation of 'globalOutOfBagEstimates' is correct
26 /***********************************************************************/
28 vector<int> AbstractRandomForest::getGlobalDiscardedFeatureIndices() {
30 vector<int> globalDiscardedFeatureIndices;
32 // calculate feature vectors
33 vector< vector<int> > featureVectors(numFeatures, vector<int>(numSamples, 0));
34 for (int i = 0; i < numSamples; i++) {
35 if (m->control_pressed) { return globalDiscardedFeatureIndices; }
36 for (int j = 0; j < numFeatures; j++) { featureVectors[j][i] = dataSet[i][j]; }
39 for (int i = 0; i < featureVectors.size(); i++) {
40 if (m->control_pressed) { return globalDiscardedFeatureIndices; }
41 double standardDeviation = m->getStandardDeviation(featureVectors[i]);
42 if (standardDeviation <= 0){ globalDiscardedFeatureIndices.push_back(i); }
46 m->mothurOut("number of global discarded features: " + toString(globalDiscardedFeatureIndices.size())+ "\n");
47 m->mothurOut("total features: " + toString(featureVectors.size())+ "\n");
50 return globalDiscardedFeatureIndices;
53 m->errorOut(e, "AbstractRandomForest", "getGlobalDiscardedFeatureIndices");
58 /***********************************************************************/