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 VectorDouble &x) - Base class not overwritten!" << endl;
65 warningLog <<
"predict(const VectorDouble &x) - Base class not overwritten!" << endl;
74 if( leftChild != NULL ){
83 if( rightChild != NULL ){
102 ostringstream stream;
104 cout << stream.str();
114 for(UINT i=0; i<depth; i++) tab +=
"\t";
116 stream << tab <<
"depth: " << depth <<
" isLeafNode: " << isLeafNode <<
" nodeID: " << nodeID << endl;
118 if( leftChild != NULL ){
119 stream << tab <<
"LeftChild: " << endl;
123 if( rightChild != NULL ){
124 stream << tab <<
"RightChild: " << endl;
135 errorLog <<
"saveToFile(fstream &file) - File is not open!" << endl;
139 file <<
"NodeType: " << nodeType << endl;
140 file <<
"Depth: " << depth << endl;
141 file <<
"NodeID: " << nodeID << endl;
142 file <<
"IsLeafNode: " << isLeafNode << endl;
148 file <<
"LeftChild\n";
150 errorLog <<
"saveToFile(fstream &file) - Failed to save left child at depth: " << depth << endl;
157 file <<
"RightChild\n";
159 errorLog <<
"saveToFile(fstream &file) - Failed to save right child at depth: " << depth << endl;
166 errorLog <<
"saveToFile(fstream &file) - Failed to save parameters to file at depth: " << depth << endl;
180 errorLog <<
"loadFromFile(fstream &file) - File is not open!" << endl;
185 bool hasLeftChild =
false;
186 bool hasRightChild =
false;
189 if( word !=
"NodeType:" ){
190 errorLog <<
"loadFromFile(fstream &file) - Failed to find Node header!" << endl;
196 if( word !=
"Depth:" ){
197 errorLog <<
"loadFromFile(fstream &file) - Failed to find Depth header!" << endl;
203 if( word !=
"NodeID:" ){
204 errorLog <<
"loadFromFile(fstream &file) - Failed to find NodeID header!" << endl;
210 if( word !=
"IsLeafNode:" ){
211 errorLog <<
"loadFromFile(fstream &file) - Failed to find IsLeafNode header!" << endl;
217 if( word !=
"HasLeftChild:" ){
218 errorLog <<
"loadFromFile(fstream &file) - Failed to find HasLeftChild header!" << endl;
221 file >> hasLeftChild;
224 if( word !=
"HasRightChild:" ){
225 errorLog <<
"loadFromFile(fstream &file) - Failed to find HasRightChild header!" << endl;
228 file >> hasRightChild;
232 if( word !=
"LeftChild" ){
233 errorLog <<
"loadFromFile(fstream &file) - Failed to find LeftChild header!" << endl;
237 leftChild->setParent(
this );
239 errorLog <<
"loadFromFile(fstream &file) - Failed to load left child at depth: " << depth << endl;
246 if( word !=
"RightChild" ){
247 errorLog <<
"loadFromFile(fstream &file) - Failed to find RightChild header!" << endl;
251 rightChild->setParent(
this );
253 errorLog <<
"loadFromFile(fstream &file) - Failed to load right child at depth: " << depth << endl;
260 errorLog <<
"loadParametersFromFile(fstream &file) - Failed to load parameters from file at depth: " << depth << endl;
276 node->setNodeID( nodeID );
277 node->setDepth( depth );
278 node->setIsLeafNode( isLeafNode );
283 node->leftChild->setParent( node );
289 node->rightChild->setParent( node );
308 return predictedNodeID;
311 UINT Node::getMaxDepth()
const {
313 UINT maxDepth = depth;
317 UINT maxLeftDepth = leftChild->getMaxDepth();
318 if( maxLeftDepth > maxDepth ){
319 maxDepth = maxLeftDepth;
325 UINT maxRightDepth = rightChild->getMaxDepth();
326 if( maxRightDepth > maxDepth ){
327 maxDepth = maxRightDepth;
339 return (parent != NULL);
343 return (leftChild != NULL);
347 return (rightChild != NULL);
350 bool Node::initNode(
Node *parent,
const UINT depth,
const UINT nodeID,
const bool isLeafNode){
351 this->parent = parent;
353 this->nodeID = nodeID;
354 this->isLeafNode = isLeafNode;
358 bool Node::setParent(Node *parent){
359 this->parent = parent;
363 bool Node::setLeftChild(Node *leftChild){
364 this->leftChild = leftChild;
368 bool Node::setRightChild(Node *rightChild){
369 this->rightChild = rightChild;
373 bool Node::setDepth(
const UINT depth){
378 bool Node::setNodeID(
const UINT nodeID){
379 this->nodeID = nodeID;
383 bool Node::setIsLeafNode(
const bool isLeafNode){
384 this->isLeafNode = isLeafNode;
virtual Node * deepCopyNode() const
UINT getPredictedNodeID() const
bool getHasLeftChild() const
virtual bool loadFromFile(fstream &file)
virtual bool saveToFile(fstream &file) const
virtual bool getModel(ostream &stream) const
string getNodeType() const
virtual bool loadParametersFromFile(fstream &file)
virtual bool saveParametersToFile(fstream &file) const
std::map< string, Node *(*)() > StringNodeMap
This class contains the main Node base class.
virtual bool predict(const VectorDouble &x)
Node * createNewInstance() const
bool getHasParent() const
bool getIsLeafNode() const
static Node * createInstanceFromString(string const &nodeType)
bool getHasRightChild() const
virtual bool print() const