-
-
Notifications
You must be signed in to change notification settings - Fork 371
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix line search to avoid non-finite gradients #3309
base: develop
Are you sure you want to change the base?
Conversation
Related to stan-dev#3306 Modify the `WolfeLineSearch` function in `src/stan/optimization/bfgs_linesearch.hpp` to handle non-finite gradients. * Check if the function value `func_val` is finite. * Check if the gradient `gradx1` is finite. * If either the function value or the gradient is non-finite, restart the line search with a smaller step size. --- For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/stan-dev/stan/issues/3306?shareId=XXXX-XXXX-XXXX-XXXX).
* Add `linesearch_testfunc_nonfinite` class to simulate non-finite gradients * Add `wolfeLineSearch_nonfinite_gradient` test to verify that the optimization process can handle non-finite gradients * Ensure the test checks that the line search algorithm avoids returning points with finite log density but infinite gradient --- For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/stan-dev/stan/issues/3306?shareId=XXXX-XXXX-XXXX-XXXX).
Add test for handling non-finite gradients in WolfeLineSearch
For more details, open the Copilot Workspace session. |
For what it's worth, this was a vague attempt at solving this problem using Copilot Workspace. It'd be very cool if this was all it took. Close this if it's garbage because I'm not that familiar with stan's internals. If the robot did a good job I'm happy to investigate this more. |
The fix looks OK in that it will do the same thing for a non-finite return now as for an error code. I kicked off the integration testing. It'd be nice if the test tested all the ways things could fail. The new test is testing a 1 return, but I didn't see how that was being triggered. The easiest is just plugging in three different functions for testing:
All these should then return a 1 from the line search. |
Alright, let's give that a try. Apologies in advance, very new to the whole stan toolchain and I'll likely be pretty clumsy. |
Thanks, @cpfiffer. We're happy to help, as our C++ is pretty complicated in a lot of places. |
The test The single-line fix looks correct but I'm puzzled as to why it is needed. At the previous line, stan/src/stan/optimization/bfgs.hpp Lines 351 to 360 in 01f5923
|
Related to #3306
Modify the
WolfeLineSearch
function insrc/stan/optimization/bfgs_linesearch.hpp
to handle non-finite gradients.func_val
is finite.gradx1
is finite.For more details, open the Copilot Workspace session.