Nodes API¶
Nodes are the fundamental building blocks of trees in OKAPI. This section documents the different types of nodes available.
Base Node Class¶
The Node class is the base class for all node types in OKAPI.
Nodes act as the fundamental building blocks of a tree, capable of holding children and a reference to their parent node.
When created, parent reference cannot be specified. The reason for it is to create uniderectional responsibility for link creation. A node should be responsible for creating and breaking links with its children, by setting their parent links.
Attributes:
| Name | Type | Description |
|---|---|---|
parent |
Union[Node, None]
|
A reference to a parent node, of which this node is a child. |
children |
List[Node]
|
A list of references to a children nodes. |
Source code in okapi/node.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 | |
code
property
¶
Identifies node for duplicate handling.
Returns: - Code string
__init__(children=None)
¶
Create a node
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
children
|
Optional[Sequence[Node]]
|
An optional list like sequence of children of the node |
None
|
Source code in okapi/node.py
add_child(child_node)
¶
Add a child to the Node.
Parameters: - child_node: Node to be added as child
Source code in okapi/node.py
calculate()
¶
Abstract method for calculation logic.
Returns: - Calculated Tensor object
copy()
¶
Create a copy of the node. It's children and parent references are not copied.
Returns: - Copy of the node
copy_subtree()
¶
Copy the subtree rooted at this node. Does not call "add_child" method to avoid any other operations like weight adjustments. Directly sets parent and children references. Returns: - Copy of the subtree rooted at this node
Source code in okapi/node.py
get_nodes()
¶
Get all nodes in the tree created by node and its subnodes. Returns: - List of all nodes in the tree in breadth-first order
Source code in okapi/node.py
replace_child(child, replacement_node)
¶
Replaces child in place. No add child or remove child is called, so no add/remove adjustments are made.
Source code in okapi/node.py
Value Node¶
The ValueNode class represents a node that holds tensor data (model predictions).
Bases: Node
Represents a Value Node in a computational tree.
A Value Node holds a specific value or tensor.
Source code in okapi/node.py
Operator Node¶
The OperatorNode class is the base class for all operation nodes that define how to combine tensor data.
Bases: Node
Abstract Base Class for an Operator Node in a computational tree.
Reduction Operator Nodes are specialized Operator Nodes capable of performing reduction operations like mean, max, min, etc., on tensors.
Source code in okapi/node.py
Specific Operator Nodes¶
Various specific operator node implementations are provided:
Mean Node¶
Bases: OperatorNode
Represents a Mean Node in a computational tree.
A Mean Node computes the mean along a specified axis of a tensor.
Source code in okapi/node.py
Weighted Mean Node¶
Bases: OperatorNode
Represents a Weighted Mean Node in a computational tree.
A Weighted Mean Node computes the mean of a tensor, but with different weights applied to each element.
Source code in okapi/node.py
257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 | |
Min Node¶
Bases: OperatorNode
Represents a Min Node in a computational tree.
A Min Node computes the minimum value along a specified axis of a tensor.
Source code in okapi/node.py
Max Node¶
Bases: OperatorNode
Represents a Max Node in a computational tree.
A Max Node computes the maximum value along a specified axis of a tensor.