10 nodeType =
"DecisionTreeNode";
26 classLikelihoods = classProbabilities;
27 predictedNodeID = nodeID;
31 if( leftChild == NULL && rightChild == NULL )
36 if( rightChild->predict( x, classLikelihoods ) ){
37 predictedNodeID = rightChild->getPredictedNodeID();
40 warningLog <<
"predict(const VectorFloat &x,VectorFloat &classLikelihoods) - Right child failed prediction!" << std::endl;
45 if( leftChild->predict( x, classLikelihoods ) ){
46 predictedNodeID = leftChild->getPredictedNodeID();
49 warningLog <<
"predict(const VectorFloat &x,VectorFloat &classLikelihoods) - Left child failed prediction!" << std::endl;
59 switch( trainingMode ){
60 case Tree::BEST_ITERATIVE_SPILT:
61 return computeBestSpiltBestIterativeSpilt( numSplittingSteps, trainingData, features, classLabels, featureIndex, minError );
63 case Tree::BEST_RANDOM_SPLIT:
64 return computeBestSpiltBestRandomSpilt( numSplittingSteps, trainingData, features, classLabels, featureIndex, minError );
67 errorLog <<
"computeBestSpilt(...) - Uknown trainingMode!" << std::endl;
81 classProbabilities.clear();
89 for(UINT i=0; i<depth; i++) tab +=
"\t";
91 stream << tab <<
"depth: " << depth <<
" nodeSize: " << nodeSize <<
" isLeafNode: " << isLeafNode << std::endl;
92 stream << tab <<
"ClassProbabilities: ";
93 for(UINT i=0; i<classProbabilities.size(); i++){
94 stream << classProbabilities[i] <<
"\t";
98 if( leftChild != NULL ){
99 stream << tab <<
"LeftChild: " << std::endl;
100 leftChild->getModel( stream );
103 if( rightChild != NULL ){
104 stream << tab <<
"RightChild: " << std::endl;
105 rightChild->getModel( stream );
121 node->isLeafNode = isLeafNode;
122 node->nodeID = nodeID;
123 node->predictedNodeID = predictedNodeID;
124 node->nodeSize = nodeSize;
125 node->classProbabilities = classProbabilities;
130 node->leftChild->setParent( node );
136 node->rightChild->setParent( node );
151 return (UINT)classProbabilities.size();
155 return classProbabilities;
159 this->nodeSize = nodeSize;
160 this->classProbabilities = classProbabilities;
161 this->isLeafNode =
true;
166 this->nodeSize = nodeSize;
171 this->classProbabilities = classProbabilities;
175 UINT DecisionTreeNode::getClassLabelIndexValue(UINT classLabel,
const Vector< UINT > &classLabels){
176 const UINT N = classLabels.
getSize();
177 for(UINT i=0; i<N; i++){
178 if( classLabel == classLabels[i] )
virtual bool computeBestSpilt(const UINT &trainingMode, const UINT &numSplittingSteps, const ClassificationData &trainingData, const Vector< UINT > &features, const Vector< UINT > &classLabels, UINT &featureIndex, Float &minError)
bool setClassProbabilities(const VectorFloat &classProbabilities)
UINT getNumClasses() const
unsigned int getSize() const
virtual Node * deepCopyNode() const
This file implements a DecisionTreeNode, which is a specific base node used for a DecisionTree...
virtual bool predict(const VectorFloat &x, VectorFloat &classLikelihoods)
bool setLeafNode(const UINT nodeSize, const VectorFloat &classProbabilities)
DecisionTreeNode * deepCopy() const
static Node * createInstanceFromString(std::string const &nodeType)
virtual Node * deepCopyNode() const
virtual ~DecisionTreeNode()
virtual bool getModel(std::ostream &stream) const
VectorFloat getClassProbabilities() const
bool setNodeSize(const UINT nodeSize)