Skip to content

GP: Acquisition Functions and Multipoint Sampling - #134

Open
asher-m wants to merge 4 commits into
masterfrom
dev/gp-jax
Open

asher-m wants to merge 4 commits into
masterfrom
dev/gp-jax

Conversation

@asher-m

@asher-m asher-m commented Dec 1, 2026

Copy link
Copy Markdown
Collaborator

GaussianProcess.get_sample_point could only maximize posterior variance, returned one point per call, and always ran a fixed number of optimizer steps. This PR makes the acquisition function pluggable, adds batch selection of q points per call, and stops optimization once it converges.

Default behavior is unchanged apart from stopping earlier: maximum posterior variance, one point per call, same return shape (1, d). Existing calls keep working.

Changes

Acquisition functions (gp.acquisition, new)

  • AcquisitionFunction base class, plus MaximumVariance, UpperConfidenceBound, ExpectedImprovement, and ProbabilityOfImprovement.
  • EI and PI are computed in log space (Ament et al. 2023), so values and gradients stay finite far from the best observed value.
  • UCB, EI, and PI accept maximize= and, for vector-valued GPs, scalarization weights=.

Posterior snapshot (gp.posterior, new)

  • Posterior is a read-only, JAX-traceable snapshot of a conditioned GP. Acquisition functions evaluate against it, and you can get one with GaussianProcess.posterior().
  • posterior_mean and posterior_covariance now delegate to it.

get_sample_point

  • acquisition= selects the acquisition function. The default is MaximumVariance().
  • x may be a single starting point (d,), or candidates (m, d). The best in-domain candidate is used as the starting point, and out-of-domain candidates are skipped.
  • q= selects several points greedily using the Kriging Believer heuristic. After each pick, the posterior is conditioned on a "fantasy" observation at the posterior mean, with noise fantasy_noise (default: the mean training noise, floored at nugget). Fantasy observations are local to the call; the GP is never modified.
  • Optimization stops when the best value so far improves by at most rtol·|best| + atol over the last window steps (defaults 1e-2, 1e-8, 10). For log-space acquisitions this compares absolute differences, which are relative changes in EI or PI. n is now the maximum number of steps, and rtol=None restores fixed-n behavior.
  • Returns the best in-domain iterate rather than the last one.

Docs and demo

  • docs/formalism/gp.md: note on the Kriging Believer heuristic.
  • demos/gp-1d.ipynb: passes random candidates straight to get_sample_point, replacing the manual pre-screening step.

Notes

  • PI with xi=0 can pick nearly the same point repeatedly within a batch. This is a known weakness of PI, documented in its docstring; use xi > 0.
  • JAX recompiles once for each point in a batch, because the training set grows. A q=3 batch takes about 1–2 s on CPU.
  • With scalar noise below nugget, the fantasy noise is floored, so Kronecker kernels fall back to a dense Cholesky solve during batch selection. Results are unaffected; it's just slower.
  • On a test problem, convergence stopping cut steps from 3000 to 13–40 while landing on essentially the same point.

Testing

  • 12 new tests in tests/test_gp.py: batch selection (including that a greedy max-variance batch matches sequential conditioning), each acquisition function, the log-space EI math, noise handling, early stopping, and input checks. The full suite passes (52 tests).
  • Both flake8 workflow configurations pass, and demos/gp-1d.ipynb runs end to end.

AI Use

Much of these changes were made with the use of AI/LLMs, in particular Claude Opus 5.5. After I suggested an initial plan and iterating on that design, Claude was used to execute the implementation. I verified the implementation against the plan and verified consistency with the codebase. Finally, Claude was used to draft this PR.

@asher-m
asher-m requested a review from akilnarayan December 1, 2026 19:56
@asher-m asher-m self-assigned this Dec 1, 2026
@asher-m
asher-m added this pull request to stack #135 December 1, 2026 19:56
Base automatically changed from dev/dev to master December 2, 2026 04:41
* add gp.acquisition with AcquisitionFunction base class, MaximumVariance,
  UpperConfidenceBound, ExpectedImprovement, and ProbabilityOfImprovement
* EI and PI are computed in log space to keep values and gradients finite
  far from the incumbent
* add gp.posterior.Posterior, an immutable JAX-traceable posterior snapshot,
  and GaussianProcess.posterior(); posterior_mean/posterior_covariance
  delegate to it
* get_sample_point accepts acquisition=, q=, and fantasy_noise=, and returns
  shape (q, d); x may be one starting coordinate or (m, d) candidates
* q > 1 selects points greedily with the Kriging Believer heuristic, using
  local fantasy observations so the Gaussian process is never modified
* optimization keeps the best in-domain iterate rather than the last one
* default behavior (maximum posterior variance, q = 1) is unchanged
* update gp-1d demo to pass candidates directly to get_sample_point
* add Kriging Believer note to gp formalism docs
* add tests for batch selection, acquisitions, log-space EI, and noise
  augmentation
* get_sample_point stops once the best acquisition value improves by at
  most rtol * |best| + atol over the last window steps; n is now the
  maximum number of steps
* new keyword arguments rtol (default 1e-2), atol (default 1e-8), and
  window (default 10); rtol=None restores fixed-n optimization
* add AcquisitionFunction.log_scale (True for EI and PI), so convergence
  of log-space acquisitions compares absolute differences, i.e., relative
  changes of the underlying quantity
* add tests for early stopping, convergence of UCB and EI, the windowed
  criterion, and argument validation
* note the stopping criterion in the gp-1d demo
@asher-m

asher-m commented Dec 2, 2026

Copy link
Copy Markdown
Collaborator Author

The tests just failed—whoops!

This is a real failure that I'll need to investigate tomorrow. Until then, feel free to hold off on a review.

* python 3.14 introduced lazy evaluation of type annotations, which allows for the possibility of name collisions on evaluation
* these changes resolve this issue by importing members from gp submodules directly, rather than importing the entire submodule and type hinting at a member of a submodule
…posterior

* gp.posterior is distinct from gp.GaussianProcess.posterior
* this suppresses the style error

This branch has not been deployed

No deployments
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