Skip to content

Comments

Fix NaN EI/PI gradients for tiny positive std#9

Open
alex-rosen wants to merge 2 commits intoholgern:mainfrom
alex-rosen:fix/ei-pi-stability-mask
Open

Fix NaN EI/PI gradients for tiny positive std#9
alex-rosen wants to merge 2 commits intoholgern:mainfrom
alex-rosen:fix/ei-pi-stability-mask

Conversation

@alex-rosen
Copy link

Summary

This PR fixes a numerical stability issue in gaussian_pi and gaussian_ei when predicted std is extremely small but still positive.

In that regime, the gradient path can hit inf * 0 (overflow in improve_grad, underflow in norm.pdf(scaled)), which may produce NaN gradients.

What changed

  • In skopt/acquisition.py:

    • Keep acquisition value computation unchanged for std > 0.
    • In gradient mode, if |scaled| > 35, return a zero gradient (stable tail-limit behavior) instead of proceeding through an unstable numeric path.
  • In skopt/tests/test_acquisition.py:

    • Add a regression test:
      • test_ei_pi_gradients_are_finite_for_tiny_positive_std
      • Uses a tiny-std surrogate (std = 1e-160) with non-zero std_grad
      • Verifies EI/PI values and gradients are finite.

Why this is correct

For extreme tails, the EI/PI gradient should tend to zero. Returning zero gradient in this regime preserves optimization behavior while avoiding NaNs from numerical overflow/underflow.

Validation

Ran:
bash
pytest -q skopt/tests/test_acquisition.py -k "tiny_positive_std"
Result:

  • 2 passed

Result:- 2 passed

Alex Rosen and others added 2 commits February 10, 2026 14:12
Avoid NaN gradients in gaussian_ei/gaussian_pi for extreme tails by
masking unstable regions, and add a regression test.

Co-authored-by: Cursor <cursoragent@cursor.com>
Preserve acquisition values for std>0 while returning a zero gradient when
|scaled| is extreme, avoiding NaNs from inf*0 in analytic gradients.

Co-authored-by: Cursor <cursoragent@cursor.com>
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