-
-
Notifications
You must be signed in to change notification settings - Fork 5.1k
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
ENH: optimize, returning True from callback function halts minimization #4384
Conversation
As part of this PR I'm wondering it it would be possible to have some way of tracking the progress of the minimization. For example, for a long minimization one could use this PR to halt the minimization if it's taking too long. But you might want to stop it after so many At the moment the |
Why did you choose to return |
I noticed that the basinhopping code halts if the callback returned True.
|
Andrew Nelson a écrit :
I guess so. One advantage of this approach is that you can carry |
The question of tracking the state of the minimization after halting reminds me of the approach taken in this project: https://github.com/mikecroucher/nearest_correlation/blob/master/nearest_correlation.py. I suggested that they could use an interface modeled on scipy's |
So there are two places a user could raise an My use case is tracking what a minimizer is doing. I am using differential_evolution and a minimization can go on for a few minutes. I am doing this in a GUI program. I want to track (and display) what's happening to chi2, how many iterations have been done, how close to convergence I am, etc. If I notice a problem I would like to halt, but keep the best solution so far. As I see it there are two places for improvement:
|
Andrew Nelson wrote:
Working at the callback level is probably easier and makes more sense,
In addition, we could simply bind the exception object to the
So, in essence, you'd like to pass a state object similar to the final |
Actually one could just have |
I was thinking that it could be achieved relatively simply by wrapping the callback function, similar to what a decorator can do. The wrapping function could take care of constructing the OptimizeResult and hold the try catch block. |
@dlax, @argriffing how about this example: |
Andrew Nelson a écrit :
AFAICT, this does not preserve backwards compatibility. In other words, |
That's correct. Unfortunately I don't know how one would handle backwards compatibility. I suppose it could be caught as an exception in the wrapper code? |
this will be superseded by #8414, if it gets merged. |
Closing this as superseded by #17486 |
If the
callback
functions in scipy.optimize returnTrue
, then the minimization halts.I have not modified
optimize.TNC
because thecallback
function is called in the Fortran somewhere.