pymc.logprob.conditional_logp#

pymc.logprob.conditional_logp(rv_values, warn_rvs=None, ir_rewriter=None, extra_rewrites=None, **kwargs)[source]#

Create a map between variables and conditional log-probabilities such that the sum is their joint log-probability.

The rv_values dictionary specifies a joint probability graph defined by pairs of random variables and respective measure-space input parameters

For example, consider the following

import pytensor.tensor as pt

sigma2_rv = pt.random.invgamma(0.5, 0.5)
Y_rv = pt.random.normal(0, pt.sqrt(sigma2_rv))

This graph for Y_rv is equivalent to the following hierarchical model:

\[\begin{split}\sigma^2 \sim& \operatorname{InvGamma}(0.5, 0.5) \\ Y \sim& \operatorname{N}(0, \sigma^2)\end{split}\]

If we create a value variable for Y_rv, i.e. y_vv = pt.scalar("y"), the graph of conditional_logp({Y_rv: y_vv}) is equivalent to the conditional log-probability \(\log p_{Y \mid \sigma^2}(y \mid s^2)\), with a stochastic sigma2_rv.

If we specify a value variable for sigma2_rv, i.e. s2_vv = pt.scalar("s2"), then conditional_logp({Y_rv: y_vv, sigma2_rv: s2_vv}) yields the conditional log-probabilities of the two variables. The sum of the two terms gives their joint log-probability.

\[\log p_{Y, \sigma^2}(y, s^2) = \log p_{Y \mid \sigma^2}(y \mid s^2) + \log p_{\sigma^2}(s^2)\]
Parameters:
rv_values: dict

A dict of variables that maps stochastic elements (e.g. RandomVariables) to symbolic Variables representing their values in a log-probability.

warn_rvsbool, default True

When True, issue a warning when a RandomVariable is found in the logp graph and doesn’t have a corresponding value variable specified in rv_values.

ir_rewriter

Rewriter that produces the intermediate representation of Measurable Variables.

extra_rewrites

Extra rewrites to be applied (e.g. reparameterizations, transforms, etc.)

Returns:
values_to_logps: dict

A dict that maps each value variable to the conditional log-probability term derived from the respective RandomVariable.