Getting started#
The best way to get started with PyVBMC is via the tutorials and worked examples. In particular, start with PyVBMC Example 1: Basic usage and continue from there.
If you are already familiar with approximate inference methods, you can find a summary usage below.
Summary usage#
The typical usage pipeline of PyVBMC follows four steps:
Define the model, which defines a target log density (i.e., an unnormalized log posterior density);
Setup the parameters (parameter bounds, starting point);
Initialize and run the inference;
Examine and visualize the results.
PyVBMC is not concerned with how you define your model in step 1, as long as you can provide an (unnormalized) target log density. Running the inference in step 3 only involves a couple of lines of code:
from pyvbmc import VBMC
# ...
vbmc = VBMC(target, x0, LB, UB, PLB, PUB)
vp, results = vbmc.optimize()
with input arguments:
target
: the target (unnormalized) log density — often an unnormalized log posterior.target
takes as input a parameter vector and returns the log density at the point. The returned log density must return a finite real value, i.e. non NaN or -inf. See the VBMC FAQ for more details;x0
: the starting point of the inference in parameter space;LB
andUB
: hard lower and upper bounds for the parameters (can be-inf
andinf
, or bounded);PLB
andPUB
: plausible lower and upper bounds, that is a box that ideally brackets a region of high density of the target.
The outputs are:
vp
: aVariationalPosterior
object which approximates the true target density;results
: adict
with additional information. Important keys are: -"elbo"
: the estimated lower bound on the log model evidence (log normalization constant); -"elbo_sd"
: the standard deviation of the estimate of the ELBO (not the error between the ELBO and the true log model evidence, which is generally unknown).
The vp
object can be manipulated in various ways, see the VariationalPosterior class documentation.
See the examples for more detailed information. The Basic options may also be useful.