Skip to content

Add FullyBayesianGP: HMC-marginalized hyperparameters + Bayesian model averaging#10

Open
blankjul wants to merge 1 commit into
docsfrom
feat/fully-bayesian-gp
Open

Add FullyBayesianGP: HMC-marginalized hyperparameters + Bayesian model averaging#10
blankjul wants to merge 1 commit into
docsfrom
feat/fully-bayesian-gp

Conversation

@blankjul

@blankjul blankjul commented Jul 8, 2026

Copy link
Copy Markdown
Collaborator

What

A new surrogate backend, FullyBayesianGP (in pysurrogate.models), that marginalizes the GP length-scales and nugget by Hamiltonian Monte Carlo instead of point-estimating them by maximum likelihood, then predicts by Bayesian model averaging:

mean = <mu_s>        var = <sigma2_s> + Var_s(mu_s)

The extra between-sample term is the hyperparameter uncertainty an MLE fit drops — which is why an MLE variance is overconfident on scarce/noisy data (one length-scale guess, no acknowledgement it was a guess).

Why it's cheap to add

No new gradient code. The HMC potential is the DACE profile likelihood the Kriging search already descends (log-lik = -(n/2)·log(obj)), so _GPPosterior just wraps DaceProblem through a log transform plus a log-space prior. Each posterior sample becomes a frozen Dace fit (optimizer=None); prediction averages their Predictions. Builds directly on the Prior foundation from #9.

New files

  • dace/hmc.py — generic HMC with dual-averaging step-size adaptation and trajectory-length jitter (breaks the fixed-leapfrog resonance that was under-sampling the widest posterior direction).
  • models/bayesian.pyFullyBayesianGP + the _GPPosterior wrapper.
  • tests/models/test_bayesian.py — 10 tests.

Verification

  • HMC recovers a known 3D Gaussian (mean + full covariance).
  • Log-posterior gradient matches finite differences to ~1e-9.
  • Deterministic given the seed.
  • DACE golden stays 19/19 byte-identical (purely additive).
  • pyclawd check green; fast tier 531 passed.

Honest scope

Regime Verdict
Noisy data (calibration) ✅ Clear, reliable win. d4/n40: mean NLPD 0.2 vs 0.9 (4× better calibrated) at comparable RMSE, and never catastrophically overconfident — MLE-Kriging is on ~half the seeds. Exactly what a BO acquisition needs.
Sparse high-D (SAAS) ❌ Not shipped. Couldn't demonstrate a win in tractable regimes (MLE-ARD is either already perfect or everything fails), so the headline is calibration + noise-robustness, not sparsity.

The calibration test asserts the aggregate NLPD win (robust) rather than per-seed (which MLE occasionally wins when it happens to be calibrated) — marked @slow.

🤖 Generated with Claude Code

…odel averaging

Point-estimating the GP hyperparameters by maximum likelihood gives a variance
conditional on one length-scale/nugget guess -- overconfident when the data is
scarce or noisy and the likelihood is flat or multi-modal. FullyBayesianGP instead
draws posterior samples of (theta, noise) by Hamiltonian Monte Carlo and predicts
by Bayesian model averaging:

    mean = <mu_s>,  var = <sigma2_s> + Var_s(mu_s)

-- the extra between-sample term is the hyperparameter uncertainty MLE drops.

The machinery is reused, not reinvented: the HMC potential is the same DACE profile
likelihood the Kriging search already descends (via DaceProblem), so no new gradient
code -- log-likelihood = -(n/2) log(obj) and its gradient follow by the chain rule
through the log. Each posterior sample becomes a frozen Dace fit; prediction averages
their Predictions.

New:
- dace/hmc.py: generic HMC with dual-averaging step-size adaptation and trajectory-
  length jitter (breaks fixed-L resonance). Recovers a known Gaussian posterior.
- models/bayesian.py: FullyBayesianGP backend + the _GPPosterior wrapper.

Verified: HMC recovers a 3D Gaussian (mean/cov); the log-posterior gradient matches
finite differences to ~1e-9; the fit is deterministic given the seed; DACE golden
stays 19/19 byte-identical (additive change). On noisy d=4/n=40 data the model-average
reports honest uncertainty where MLE-Kriging is overconfident: mean NLPD ~0.2 vs ~0.9
(4x better calibrated) at comparable RMSE, and never catastrophically overconfident
(MLE is on ~half the seeds). Not a free lunch on clean, data-rich problems -- there
MLE-ARD already nails the fit -- so it is scoped to the scarce/noisy regime where
calibration matters (Bayesian optimization).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant