Skip to content

ExpectedImprovement returns NaN for zero predictive variance at the improvement threshold #621

Open

Description

@AHMETHAKANBEZIR1

On master af8b928, ExpectedImprovement.base_acq computes a/std unconditionally. At std=0 and mean=y_max+xi it returns NaN, although a deterministic predictive distribution has expected improvement max(mean-y_max-xi,0). Other zero-variance points also emit divide-by-zero warnings.

import numpy as np
from bayes_opt.acquisition import ExpectedImprovement
from sklearn.gaussian_process import GaussianProcessRegressor
from sklearn.gaussian_process.kernels import ConstantKernel
a = ExpectedImprovement(xi=0)
a.y_max = 1.0
gp = GaussianProcessRegressor(
    kernel=ConstantKernel(1.0, constant_value_bounds='fixed'),
    alpha=0, optimizer=None,
).fit([[0.]], [1.])
mean, std = gp.predict([[0.], [1.]], return_std=True)
print(mean, std)              # [1. 1.] [0. 0.]
print(a.base_acq(mean, std))  # [nan nan], expected [0. 0.]

Reproduced in Python 3.12 / NumPy 2.5.3 / sklearn 1.9.1. The older #516 reported the warning without a complete reproduction and was closed pending information; the current API and an actual GP reproduction are shown here. No open overlapping PR found.

Proposed fix: avoid division by zero and use the deterministic positive-part expectation at zero variance, preserving the formula for positive std, broadcasting and scalar calls. Add a focused mixed-variance regression checked against a numerical Gaussian expectation and a real zero-variance GP control. ProbabilityOfImprovement's threshold/tie convention is outside this issue.

AI assistance: Codex autonomously reproduced this report and is preparing the contribution; no independent human review has occurred.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions