Fix NaN EI/PI gradients for tiny positive std#9
Open
alex-rosen wants to merge 2 commits intoholgern:mainfrom
Open
Fix NaN EI/PI gradients for tiny positive std#9alex-rosen wants to merge 2 commits intoholgern:mainfrom
alex-rosen wants to merge 2 commits intoholgern:mainfrom
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR fixes a numerical stability issue in
gaussian_piandgaussian_eiwhen predictedstdis extremely small but still positive.In that regime, the gradient path can hit
inf * 0(overflow inimprove_grad, underflow innorm.pdf(scaled)), which may produceNaNgradients.What changed
In
skopt/acquisition.py:std > 0.|scaled| > 35, return a zero gradient (stable tail-limit behavior) instead of proceeding through an unstable numeric path.In
skopt/tests/test_acquisition.py:test_ei_pi_gradients_are_finite_for_tiny_positive_stdstd = 1e-160) with non-zerostd_gradWhy 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 passedResult:-
2 passed