VBMC algorithm helpers

VBMC algorithm helpers#

These lower-level functions implement parts of the VBMC algorithm. Most users should use pyvbmc.VBMC.optimize() instead.

pyvbmc.vbmc.optimize_vp(options: Options, optim_state: dict, vp: VariationalPosterior, gp: GP, fast_opts_N: int, slow_opts_N: int, K: int = None)[source]#

Optimize variational posterior.

Parameters:
optionsOptions

Options from the VBMC instance we are calling this from.

optim_statedict

Optimization state from the VBMC instance we are calling this from.

vpVariationalPosterior

The variational posterior we want to optimize.

gpgpyreg.GaussianProcess

The Gaussian process surrogate of the log-posterior, against which to optimize the VP.

fast_opts_Nint

Number of fast optimizations. Zero starts the optimization from the given VP alone, and then requires slow_opts_N = 1, as in MATLAB.

slow_opts_Nint

Number of slow optimizations.

Kint, optional

Number of mixture components. If not given defaults to the number of mixture components the given VP has.

Returns:
vpVariationalPosterior

The optimized variational posterior.

var_ssfloat

Spread of the expected log joint across the GP hyperparameter samples: the sample variance of its value from sample to sample plus the sample standard deviation of its per-sample variances. Zero with a single hyperparameter sample, and when the variance of the expected log joint is not computed.

prunedint

Number of pruned components.

Raises:
ValueError

If the full ELCBO evaluation of every optimized solution returns NaN, so that no variational parameters can be selected, or if the entropy is estimated by Monte Carlo, which the stochastic optimization follows, and the option stochastic_optimizer is not "adam".

Notes

Random draws (starting points, Monte Carlo entropy, choice of the component to prune) use vp.rng.

pyvbmc.vbmc.train_gp(hyp_dict: dict, optim_state: dict, function_logger: FunctionLogger, iteration_history: IterationHistory, options: Options, plb_tran: ndarray, pub_tran: ndarray, rng=None)[source]#

Train Gaussian process model.

Parameters:
hyp_dictdict

Hyperparameter summary statistics dictionary. If it does not contain the appropriate keys they will be added automatically. A statistic whose shape does not match the number of hyperparameters of the GP model is dropped and started afresh.

optim_statedict

Optimization state from the VBMC instance we are calling this from.

function_loggerFunctionLogger

Function logger from the VBMC instance which we are calling this from.

iteration_historyIterationHistory

Iteration history from the VBMC instance we are calling this from.

optionsOptions

Options from the VBMC instance we are calling this from.

plb_tranndarray, shape (1, D)

Transformed lower plausible bounds, used to set GP hyperparameters.

pub_tranndarray, shape (1, D)

Transformed upper plausible bounds, used to set GP hyperparameters.

rngNone, int, SeedSequence or np.random.Generator, optional

Random generator (or seed) used to subsample the starting hyperparameters and handed to the fit itself (gpyreg.GP.fit: the space-filling initial design and the slice sampler). By default a generator derived from NumPy’s global random state.

Returns:
gpGP

The trained GP.

gp_s_Nint

The number of samples for fitting.

sn2_hpdfloat

An estimate of the GP noise variance at high posterior density.

hyp_dictdict

The updated summary statistics.

pyvbmc.vbmc.update_K(optim_state: dict, iteration_history: IterationHistory, options: Options)[source]#

Update number of variational mixture components.

Parameters:
optim_statedict

Optimization state from the VBMC instance we are calling this from.

iteration_historyIterationHistory

Iteration history from the VBMC instance we are calling this from.

optionsOptions

Options from the VBMC instance we are calling this from.

Returns:
K_newint

The new number of variational mixture components.