Value

Contents

Value#

class liesel.model.Value(value, _name='', convert='default')[source]#

Bases: Node

A Node subclass that holds constant values.

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

  • By default, value 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 value node in a Var to make it appear in the model graph.

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

  • _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 a Model.

  • convert (Callable[[Any], Any] | Literal['default'], default: 'default') – A function used to process the value of this node. The default uses the function stored in convert_value, which is jax.numpy.asarray.

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 constant node representing a constant value without a name:

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

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

>>> model = lsl.Model([nameless_node])
>>> nameless_node.name.startswith("_")
True

A constant node with a name:

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

Methods

flag_outdated()

Stops the recursion setting outdated flags.

update()

Does nothing.

Attributes

outdated

Whether the node is outdated.

value

The value of the node.

monitor

Whether the node should be monitored by an inference algorithm.