opytimizer.core.node¶
Node.
-
class
opytimizer.core.node.
Node
(name: Union[str, int], category: str, value: Optional[numpy.ndarray] = None, left: Optional[Node] = None, right: Optional[Node] = None, parent: Optional[Node] = None)¶ A Node instance is used for composing tree-based structures.
-
__init__
(name: Union[str, int], category: str, value: Optional[numpy.ndarray] = None, left: Optional[Node] = None, right: Optional[Node] = None, parent: Optional[Node] = None) → None¶ Initialization method.
Parameters: - name – Name of the node (e.g., it should be the terminal identifier or function name).
- category – Category of the node (e.g., TERMINAL or FUNCTION).
- value – Value of the node (only used if it is a terminal).
- left – Pointer to node’s left child.
- right – Pointer to node’s right child.
- parent – Pointer to node’s parent.
-
__repr__
() → str¶ Representation of a formal string.
-
__str__
() → str¶ Representation of an informal string.
-
name
¶ Name of the node.
-
category
¶ Category of the node.
-
value
¶ Value of the node.
Type: np.array
-
left
¶ Pointer to the node’s left child.
-
right
¶ Pointer to the node’s right child.
-
parent
¶ Pointer to the node’s parent.
-
flag
¶ Flag to identify whether the node is a left child.
-
min_depth
¶ Minimum depth of node.
-
max_depth
¶ Maximum depth of node.
-
n_leaves
¶ Number of leaves node.
-
n_nodes
¶ Number of nodes.
-
position
¶ Position after traversing the node.
-
post_order
¶ Traverses the node in post-order.
-
pre_order
¶ Traverses the node in pre-order.
-
-
opytimizer.core.node.
_build_string
(node: opytimizer.core.node.Node) → str¶ Builds a formatted string for displaying the nodes.
References
https://github.com/joowani/binarytree/blob/master/binarytree/__init__.py#L153
Parameters: node – An instance of the Node class (can be a tree of Nodes). Returns: Formatted string ready to be printed. Return type: (str)
-
opytimizer.core.node.
_evaluate
(node: opytimizer.core.node.Node) → numpy.ndarray¶ Evaluates a node and outputs its solution array.
Parameters: node – An instance of the Node class (can be a tree of Nodes). Returns: Output solution of size (n_variables x n_dimensions). Return type: (np.ndarray)
-
opytimizer.core.node.
_properties
(node: opytimizer.core.node.Node) → Dict[str, Any]¶ Traverses the node and returns some useful properties.
Parameters: node – An instance of the Node class (can be a tree of Nodes). Returns: Dictionary containing some useful properties: min_depth, max_depth, n_leaves and n_nodes. Return type: (Dict[str, Any])