30 #ifndef GRT_REGRESSION_TREE_NODE_HEADER
31 #define GRT_REGRESSION_TREE_NODE_HEADER
33 #include "../../CoreAlgorithms/Tree/Node.h"
43 nodeType =
"RegressionTreeNode";
68 if( x[ featureIndex ] >= threshold )
return true;
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();
133 std::string tab =
"";
134 for(UINT i=0; i<depth; i++) tab +=
"\t";
136 std::cout << tab <<
"depth: " << depth <<
" nodeSize: " << nodeSize <<
" featureIndex: " << featureIndex <<
" threshold " << threshold <<
" isLeafNode: " << isLeafNode << std::endl;
137 std::cout << tab <<
"RegressionData: ";
138 for(UINT i=0; i<regressionData.size(); i++){
139 std::cout << regressionData[i] <<
"\t";
141 std::cout << std::endl;
143 if( leftChild != NULL ){
144 std::cout << tab <<
"LeftChild: " << std::endl;
148 if( rightChild != NULL ){
149 std::cout << tab <<
"RightChild: " << std::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 );
190 return dynamic_cast< Node*
>( node );
207 bool set(
const UINT nodeSize,
const UINT featureIndex,
const Float threshold,
const VectorFloat ®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!" << std::endl;
232 file <<
"NodeSize: " << nodeSize << std::endl;
233 file <<
"FeatureIndex: " << featureIndex << std::endl;
234 file <<
"Threshold: " << threshold << std::endl;
235 file <<
"RegressionDataSize: " << regressionData.
getSize() << std::endl;
236 file <<
"RegressionData: ";
237 for(
unsigned int i=0; i<regressionData.
getSize(); i++){
238 file << regressionData[i] <<
" ";
255 errorLog <<
"loadFromFile(fstream &file) - File is not open!" << std::endl;
260 UINT regressionDataSize = 0;
264 if( word !=
"NodeSize:" ){
265 errorLog <<
"loadParametersFromFile(fstream &file) - Failed to find NodeSize header!" << std::endl;
271 if( word !=
"FeatureIndex:" ){
272 errorLog <<
"loadParametersFromFile(fstream &file) - Failed to find FeatureIndex header!" << std::endl;
275 file >> featureIndex;
278 if( word !=
"Threshold:" ){
279 errorLog <<
"loadParametersFromFile(fstream &file) - Failed to find Threshold header!" << std::endl;
285 if( word !=
"RegressionDataSize:" ){
286 errorLog <<
"loadParametersFromFile(fstream &file) - Failed to find RegressionDataSize header!" << std::endl;
289 file >> regressionDataSize;
290 regressionData.
resize(regressionDataSize);
293 if( word !=
"RegressionData:" ){
294 errorLog <<
"loadParametersFromFile(fstream &file) - Failed to find RegressionData header!" << std::endl;
297 for(
unsigned int i=0; i<regressionData.
getSize(); i++){
298 file >> regressionData[i];
314 #endif //GRT_REGRESSION_TREE_NODE_HEADER
virtual bool loadParametersFromFile(std::fstream &file)
virtual bool print() const
virtual bool resize(const unsigned int size)
virtual ~RegressionTreeNode()
bool set(const UINT nodeSize, const UINT featureIndex, const Float threshold, const VectorFloat ®ressionData)
unsigned int getSize() const
virtual bool predict(const VectorFloat &x)
virtual Node * deepCopyNode() const
virtual Node * deepCopyNode() const
virtual bool print() const
virtual bool saveParametersToFile(std::fstream &file) const
virtual bool predict(const VectorFloat &x)
virtual bool predict(const VectorFloat &x, VectorFloat &y)