opto.trace.nodes.Node#
- class Node[source]#
A data node in a directed graph, this is a basic data structure of Trace.
- Parameters:
value (Any) β The value to be assigned to the node.
name (str, optional) β The name of the node.
trainable (bool, optional) β Whether the node is trainable or not. Defaults to False.
description (str, optional) β String describing the node. Defaults to β[Node] This is a node in a computational graph.β
constraint (Union[None, str], optional) β String describing constraints that the data should satisfy. Defaults to None.
info (Union[None, Dict], optional) β Dictionary containing additional information about the node. Defaults to None.
- trainable#
Whether the node is trainable or not.
- Type:
bool
- _feedback#
Dictionary of feedback from children nodes.
- Type:
dict
- _description#
String describing the node.
- Type:
str
- _constraint#
String describing all constraints that the data should satisfy.
- Type:
str
- _backwarded#
Whether the backward method has been called.
- Type:
bool
- _info#
Dictionary containing additional information about the node.
- Type:
dict
- _dependencies#
Dictionary of dependencies on parameters and expandable nodes.
- Type:
dict
Notes
The Node class extends AbstractNode to represent a data node in a directed graph. It includes attributes and methods to handle feedback, constraints, and dependencies. The node can be marked as trainable and store feedback from children nodes. The feedback mechanism is analogous to gradients in machine learning and propagates information back through the graph. The feedback mechanism supports non-commutative aggregation, so feedback should be handled carefully to maintain correct operation order. The node can track dependencies on parameters and expandable nodes (nodes that depend on parameters not visible in the current graph level).
Initialize an instance of the Node class.
- Parameters:
value β The value to be assigned to the node.
name β The name of the node (optional).
trainable β A boolean indicating whether the node is trainable or not (optional).
description β A string describing the node (optional).
constraint β A string describing constraints on the node (optional).
info β A dictionary containing additional information about the node (optional).
Attributes
Get the children of a node.
Retrieve the internal data of a node.
A textual description of the node.
The depended expandable nodes.
The feedback from children nodes.
Get the identifier part of the node's name.
Additional information about the node.
Check if the node is a leaf node.
Check if the node is a root node.
Get the level of the node in the graph.
Get the name of the node.
The depended parameters.
Get the parents of a node.
Get the Python-friendly name of the node.
The type of the data stored in the node.
Methods
append
(*args, **kwargs)backward
([feedback, propagator, ...])Performs a backward pass in a computational graph.
call
(fun, *args, **kwargs)Call the function with the specified arguments and keyword arguments.
clone
()Create and return a duplicate of the current Node object.
detach
()Create and return a deep copy of the current instance of the Node class.
eq
(other)Check if the node is equal to another value.
format
(*args, **kwargs)getattr
(key)Get the attribute of the node with the specified key.
gt
(other)Compare if this node's level is greater than another node's level.
items
()join
(seq)keys
()len
()Return the length of the node.
lower
()lt
(other)Compare if this node's level is less than another node's level.
neq
(other)Check if the node is not equal to another value.
pop
([_Node__index])replace
(old, new[, count])split
([sep, maxsplit])strip
([chars])swapcase
()title
()upper
()values
()Zero out the feedback of the node.
- __init__(value: Any, *, name: str | None = None, trainable: bool = False, description: str = '[Node] This is a node in a computational graph.', constraint: None | str = None, info: None | Dict = None) None [source]#
Initialize an instance of the Node class.
- Parameters:
value β The value to be assigned to the node.
name β The name of the node (optional).
trainable β A boolean indicating whether the node is trainable or not (optional).
description β A string describing the node (optional).
constraint β A string describing constraints on the node (optional).
info β A dictionary containing additional information about the node (optional).
- __new__(**kwargs)#