- liesel.model.nodes.obs(value, distribution=None, name='')#
Helper function that returns an observed
Var.observedflag. 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
- Return type:
An observed variable.
A node representing a general calculation/operation in JAX or Python.
A node representing some static data.
A node representing a
A variable in a statistical model, typically with a probability distribution.
A helper function to initialize a
Varas 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
>>> 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 Var(name="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
>>> model.log_lik Array(-3.0068154, dtype=float32)
>>> jnp.sum(y.log_prob) Array(-3.0068154, dtype=float32)