30 #ifndef GRT_REGRESSION_TREE_NODE_HEADER
31 #define GRT_REGRESSION_TREE_NODE_HEADER
33 #include "../../CoreAlgorithms/Tree/Node.h"
43 nodeType =
"RegressionTreeNode";
67 virtual bool predict(
const VectorDouble &x){
68 if( x[ featureIndex ] >= threshold )
return true;
85 virtual bool predict(
const VectorDouble &x,VectorDouble &y){
88 y = this->regressionData;
92 if( leftChild == NULL && rightChild == NULL )
97 return rightChild->
predict( x, y );
100 return leftChild->
predict( x, y );
120 regressionData.clear();
134 for(UINT i=0; i<depth; i++) tab +=
"\t";
136 cout << tab <<
"depth: " << depth <<
" nodeSize: " << nodeSize <<
" featureIndex: " << featureIndex <<
" threshold " << threshold <<
" isLeafNode: " << isLeafNode << endl;
137 cout << tab <<
"RegressionData: ";
138 for(UINT i=0; i<regressionData.size(); i++){
139 cout << regressionData[i] <<
"\t";
143 if( leftChild != NULL ){
144 cout << tab <<
"LeftChild: " << endl;
148 if( rightChild != NULL ){
149 cout << tab <<
"RightChild: " << endl;
171 node->depth = this->depth;
172 node->isLeafNode = this->isLeafNode;
173 node->nodeSize = this->nodeSize;
174 node->featureIndex = this->featureIndex;
175 node->threshold = this->threshold;
176 node->regressionData = this->regressionData;
179 if( this->leftChild ){
181 node->leftChild->setParent( node );
185 if( this->rightChild ){
187 node->rightChild->setParent( node );
207 bool set(
const UINT nodeSize,
const UINT featureIndex,
const double threshold,
const VectorDouble ®ressionData){
208 this->nodeSize = nodeSize;
209 this->featureIndex = featureIndex;
210 this->threshold = threshold;
211 this->regressionData = regressionData;
227 errorLog <<
"saveParametersToFile(fstream &file) - File is not open!" << endl;
232 file <<
"NodeSize: " << nodeSize << endl;
233 file <<
"FeatureIndex: " << featureIndex << endl;
234 file <<
"Threshold: " << threshold << endl;
235 file <<
"RegressionDataSize: " << regressionData.size() << endl;
236 file <<
"RegressionData: ";
237 for(
unsigned int i=0; i<regressionData.size(); i++){
238 file << regressionData[i] <<
" ";
255 errorLog <<
"loadFromFile(fstream &file) - File is not open!" << endl;
260 UINT regressionDataSize = 0;
264 if( word !=
"NodeSize:" ){
265 errorLog <<
"loadParametersFromFile(fstream &file) - Failed to find NodeSize header!" << endl;
271 if( word !=
"FeatureIndex:" ){
272 errorLog <<
"loadParametersFromFile(fstream &file) - Failed to find FeatureIndex header!" << endl;
275 file >> featureIndex;
278 if( word !=
"Threshold:" ){
279 errorLog <<
"loadParametersFromFile(fstream &file) - Failed to find Threshold header!" << endl;
285 if( word !=
"RegressionDataSize:" ){
286 errorLog <<
"loadParametersFromFile(fstream &file) - Failed to find RegressionDataSize header!" << endl;
289 file >> regressionDataSize;
290 regressionData.resize(regressionDataSize);
293 if( word !=
"RegressionData:" ){
294 errorLog <<
"loadParametersFromFile(fstream &file) - Failed to find RegressionData header!" << endl;
297 for(
unsigned int i=0; i<regressionData.size(); i++){
298 file >> regressionData[i];
307 VectorDouble regressionData;
314 #endif //GRT_REGRESSION_TREE_NODE_HEADER
virtual Node * deepCopyNode() const
virtual bool loadParametersFromFile(fstream &file)
bool set(const UINT nodeSize, const UINT featureIndex, const double threshold, const VectorDouble ®ressionData)
virtual bool print() const
virtual bool saveParametersToFile(fstream &file) const
virtual bool predict(const VectorDouble &x)
virtual Node * deepCopyNode() const
virtual ~RegressionTreeNode()
virtual bool predict(const VectorDouble &x)
virtual bool predict(const VectorDouble &x, VectorDouble &y)
virtual bool print() const