Acquisition Functions#
- class pyvbmc.acquisition_functions.AbstractAcqFcn[source]#
Bases:
ABCAbstract acquisition function for VBMC.
Notes
A subclass that sets
acq_info["compute_var_log_joint"] = Trueis given the posterior uncertainty of the expected log joint before each search:active_samplethen writes its variance per GP hyperparameter sample tooptim_state["var_log_joint_samples"], shape(Ns,)and a scalar whenNs == 1, and the covariance of the mixture components’ integrals tooptim_state["cov_log_joint_components"], shape(Ns, K, K). The built-in acquisitions leave the flag disabled and neither entry exists for them.- __call__(Xs: ndarray, gp: GP, vp: VariationalPosterior, function_logger: FunctionLogger, optim_state: dict)[source]#
Calculate the acquisition function for the given inputs.
- Parameters:
- Xsnp.ndarray
Input points.
- gpgpr.GP
The GaussianProcess of the VBMC instance this function is called from.
- vpVariationalPosterior
The VariationalPosterior of the VBMC instance this function is called from.
- function_loggerFunctionLogger
The FunctionLogger of the VBMC instance this function is called from.
- optim_statedict
The optim_state of the VBMC instance this function is called from.
- Returns:
- acqnp.ndarray
The output of the acquisition function, shape
(N,)whereNis the number of input points.
- class pyvbmc.acquisition_functions.AcqFcn[source]#
Bases:
AbstractAcqFcnAcquisition function for prospective uncertainty search.
- class pyvbmc.acquisition_functions.AcqFcnIMIQR(quantile=0.75)[source]#
Bases:
AbstractAcqFcnIntegrated Median Interquantile Range (IMIQR) acquisition function.
Approximates the Integrated Median Interquantile Range (IMIQR) via importance samples from the GP surrogate.
- Parameters:
- quantilefloat, optional
The upper quantile \(p_u\) of the interquantile range, a number strictly between 0.5 and 1; the default 0.75 gives \(u = \Phi^{-1}(0.75)\).
- is_log_added(**kwargs)[source]#
Importance sampling proposal log density, added part.
The added term in the importance sampling proposal log density: The full proposal log density is
is_log_full = is_log_base + is_log_added. Added part for VIQR/IMIQR is \(\log [2 \sinh(u f_s)]\), where \(f_s\) is the GP predictive standard deviation at the input points.- Parameters:
- f_s2np.ndarray
The predicted posterior variance at the points of interest.
- Returns:
- ynp.ndarray
The added log density term at the points of interest.
- is_log_base(x, **kwargs)[source]#
Importance sampling proposal log density, base part.
The base density of the importance sampling proposal distribution, used for computing i.s. weights (in addition to the full proposal density). The full proposal log density is
is_log_full = is_log_base + is_log_added. IMIQR approximates an expectation w.r.t. to the (exponentiated) GP using importance sampling, so this base log density is the GP mean,f_mu.- Parameters:
- f_munp.ndarray
The gp posterior mean at the points of interest.
- Returns:
- f_munp.ndarray
The log density of the target against which the i.s. expectation is taken. Here, just the log density as modeled by the GP.
- is_log_full(x, **kwargs)[source]#
Importance sampling full proposal log density.
The full proposal log density, used for MCMC sampling:
is_log_full = is_log_base + is_log_added.- Parameters:
- f_munp.ndarray
The gp posterior mean at the points of interest. Either [
f_s2andf_mu] orgpmust be provided.- f_s2np.ndarray, optional
The predicted posterior variance at the points of interest. Either [
f_s2andf_mu] orgpmust be provided.- gpgpyreg.GaussianProcess, optional
The GP modeling the log-density. Either [
f_s2andf_mu] orgpmust be provided.
- Returns:
- ynp.ndarray
The full log density of the importance sampling proposal distribution at the points of interest. Of the same shape as
f_s2.
- Raises:
- ValueError
If [
f_s2orf_mu] are not provided, andgpis not provided.
- class pyvbmc.acquisition_functions.AcqFcnLog[source]#
Bases:
AbstractAcqFcnAcquisition function for prospective uncertainty search (log-valued).
- class pyvbmc.acquisition_functions.AcqFcnNoisy[source]#
Bases:
AbstractAcqFcnAcquisition function for noisy prospective uncertainty search.
- class pyvbmc.acquisition_functions.AcqFcnVIQR(quantile=0.75, loss='iqr')[source]#
Bases:
AbstractAcqFcnVariational Interquantile Range (VIQR) acquisition function.
Approximates the Integrated Median Interquantile Range (IMIQR) by simple Monte Carlo using samples from the Variational Posterior.
- Parameters:
- quantilefloat, optional
The upper quantile \(p_u\) of the interquantile range, a number strictly between 0.5 and 1; the default 0.75 gives \(u = \Phi^{-1}(0.75)\).
- loss{“iqr”, “iqr_reduction”}, optional
The loss whose expectation under the variational posterior the acquisition minimizes. Both losses share the same look-ahead predictive standard deviation \(s_{\Xi \cup \theta_*}(\theta_a)\) at the importance points \(\theta_a\): the GP posterior after a hypothetical observation at the candidate \(\theta_*\), which does not depend on the value observed there.
"iqr"(default): the log integrated interquantile range after the observation, \(\log \sum_a 2 \sinh(u\, s_{\Xi \cup \theta_*}(\theta_a))\), the VIQR of [1]."iqr_reduction": minus the log of the integrated reduction of the interquantile range, \(-\log \sum_a w_a [\sinh(u\, s_\Xi(\theta_a)) - \sinh(u\, s_{\Xi \cup \theta_*}(\theta_a))]\). It has the same minimizer as"iqr"over any fixed candidate set. The log of the reduction spans orders of magnitude where the log of the residual range is nearly flat, which matters to the tolerance-based termination of the search optimizer.
\(w_a\) are the importance weights, normalized over the hyperparameter samples and the importance points together (so the reduction acquisition carries a constant, \(\log (N_s N_a)\) for \(N_s\) hyperparameter samples and \(N_a\) importance points, that does not move the minimizer) and uniform under the simple Monte Carlo of VIQR. The reduction is non-negative, so
"iqr_reduction"is+infwhere the candidate reduces the interquantile range at no importance point.
References
[1]Acerbi, L. (2020). “Variational Bayesian Monte Carlo with Noisy Likelihoods.” Advances in Neural Information Processing Systems 33.
- LOSSES = ('iqr', 'iqr_reduction')#
- is_log_added(**kwargs)[source]#
Importance sampling proposal log density, added part.
The added term in the importance sampling proposal log density: The full proposal log density is
is_log_full = is_log_base + is_log_added. Added part for VIQR/IMIQR is \(\log [2 \sinh(u f_s)]\), where \(f_s\) is the GP predictive standard deviation at the input points.- Parameters:
- f_s2np.ndarray
The predicted posterior variance at the points of interest.
- Returns:
- ynp.ndarray
The added log density term at the points of interest. Of the same shape as
f_s2.
- is_log_base(x, **kwargs)[source]#
Importance sampling proposal log density, base part.
The base density of the importance sampling proposal distribution, used for computing i.s. weights (in addition to the full proposal density). The full proposal log density is
is_log_full = is_log_base + is_log_added. VIQR approximates an expectation w.r.t. to the VP using simple Monte Carlo, so this base density is constant (log=0).- Parameters:
- xnp.ndarray
The input points, shape
(N, D)whereNis the number of points andDis the dimension.- f_s2np.ndarray
The predicted posterior variance at the points of interest.
- Returns:
- znp.ndarray
The log base part of the importance sampling weights (zeros), shape
f_s2.
- is_log_full(x, **kwargs)[source]#
Importance sampling full proposal log density.
The full proposal log density, used for MCMC sampling:
is_log_full = is_log_base + is_log_added.- Parameters:
- f_s2np.ndarray, optional
The predicted posterior variance at the points of interest. Either
f_s2orgpmust be provided.- gpgpyreg.GaussianProcess, optional
The GP modeling the log-density. Either
f_s2orgpmust be provided.
- Returns:
- ynp.ndarray
The full log density of the importance sampling proposal distribution at the points of interest. Of the same shape as
f_s2.
- Raises:
- ValueError
If neither
f_s2norgpare provided.
- class pyvbmc.acquisition_functions.AcqFcnVanilla[source]#
Bases:
AbstractAcqFcnAcquisition function via vanilla uncertainty sampling.