Data#

class liesel.model.nodes.Data(value, _name='')[source]#

Bases: Node

A Node subclass that holds constant data.

Since the value represented by a data node does not change, it is always up-to-date. A common usecase for data nodes is to cache computed values.

  • By default, data nodes will appear in the node graph created by viz.plot_nodes(), but they will not appear in the model graph created by viz.plot_vars().

  • You can wrap a data node in a Var to make it appear in the model graph.

Parameters:
  • value (Any) – The value of the data node.

  • _name (str) – The name of the data node. If you do not specify a name, a unique name will be automatically generated upon initialization of a Model. (default: '')

See also

Calc

A node representing a general calculation/operation in JAX or Python.

Dist

A node representing a tensorflow_probability Distribution.

Var

A variable in a statistical model, typically with a probability distribution.

param

A helper function to initialize a Var as a model parameter.

obs

A helper function to initialize a Var as an observed variable.

Examples

A simple data node representing a constant value without a name:

>>> nameless_node = lsl.Data(1.0)
>>> nameless_node
Data(name="")

Adding this node to a model leads to an automatically generated name:

>>> model = lsl.GraphBuilder().add(nameless_node).build_model()
>>> nameless_node
Data(name="n0")

A data node with a name:

>>> node = lsl.Data(1.0, _name="my_name")
>>> node
Data(name="my_name")

Methods

add_inputs(*inputs, **kwinputs)

Adds non-keyword and keyword input nodes to the existing ones.

all_input_nodes()

Returns all non-keyword and keyword input nodes as a unique tuple.

all_output_nodes()

Returns all output nodes as a unique tuple.

clear_state()

Clears the state of the node.

flag_outdated()

Stops the recursion setting outdated flags.

set_inputs(*inputs, **kwinputs)

Sets the non-keyword and keyword input nodes.

update()

Does nothing.

Attributes

groups

The groups that this node is a part of.

inputs

The non-keyword input nodes.

kwinputs

The keyword input nodes.

model

The model the node is part of.

name

The name of the node.

needs_seed

Whether the node needs a seed / PRNG key.

outdated

Whether the node is outdated.

outputs

The output nodes.

state

The state of the node.

value

The value of the node.

var

The variable the node is part of.

monitor

Whether the node should be monitored by an inference algorithm.