2 #define GRT_DLL_EXPORTS 23 classLikelihoods = classProbabilities;
24 predictedNodeID = nodeID;
28 if( leftChild == NULL && rightChild == NULL ){
29 classLikelihoods = classProbabilities;
30 predictedNodeID = nodeID;
31 warningLog << __GRT_LOG__ <<
" Left and right children are NULL but node not marked as leaf node!" << std::endl;
37 if( rightChild->
predict_( x, classLikelihoods ) ){
41 warningLog << __GRT_LOG__ <<
" Right child failed prediction!" << std::endl;
44 classLikelihoods = classProbabilities;
45 predictedNodeID = nodeID;
49 if( leftChild->
predict_( x, classLikelihoods ) ){
53 warningLog << __GRT_LOG__ <<
" Left child failed prediction!" << std::endl;
56 classLikelihoods = classProbabilities;
57 predictedNodeID = nodeID;
66 switch( trainingMode ){
67 case Tree::BEST_ITERATIVE_SPILT:
68 return computeBestSplitBestIterativeSplit( numSplittingSteps, trainingData, features, classLabels, featureIndex, minError );
70 case Tree::BEST_RANDOM_SPLIT:
71 return computeBestSplitBestRandomSplit( numSplittingSteps, trainingData, features, classLabels, featureIndex, minError );
74 errorLog << __GRT_LOG__ <<
" Uknown trainingMode!" << std::endl;
88 classProbabilities.clear();
96 for(UINT i=0; i<depth; i++) tab +=
"\t";
98 stream << tab <<
"depth: " << depth <<
" nodeSize: " << nodeSize <<
" isLeafNode: " << isLeafNode << std::endl;
99 stream << tab <<
"ClassProbabilities: ";
100 for(UINT i=0; i<classProbabilities.size(); i++){
101 stream << classProbabilities[i] <<
"\t";
105 if( leftChild != NULL ){
106 stream << tab <<
"LeftChild: " << std::endl;
110 if( rightChild != NULL ){
111 stream << tab <<
"RightChild: " << std::endl;
128 node->isLeafNode = isLeafNode;
129 node->nodeID = nodeID;
130 node->predictedNodeID = predictedNodeID;
131 node->nodeSize = nodeSize;
132 node->classProbabilities = classProbabilities;
136 node->leftChild = leftChild->
deepCopy();
137 node->leftChild->setParent( node );
142 node->rightChild = rightChild->
deepCopy();
143 node->rightChild->setParent( node );
146 return dynamic_cast< Node*
>(node);
154 return classProbabilities.
getSize();
158 return classProbabilities;
162 this->nodeSize = nodeSize;
163 this->classProbabilities = classProbabilities;
164 this->isLeafNode =
true;
169 this->nodeSize = nodeSize;
174 this->classProbabilities = classProbabilities;
178 UINT DecisionTreeNode::getClassLabelIndexValue(UINT classLabel,
const Vector< UINT > &classLabels){
179 const UINT N = classLabels.
getSize();
180 for(UINT i=0; i<N; i++){
181 if( classLabel == classLabels[i] )
virtual bool computeBestSplit(const UINT &trainingMode, const UINT &numSplittingSteps, const ClassificationData &trainingData, const Vector< UINT > &features, const Vector< UINT > &classLabels, UINT &featureIndex, Float &minError)
virtual bool clear() override
virtual bool getModel(std::ostream &stream) const override
DecisionTreeNode(const std::string id="DecisionTreeNode")
virtual bool predict_(VectorFloat &x) override
bool setClassProbabilities(const VectorFloat &classProbabilities)
virtual bool predict_(VectorFloat &x, VectorFloat &classLikelihoods) override
virtual Node * deepCopy() const override
UINT getNumClasses() const
virtual bool getModel(std::ostream &stream) const override
UINT getPredictedNodeID() const
bool setLeafNode(const UINT nodeSize, const VectorFloat &classProbabilities)
static Node * createInstanceFromString(std::string const &nodeType)
virtual ~DecisionTreeNode()
virtual bool clear() override
VectorFloat getClassProbabilities() const
bool setNodeSize(const UINT nodeSize)
virtual Node * deepCopy() const