]> git.donarmstrong.com Git - mothur.git/blob - forest.cpp
sffinfo bug with flow grams right index when clipQualRight=0
[mothur.git] / forest.cpp
1 //
2 //  forest.cpp
3 //  Mothur
4 //
5 //  Created by Kathryn Iverson on 10/26/12.
6 //  Copyright (c) 2012 Schloss Lab. All rights reserved.
7 //
8
9 #include "forest.h"
10
11 /***********************************************************************/
12 Forest::Forest(const std::vector < std::vector<int> > dataSet,
13                                            const int numDecisionTrees,
14                                            const string treeSplitCriterion = "informationGain")
15 : dataSet(dataSet),
16 numDecisionTrees(numDecisionTrees),
17 numSamples((int)dataSet.size()),
18 numFeatures((int)(dataSet[0].size() - 1)),
19 globalVariableImportanceList(numFeatures, 0),
20 treeSplitCriterion(treeSplitCriterion) {
21     m = MothurOut::getInstance();
22     globalDiscardedFeatureIndices = getGlobalDiscardedFeatureIndices();
23     // TODO: double check if the implemenatation of 'globalOutOfBagEstimates' is correct
24 }
25
26 /***********************************************************************/
27
28 vector<int> Forest::getGlobalDiscardedFeatureIndices() {
29     try {
30         //vector<int> globalDiscardedFeatureIndices;
31         //globalDiscardedFeatureIndices.push_back(1);
32         
33         // calculate feature vectors
34         vector< vector<int> > featureVectors(numFeatures, vector<int>(numSamples, 0) );
35         for (int i = 0; i < numSamples; i++) {
36             if (m->control_pressed) { return globalDiscardedFeatureIndices; }
37             for (int j = 0; j < numFeatures; j++) { featureVectors[j][i] = dataSet[i][j]; }
38         }
39         
40         for (int i = 0; i < featureVectors.size(); i++) {
41             if (m->control_pressed) { return globalDiscardedFeatureIndices; }
42             double standardDeviation = m->getStandardDeviation(featureVectors[i]);
43             if (standardDeviation <= 0){ globalDiscardedFeatureIndices.push_back(i); }
44         }
45         
46         if (m->debug) {
47             m->mothurOut("number of global discarded features:  " + toString(globalDiscardedFeatureIndices.size())+ "\n");
48             m->mothurOut("total features: " + toString(featureVectors.size())+ "\n");
49         }
50         
51         return globalDiscardedFeatureIndices;
52     }
53         catch(exception& e) {
54                 m->errorOut(e, "Forest", "getGlobalDiscardedFeatureIndices");
55                 exit(1);
56         }
57 }
58
59 /***********************************************************************/
60