Skip to content

Handle deterministic predictions in Expected Improvement - #622

Open
AHMETHAKANBEZIR1 wants to merge 1 commit into
bayesian-optimization:masterfrom
AHMETHAKANBEZIR1:fix/zero-variance-expected-improvement
Open

AHMETHAKANBEZIR1 wants to merge 1 commit into
bayesian-optimization:masterfrom
AHMETHAKANBEZIR1:fix/zero-variance-expected-improvement

Conversation

@AHMETHAKANBEZIR1

@AHMETHAKANBEZIR1 AHMETHAKANBEZIR1 commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #621

When predictive std is zero, expected improvement is the positive part of the deterministic improvement, max(mean-y_max-xi,0). Avoid dividing by zero and use this result on zero-variance entries. Positive-variance entries retain the same formula and floating operation order. ProbabilityOfImprovement and its tie convention are outside this change.

Add focused tests for mixed zero/positive variance, xi=0/nonzero, scalar calls, and a real sklearn GaussianProcessRegressor with a fixed constant kernel and alpha=0. The positive-variance control uses numerical integration with scipy.stats.norm.expect instead of restating the closed-form implementation.

Validation (Windows CPU / Python 3.12):

  • New regression on untouched master af8b928: 3 failures. Real GP gives mean=[1,1], std=[0,0], old EI=[nan,nan].
  • Full collected test suite: 178 passed, 24 warnings with NumPy 2.5.3 / SciPy 1.18.1 / sklearn 1.9.1; package statement coverage 98%, modified executable lines covered.
  • Full acquisition module: 68 passed in both the above environment and NumPy 1.26.4 / SciPy 1.16.3 / sklearn 1.7.2.
  • Positive-std random controls are bitwise equal to the original formula; scalar/vector broadcasting checked.
  • Full configured Ruff 0.12.3 pre-commit lint and format checks and git diff check pass. Development extra resolves Ruff 0.16.10, which reports eight existing lint diagnostics and two existing Markdown-format differences on both untouched master and this branch; no new diagnostics.

Source installed editable with the development extra. Documentation builds, gallery notebook execution, GPU and other Python versions were not run. The current notebook-test path collects no example notebooks; the full collected test result should not be read as gallery validation.

AI assistance: Codex autonomously implemented the fix and ran validation; no independent human review has occurred. Codex is recorded as a commit coauthor.

Summary by CodeRabbit

  • Bug Fixes
    • Expected-improvement calculations now work reliably when a prediction has zero uncertainty, avoiding division errors and returning a non-negative acquisition value.
    • Calculations for predictions with uncertainty continue to use the existing expected-improvement behavior. This improves reliability when evaluating deterministic predictions, including cases where predictive variance is zero.

Use the deterministic positive-part expectation without dividing by zero.
Validate against numerical Gaussian integration and a deterministic GP.

Co-authored-by: Codex <codex@openai.com>
@coderabbitai

coderabbitai Bot commented Oct 2, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: 3a2540b7-2bf4-4745-abc5-17a01bcfbebf

📥 Commits

Reviewing files that changed from the base of the PR and between af8b928 and 6e8a460.

📒 Files selected for processing (2)
  • bayes_opt/acquisition.py
  • tests/test_acquisition.py

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.


📝 Walkthrough

Walkthrough

ExpectedImprovement.base_acq now avoids division by zero when predictive standard deviation is zero. It returns the nonnegative improvement for deterministic predictions and retains the expected-improvement formula for nonzero standard deviation. New tests cover zero-variance inputs and a deterministic Gaussian process.

Changes

Expected improvement

Layer / File(s) Summary
Zero-variance calculation and regression tests
bayes_opt/acquisition.py, tests/test_acquisition.py
ExpectedImprovement.base_acq returns the nonnegative improvement when standard deviation is zero. Tests cover xi values of 0.0 and 0.25, strict NumPy error handling, and a deterministic Gaussian process.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~8 minutes

Change: Bug fix · Severity of issue fixed: Low

Merge Risk: ⚪ Minimal · up to 6e8a4

Expected Improvement now returns deterministic positive-part improvement at zero predictive variance while retaining its existing calculation for positive variance. No actionable merge risk is evident in the reviewed change.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 6 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: handling deterministic predictions in Expected Improvement.
Linked Issues check ✅ Passed The PR addresses the coding requirements in [#621]. ExpectedImprovement.base_acq avoids division by zero and returns the deterministic positive-part improvement for zero standard deviation. Positive…
Out of Scope Changes check ✅ Passed The reviewed changes are limited to ExpectedImprovement.base_acq and focused tests in tests/test_acquisition.py. These changes directly implement and verify [#621]. No unrelated production behavio…
  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Autopilot is currently an internal CodeRabbit preview.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@codecov

codecov Bot commented Oct 2, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.36%. Comparing base (af8b928) to head (6e8a460).

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #622   +/-   ##
=======================================
  Coverage   98.36%   98.36%           
=======================================
  Files          10       10           
  Lines        1220     1221    +1     
=======================================
+ Hits         1200     1201    +1     
  Misses         20       20           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

ExpectedImprovement returns NaN for zero predictive variance at the improvement threshold

1 participant