LogProb#
- class liesel.model.LogProb(model, component='log_prob', diff_mode='forward')[source]#
Bases:
objectInterface for evaluating the unnormalized log probability of a Liesel model.
Also provides access to the first and second derivatives.
- Parameters:
See also
FlatLogProbA similar class that returns gradients and hessians as arrays.
Examples
We initialize a very basic Liesel model:
>>> x = lsl.Var.new_param( ... jnp.zeros(2), ... dist=lsl.Dist(tfd.Normal, loc=0.0, scale=1.0), ... name="x", ... ) >>> model = lsl.Model([x])
Now we initialize the log prob object:
>>> lp = lsl.LogProb(model)
And evaluate the log prob (the unnormalized log posterior) at a new position:
>>> lp({"x": jnp.array([1.0, 2.0])}) Array(-4.3378773, dtype=float32)
Now we evaluate the gradient of the unnormalized log posterior at the new position:
>>> lp.grad({"x": jnp.array([1.0, 2.0])}) {'x': Array([-1., -2.], dtype=float32)}
And, finally, the hessian:
>>> lp.hessian({"x": jnp.array([1.0, 2.0])}) {'x': {'x': Array([[-1., -0.], [-0., -1.]], dtype=float32)}}
Methods