]> git.donarmstrong.com Git - mothur.git/commitdiff
restructuring random forest implementation
authorKathryn Iverson <kd.iverson@gmail.com>
Fri, 26 Oct 2012 21:16:10 +0000 (17:16 -0400)
committerKathryn Iverson <kd.iverson@gmail.com>
Fri, 26 Oct 2012 21:16:10 +0000 (17:16 -0400)
forest.cpp
forest.h
randomforest.cpp
randomforest.hpp

index 8ac1b79ca12c540ccb8c38498cc62b0201bc2f41..58c7f7e7d4d780b54d4c757e4653a368a60f6a74 100644 (file)
@@ -27,10 +27,11 @@ treeSplitCriterion(treeSplitCriterion) {
 
 vector<int> Forest::getGlobalDiscardedFeatureIndices() {
     try {
-        vector<int> globalDiscardedFeatureIndices;
+        //vector<int> globalDiscardedFeatureIndices;
+        //globalDiscardedFeatureIndices.push_back(1);
         
         // calculate feature vectors
-        vector< vector<int> > featureVectors(numFeatures, vector<int>(numSamples, 0));
+        vector< vector<int> > featureVectors(numFeatures, vector<int>(numSamples, 0) );
         for (int i = 0; i < numSamples; i++) {
             if (m->control_pressed) { return globalDiscardedFeatureIndices; }
             for (int j = 0; j < numFeatures; j++) { featureVectors[j][i] = dataSet[i][j]; }
index c9d29dc2321325f216f04c325bffb38548b2b529..78f61b3646c446bd9279eb09986d7e5d4bdc10df 100644 (file)
--- a/forest.h
+++ b/forest.h
@@ -12,6 +12,7 @@
 #include <iostream>
 #include "mothurout.h"
 #include "macros.h"
+#include "decisiontree.hpp"
 #include "abstractdecisiontree.hpp"
 /***********************************************************************/
 //this is a re-implementation of the abstractrandomforest class
@@ -26,6 +27,7 @@ public:
     virtual int populateDecisionTrees() = 0;
     virtual int calcForrestErrorRate() = 0;
     virtual int calcForrestVariableImportance(string) = 0;
+    virtual int updateGlobalOutOfBagEstimates(DecisionTree* decisionTree) = 0;
     
     /***********************************************************************/
     
index 36a2c1a261f27514c394a370d0d97387ac9cbfac..bd96cd2f7177633e3d21181c95e7ff2c07682eb2 100644 (file)
@@ -11,7 +11,7 @@
 /***********************************************************************/
 
 RandomForest::RandomForest(const vector <vector<int> > dataSet,const int numDecisionTrees,
-             const string treeSplitCriterion = "informationGain") : AbstractRandomForest(dataSet, numDecisionTrees, treeSplitCriterion) {
+             const string treeSplitCriterion = "informationGain") : Forest(dataSet, numDecisionTrees, treeSplitCriterion) {
     m = MothurOut::getInstance();
 }
 
@@ -58,6 +58,7 @@ int RandomForest::calcForrestVariableImportance(string filename) {
         //could cause maintenance issues later if other types of Abstract decison trees are created that cannot be cast as a decision tree.
     for (int i = 0; i < decisionTrees.size(); i++) {
         if (m->control_pressed) { return 0; }
+        
         DecisionTree* decisionTree = dynamic_cast<DecisionTree*>(decisionTrees[i]);
         
         for (int j = 0; j < numFeatures; j++) {
@@ -127,7 +128,7 @@ int RandomForest::populateDecisionTrees() {
 }
 /***********************************************************************/
 // TODO: need to finalize bettween reference and pointer for DecisionTree [partially solved]
-// TODO: make this pure virtual in superclass
+// DONE: make this pure virtual in superclass
 // DONE
 int RandomForest::updateGlobalOutOfBagEstimates(DecisionTree* decisionTree) {
     try {
index e67a6b920130e50d5070190b92401737a06ab781..30eb43842f8cb280e1e4e95919909885f2702d28 100755 (executable)
@@ -10,7 +10,7 @@
 #define rrf_fs_prototype_randomforest_hpp
 
 #include "macros.h"
-#include "abstractrandomforest.hpp"
+#include "forest.h"
 #include "decisiontree.hpp"
 
 class RandomForest: public Forest {
@@ -23,14 +23,14 @@ public:
     
     //NOTE:: if you are going to dynamically cast, aren't you undoing the advantage of abstraction. Why abstract at all?
     //could cause maintenance issues later if other types of Abstract decison trees are created that cannot be cast as a decision tree.
-    virtual ~RandomForest() {
-        for (vector<AbstractDecisionTree*>::iterator it = decisionTrees.begin(); it != decisionTrees.end(); it++) {
-            // we know that this is decision tree, so we can do a dynamic_case<DecisionTree*> here
-            DecisionTree* decisionTree = dynamic_cast<DecisionTree*>(*it);
-            // calling the destructor by deleting
-            delete decisionTree;
-        }
-    }
+//    virtual ~RandomForest() {
+//        for (vector<AbstractDecisionTree*>::iterator it = decisionTrees.begin(); it != decisionTrees.end(); it++) {
+//            // we know that this is decision tree, so we can do a dynamic_case<DecisionTree*> here
+//            DecisionTree* decisionTree = dynamic_cast<DecisionTree*>(*it);
+//            // calling the destructor by deleting
+//            delete decisionTree;
+//        }
+//    }
     
     int calcForrestErrorRate();
     int calcForrestVariableImportance(string);