bayesianbandits.RVGAApproximator#

class bayesianbandits.RVGAApproximator(n_iter: int = 5, tol: float = 0.0001, n_gh_nodes: int = 20, use_probit: bool = True, batch_size: int | None = 2048)#

Bases: PosteriorApproximator

R-VGA posterior approximation via expected curvature.

Replaces Laplace’s point-estimate curvature with expected curvature under the approximate posterior, correcting systematic bias for non-Gaussian likelihoods.

Parameters:
  • n_iter (int, default 5) – Maximum iterations per update.

  • tol (float, default 1e-4) – Convergence tolerance on coefficient change.

  • n_gh_nodes (int, default 20) – Number of Gauss-Hermite quadrature nodes. Only used for link=’logit’ with use_probit=False; the log link uses the exact closed form \(E[\exp(\eta)] = \exp(m + v/2)\).

  • use_probit (bool, default True) – If True and link=’logit’, use the analytical probit approximation instead of GH quadrature. Ignored for log link.

  • batch_size (int or None, default 2048) – Sparse models only. Batches larger than this are processed as sequential minibatch updates (R-VGA’s native recursive mode), bounding the predictive-variance Gram allocation at 8 * batch_size**2 bytes (~34 MB at the default) instead of growing quadratically with the batch. Sequential updates make the posterior mildly dependent on row order; set to None to force a single joint update regardless of batch size. Ignored for dense models, whose memory does not depend on batch size.

References

Lambert, Bonnabel, Bach (2022). Statistics and Computing, 32, 10.

See also

LaplaceApproximator

Default approximation using IRLS.

BayesianGLM

Estimator that uses this protocol.

Examples

>>> from bayesianbandits import RVGAApproximator, BayesianGLM
>>> model = BayesianGLM(approximator=RVGAApproximator())
__init__(n_iter: int = 5, tol: float = 0.0001, n_gh_nodes: int = 20, use_probit: bool = True, batch_size: int | None = 2048) None#
batch_size: int | None = 2048#
n_gh_nodes: int = 20#
n_iter: int = 5#
tol: float = 0.0001#
update_posterior(X: ndarray[tuple[int, ...], dtype[float64]] | csc_array, y: ndarray[tuple[int, ...], dtype[float64]], prior_mean: ndarray[tuple[int, ...], dtype[float64]] | csc_array, prior_precision: ndarray[tuple[int, ...], dtype[float64]] | csc_array, link: Literal['logit', 'log'], sample_weight: ndarray[tuple[int, ...], dtype[float64]] | None, learning_rate: float, sparse: bool, prior_factor: Any | None = None) GaussianPosterior#
use_probit: bool = True#