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 )
120 regressionData.clear();
131 virtual bool print()
const override{
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 ){
180 node->leftChild = this->leftChild->
deepCopy();
181 node->leftChild->setParent( node );
185 if( this->rightChild ){
186 node->rightChild = this->rightChild->
deepCopy();
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 <<
"load(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];
315 #endif //GRT_REGRESSION_TREE_NODE_HEADER virtual Node * deepCopy() const override
virtual bool predict_(VectorFloat &x) override
virtual bool loadParametersFromFile(std::fstream &file) override
virtual bool predict_(VectorFloat &x) override
virtual bool resize(const unsigned int size)
virtual ~RegressionTreeNode()
virtual bool print() const override
virtual bool saveParametersToFile(std::fstream &file) const override
virtual bool print() const override
virtual bool predict_(VectorFloat &x, VectorFloat &y) override
virtual bool clear() override
virtual bool clear() override
virtual Node * deepCopy() const