30 #ifndef GRT_NODE_HEADER 31 #define GRT_NODE_HEADER 33 #include "../../CoreModules/MLBase.h" 42 Node(
const std::string
id =
"Node" );
75 virtual bool computeFeatureWeights(
VectorFloat &weights )
const;
84 virtual bool computeLeafNodeWeights(
MatrixFloat &weights )
const;
92 virtual bool clear()
override;
100 virtual bool print()
const override;
109 virtual bool getModel( std::ostream &stream )
const override;
117 virtual bool save( std::fstream &file )
const override;
125 virtual bool load( std::fstream &file )
override;
133 virtual Node* deepCopy()
const;
140 std::string getNodeType()
const;
148 UINT getDepth()
const;
155 UINT getNodeID()
const;
162 UINT getPredictedNodeID()
const;
164 UINT getMaxDepth()
const;
171 bool getIsLeafNode()
const;
178 bool getHasParent()
const;
185 bool getHasLeftChild()
const;
192 bool getHasRightChild()
const;
194 Node *getParent()
const {
return parent; }
195 Node *getLeftChild()
const {
return leftChild; }
196 Node *getRightChild()
const {
return rightChild; }
198 bool initNode(
Node *parent,
const UINT depth,
const UINT nodeID,
const bool isLeafNode =
false);
200 bool setParent(
Node *parent);
202 bool setLeftChild(
Node *leftChild);
204 bool setRightChild(
Node *rightChild);
206 bool setDepth(
const UINT depth);
208 bool setNodeID(
const UINT nodeID);
210 bool setIsLeafNode(
const bool isLeafNode);
223 static Node* createInstanceFromString( std::string
const &nodeType );
230 Node* createNewInstance()
const;
257 std::string nodeType;
260 UINT predictedNodeID;
266 static StringNodeMap *getMap() {
267 if( !stringNodeMap ){ stringNodeMap =
new StringNodeMap; }
268 return stringNodeMap;
272 static StringNodeMap *stringNodeMap;
273 static UINT numNodeInstances;
277 template<
typename T >
Node* getNewNodeInstance() {
return new T; }
279 template<
typename T >
283 getMap()->insert( std::pair< std::string,
Node*(*)() >(newNodeName, &getNewNodeInstance< T > ) );
289 #endif //GRT_NODE_HEADER virtual bool predict(VectorFloat inputVector)
virtual bool predict_(VectorFloat &inputVector)
virtual bool getModel(std::ostream &stream) const
virtual bool save(const std::string &filename) const
virtual bool loadParametersFromFile(std::fstream &file)
virtual bool print() const
virtual bool saveParametersToFile(std::fstream &file) const
virtual bool load(const std::string &filename)
This is the main base class that all GRT machine learning algorithms should inherit from...
std::map< std::string, Node *(*)() > StringNodeMap