5 // Created by Abu Zaher Faridee on 5/28/12.
6 // Copyright (c) 2012 Schloss Lab. All rights reserved.
9 #ifndef rrf_fs_prototype_decisiontree_hpp
10 #define rrf_fs_prototype_decisiontree_hpp
13 #include "rftreenode.hpp"
14 #include "abstractdecisiontree.hpp"
16 /***********************************************************************/
18 struct VariableRankDescendingSorter {
19 bool operator() (vector<int> first, vector<int> second){ return first[1] > second[1]; }
21 struct VariableRankDescendingSorterDouble {
22 bool operator() (vector<double> first, vector<double> second){ return first[1] > second[1]; }
24 /***********************************************************************/
26 class DecisionTree: public AbstractDecisionTree{
28 friend class RandomForest;
32 DecisionTree(vector< vector<int> > baseDataSet,
33 vector<int> globalDiscardedFeatureIndices,
34 OptimumFeatureSubsetSelector optimumFeatureSubsetSelector,
35 string treeSplitCriterion);
36 virtual ~DecisionTree(){ deleteTreeNodesRecursively(rootNode); }
38 int calcTreeVariableImportanceAndError();
39 int evaluateSample(vector<int> testSample);
40 int calcTreeErrorRate(int& numCorrect, double& treeErrorRate);
41 vector< vector<int> > randomlyShuffleAttribute(vector< vector<int> > samples, int featureIndex);
42 void purgeDataSetsFromTree() { purgeTreeNodesDataRecursively(rootNode); }
43 int purgeTreeNodesDataRecursively(RFTreeNode* treeNode);
48 void buildDecisionTree();
49 int splitRecursively(RFTreeNode* rootNode);
50 int findAndUpdateBestFeatureToSplitOn(RFTreeNode* node);
51 vector<int> selectFeatureSubsetRandomly(vector<int> globalDiscardedFeatureIndices, vector<int> localDiscardedFeatureIndices);
52 int printTree(RFTreeNode* treeNode, string caption);
53 void deleteTreeNodesRecursively(RFTreeNode* treeNode);
55 vector<int> variableImportanceList;
56 map<int, int> outOfBagEstimates;