Node#
- class liesel.model.Node(*inputs, _name='', _needs_seed=False, convert='default', **kwinputs)[source]#
Bases:
ABCA node of a computational graph that can cache its value.
Liesel represents statistical models as directed acyclic graphs (DAGs) of random variables (see
Var) and computational nodes. The graph of random variables is built on top of the computational graph. The nodes of the computational graph will typically express computations in JAX returning arrays or pytrees, but in general, they can represent arbitrary operations in Python.Nodes can cache the result of the operations they represent, improving the efficiency of the graph. The cached values are part of the model state (see
Model.state), and can be stored in a chain by Liesel’s MCMC engine Goose.Note
This class is an abstract class that cannot be initialized without defining the
update()method. See below for the most important concrete node classes.- Parameters:
inputs (
Any) – Non-keyword inputs. Any inputs that are not already nodes orVarwill be converted toValuenodes._name (
str, default:'') – The name of the node. If you do not specify a name, a unique name will be automatically generated upon initialization of aModel._needs_seed (
bool, default:False) – Whether the node needs a seed / PRNG key.convert (
Callable[[Any],Any] |Literal['default'], default:'default') – A function used to process the value of this node. The default uses the function stored inconvert_value, which isjax.numpy.asarray.
See also
CalcA node representing a general calculation/operation in JAX or Python.
ValueA node representing some static data.
DistA node representing a
tensorflow_probabilityDistribution.VarA variable in a statistical model, typically with a probability distribution.
Methods
add_inputs(*inputs, **kwinputs)Adds non-keyword and keyword input nodes to the existing ones.
Returns all non-keyword and keyword input nodes as a unique tuple.
Returns all output nodes as a unique tuple.
Clears the state of the node.
The function used to process the value of this node, if
convert="default"is supplied during init.Ensures that the node has a name.
Flags the node and its recursive outputs as outdated.
set_inputs(*inputs, **kwinputs)Sets the non-keyword and keyword input nodes.
update()Updates the value of the node.
Attributes
The groups that this node is a part of.
The non-keyword input nodes.
The keyword input nodes.
The model the node is part of.
The name of the node.
Whether the node needs a seed / PRNG key.
Whether the node is outdated.
The output nodes.
The state of the node.
The value of the node.
The variable the node is part of.
Whether the node should be monitored by an inference algorithm.