26 UINT Node::numNodeInstances = 0;
30 StringNodeMap::iterator iter = getMap()->find( nodeType );
31 if( iter == getMap()->end() ){
35 return iter->second();
47 debugLog.setProceedingText(
"[DEBUG Node]");
48 errorLog.setProceedingText(
"[ERROR Node]");
49 trainingLog.setProceedingText(
"[TRAINING Node]");
50 testingLog.setProceedingText(
"[TESTING Node]");
51 warningLog.setProceedingText(
"[WARNING Node]");
60 warningLog <<
"predict(const VectorFloat &x) - Base class not overwritten!" << std::endl;
65 warningLog <<
"predict(const VectorFloat &x) - Base class not overwritten!" << std::endl;
74 if( leftChild != NULL ){
83 if( rightChild != NULL ){
110 std::ostringstream stream;
112 std::cout << stream.str();
121 std::string tab =
"";
122 for(UINT i=0; i<depth; i++) tab +=
"\t";
124 stream << tab <<
"depth: " << depth <<
" isLeafNode: " << isLeafNode <<
" nodeID: " << nodeID << std::endl;
126 if( leftChild != NULL ){
127 stream << tab <<
"LeftChild: " << std::endl;
131 if( rightChild != NULL ){
132 stream << tab <<
"RightChild: " << std::endl;
143 errorLog <<
"saveToFile(fstream &file) - File is not open!" << std::endl;
147 file <<
"NodeType: " << nodeType << std::endl;
148 file <<
"Depth: " << depth << std::endl;
149 file <<
"NodeID: " << nodeID << std::endl;
150 file <<
"IsLeafNode: " << isLeafNode << std::endl;
156 file <<
"LeftChild\n";
158 errorLog <<
"saveToFile(fstream &file) - Failed to save left child at depth: " << depth << std::endl;
165 file <<
"RightChild\n";
167 errorLog <<
"saveToFile(fstream &file) - Failed to save right child at depth: " << depth << std::endl;
174 errorLog <<
"saveToFile(fstream &file) - Failed to save parameters to file at depth: " << depth << std::endl;
188 errorLog <<
"loadFromFile(fstream &file) - File is not open!" << std::endl;
193 bool hasLeftChild =
false;
194 bool hasRightChild =
false;
197 if( word !=
"NodeType:" ){
198 errorLog <<
"loadFromFile(fstream &file) - Failed to find Node header!" << std::endl;
204 if( word !=
"Depth:" ){
205 errorLog <<
"loadFromFile(fstream &file) - Failed to find Depth header!" << std::endl;
211 if( word !=
"NodeID:" ){
212 errorLog <<
"loadFromFile(fstream &file) - Failed to find NodeID header!" << std::endl;
218 if( word !=
"IsLeafNode:" ){
219 errorLog <<
"loadFromFile(fstream &file) - Failed to find IsLeafNode header!" << std::endl;
225 if( word !=
"HasLeftChild:" ){
226 errorLog <<
"loadFromFile(fstream &file) - Failed to find HasLeftChild header!" << std::endl;
229 file >> hasLeftChild;
232 if( word !=
"HasRightChild:" ){
233 errorLog <<
"loadFromFile(fstream &file) - Failed to find HasRightChild header!" << std::endl;
236 file >> hasRightChild;
240 if( word !=
"LeftChild" ){
241 errorLog <<
"loadFromFile(fstream &file) - Failed to find LeftChild header!" << std::endl;
245 leftChild->setParent(
this );
247 errorLog <<
"loadFromFile(fstream &file) - Failed to load left child at depth: " << depth << std::endl;
254 if( word !=
"RightChild" ){
255 errorLog <<
"loadFromFile(fstream &file) - Failed to find RightChild header!" << std::endl;
259 rightChild->setParent(
this );
261 errorLog <<
"loadFromFile(fstream &file) - Failed to load right child at depth: " << depth << std::endl;
268 errorLog <<
"loadParametersFromFile(fstream &file) - Failed to load parameters from file at depth: " << depth << std::endl;
284 node->setNodeID( nodeID );
285 node->setDepth( depth );
286 node->setIsLeafNode( isLeafNode );
291 node->leftChild->setParent( node );
297 node->rightChild->setParent( node );
316 return predictedNodeID;
319 UINT Node::getMaxDepth()
const {
321 UINT maxDepth = depth;
325 UINT maxLeftDepth = leftChild->getMaxDepth();
326 if( maxLeftDepth > maxDepth ){
327 maxDepth = maxLeftDepth;
333 UINT maxRightDepth = rightChild->getMaxDepth();
334 if( maxRightDepth > maxDepth ){
335 maxDepth = maxRightDepth;
347 return (parent != NULL);
351 return (leftChild != NULL);
355 return (rightChild != NULL);
358 bool Node::initNode(
Node *parent,
const UINT depth,
const UINT nodeID,
const bool isLeafNode){
359 this->parent = parent;
361 this->nodeID = nodeID;
362 this->isLeafNode = isLeafNode;
366 bool Node::setParent(
Node *parent){
367 this->parent = parent;
371 bool Node::setLeftChild(
Node *leftChild){
372 this->leftChild = leftChild;
376 bool Node::setRightChild(
Node *rightChild){
377 this->rightChild = rightChild;
381 bool Node::setDepth(
const UINT depth){
386 bool Node::setNodeID(
const UINT nodeID){
387 this->nodeID = nodeID;
391 bool Node::setIsLeafNode(
const bool isLeafNode){
392 this->isLeafNode = isLeafNode;
virtual bool print() const
std::string getNodeType() const
virtual bool getModel(std::ostream &stream) const
virtual Node * deepCopyNode() const
bool getIsLeafNode() const
virtual bool loadParametersFromFile(std::fstream &file)
virtual bool saveToFile(std::fstream &file) const
virtual bool saveParametersToFile(std::fstream &file) const
This class contains the main Node base class.
virtual bool loadFromFile(std::fstream &file)
bool getHasParent() const
virtual bool computeFeatureWeights(VectorFloat &weights) const
Node * createNewInstance() const
UINT getPredictedNodeID() const
static Node * createInstanceFromString(std::string const &nodeType)
virtual bool computeLeafNodeWeights(MatrixFloat &weights) const
std::map< std::string, Node *(*)() > StringNodeMap
virtual bool predict(const VectorFloat &x)
bool getHasRightChild() const
bool getHasLeftChild() const