liesel.model.nodes.obs(value, distribution=None, name='')[source]#

Helper function that returns an observed Var.

Sets the Var.observed flag. If the observed variable is a random variable, i.e. if it has an associated probability distribution, its log-probability is automatically added to the model log-likelihood (see Model.log_lik).

  • value (Union[Any, Calc]) – The value of the variable.

  • distribution (Optional[Dist]) – The probability distribution of the variable. (default: None)

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

Return type:



An observed variable.

See also


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


A node representing some static data.


A node representing a tensorflow_probability Distribution.


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


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


A variable will compute its log probability only when Calc.update() is called. This does not happen automatically upon initialization. Commonly, the first time this method is called is during the initialization of a Model. To update the value immediately, you can call Var.update() manually.


>>> import tensorflow_probability.substrates.jax.distributions as tfd

We can declare an observed variable with a normal distribution as the observation model:

>>> dist = lsl.Dist(tfd.Normal, loc=0.0, scale=1.0)
>>> y = lsl.obs(jnp.array([-0.5, 0.0, 0.5]), dist, name="y")
>>> y

Now we build the model graph:

>>> model = lsl.GraphBuilder().add(y).build_model()

The log-likelihood of the model is the sum of the log-probabilities of all observed variables. In this case this is only our y variable:

>>> model.log_lik
Array(-3.0068154, dtype=float32)
>>> jnp.sum(y.log_prob)
Array(-3.0068154, dtype=float32)