How to visualize the conditional posterior distribution#
In all tutorials, we used the pairplot method to visualize the posterior. This method visualizes the posterior marginals. Another option to visualize the posterior conditionals. You can do this with the conditional_pairplot function:
Main syntax for visualizing 2D-conditional distributions#
from sbi.analysis import conditional_pairplot
# The posterior must have a `default_x`.
posterior = inference.build_posterior().set_default_x(x_o)
_ = conditional_pairplot(
density=posterior,
condition=posterior.sample((1,))[0], # [0] to remove batch dimension.
limits=torch.tensor([[-2.0, 2.0], [-2.0, 2.0]]),
)
Explanation#
Consider the three-dimensional posterior
The pairplot visualizes its marginals, for example:
The conditional_pairplot visualizes its conditional, for example:
Importantly, this requires a value \(t\) which specifies the value we want to condition on. These conditional distributions can be interpreted as a cut through the posterior distribution at \(\theta_3=t\). The value \(t\) is passed to the conditional_pairplot() via the condition= argument (note that conditional_pairplot requires a condition value for all parameters. The ones that we do not condition on are simply ignored.
Example#
For a detailed example on interpreting and visualizing conditional distributions, see this tutorial. This tutorial also explains how you can draw samples from arbitrary parameter-conditional distributions such as