]> git.donarmstrong.com Git - mothur.git/blob - rftreenode.hpp
changed random forest output filename
[mothur.git] / rftreenode.hpp
1 //
2 //  rftreenode.hpp
3 //  rrf-fs-prototype
4 //
5 //  Created by Abu Zaher Faridee on 5/29/12.
6 //  Copyright (c) 2012 Schloss Lab. All rights reserved.
7 //
8
9 #ifndef RF_RFTREENODE_HPP
10 #define RF_RFTREENODE_HPP
11
12 #include "mothurout.h"
13 #include "macros.h"
14
15 class RFTreeNode{
16     
17 public:
18     
19     RFTreeNode(vector< vector<int> > bootstrappedTrainingSamples,
20                vector<int> globalDiscardedFeatureIndices,
21                int numFeatures,
22                int numSamples,
23                int numOutputClasses,
24                int generation,
25                int nodeId,
26                float featureStandardDeviationThreshold = 0.0);
27     
28     virtual ~RFTreeNode(){}
29     
30     // getters
31     // we need to return const reference so that we have the actual value and not a copy, 
32     // plus we do not modify the value as well
33     const int getSplitFeatureIndex() { return splitFeatureIndex; }
34     // TODO: check if this works properly or returs a shallow copy of the data
35     const vector< vector<int> >& getBootstrappedTrainingSamples() { return bootstrappedTrainingSamples; }
36     const int getSplitFeatureValue() { return splitFeatureValue; }
37     const int getGeneration() { return generation; }
38     const bool checkIsLeaf() { return isLeaf; }
39     // TODO: fix this const pointer dillema
40     // we do not want to modify the data pointer by getLeftChildNode
41     RFTreeNode* getLeftChildNode() { return leftChildNode; }
42     RFTreeNode* getRightChildNode() { return rightChildNode; }
43     const int getOutputClass() { return outputClass; }
44     const int getNumSamples() { return numSamples; }
45     const int getNumFeatures() { return numFeatures; }
46     const vector<int>& getLocalDiscardedFeatureIndices() { return localDiscardedFeatureIndices; }
47     const vector< vector<int> >& getBootstrappedFeatureVectors() { return bootstrappedFeatureVectors; }
48     const vector<int>& getBootstrappedOutputVector() { return bootstrappedOutputVector; }
49     const vector<int>& getFeatureSubsetIndices() { return featureSubsetIndices; }
50     const double getOwnEntropy() { return ownEntropy; }
51     const int getTestSampleMisclassificationCount() { return testSampleMisclassificationCount; }
52     
53     // setters
54     void setIsLeaf(bool isLeaf) { this->isLeaf = isLeaf; }
55     void setOutputClass(int outputClass) { this->outputClass = outputClass; }
56     void setFeatureSubsetIndices(vector<int> featureSubsetIndices) { this->featureSubsetIndices = featureSubsetIndices; }
57     void setLeftChildNode(RFTreeNode* leftChildNode) { this->leftChildNode = leftChildNode; }
58     void setRightChildNode(RFTreeNode* rightChildNode) { this->rightChildNode = rightChildNode; }
59     void setParentNode(RFTreeNode* parentNode) { this->parentNode = parentNode; }
60     void setSplitFeatureIndex(int splitFeatureIndex) { this->splitFeatureIndex = splitFeatureIndex; }
61     void setSplitFeatureValue(int splitFeatureValue) { this->splitFeatureValue = splitFeatureValue; }
62     void setSplitFeatureEntropy(double splitFeatureEntropy) { this->splitFeatureEntropy = splitFeatureEntropy; }
63     
64     // TODO: need to remove this mechanism of friend class
65     //NOTE: friend classes can be useful for testing purposes, but I would avoid using them otherwise.
66     friend class DecisionTree;
67     friend class AbstractDecisionTree;
68     
69 private:
70     vector<vector<int> > bootstrappedTrainingSamples;
71     vector<int> globalDiscardedFeatureIndices;
72     vector<int> localDiscardedFeatureIndices;
73     vector<vector<int> > bootstrappedFeatureVectors;
74     vector<int> bootstrappedOutputVector;
75     vector<int> featureSubsetIndices;
76
77     int numFeatures;
78     int numSamples;
79     int numOutputClasses;
80     int generation;
81     bool isLeaf;
82     int outputClass;
83     int splitFeatureIndex;
84     int splitFeatureValue;
85     double splitFeatureEntropy;
86     double ownEntropy;
87     
88     int nodeId;
89     float featureStandardDeviationThreshold;
90     int testSampleMisclassificationCount;
91     
92     RFTreeNode* leftChildNode;
93     RFTreeNode* rightChildNode;
94     RFTreeNode* parentNode;
95     
96     MothurOut* m;
97     
98     int createLocalDiscardedFeatureList();
99     int updateNodeEntropy();
100     
101 };
102
103 #endif