Callback is not called with local minima of initial guess in basinhopping algorithm
See original GitHub issueMy issue is about …
As far as I understand, callback function is called when a local minima is found. When I use basinhopping global minimization algorithm, I have observed that the callback function is not called when local minima is found for initial guess. I have tried to reproduce this issue with the following example:
from scipy.optimize import basinhopping
import numpy as np
def func(x):
print("Objective function count: " + str(func.counter))
func.counter += 1
return np.random.rand(1)*1000
def callback_func(x, f, accepted):
print("Callback count: " + str(callback_func.counter))
callback_func.counter += 1
func.counter = 0
callback_func.counter = 0
x0 = 2000
minimizer_kwargs = {"method": "COBYLA", "options":{"maxiter": 1}}
optimizer = basinhopping(func, x0, minimizer_kwargs=minimizer_kwargs, niter=2, callback=callback_func)
It produces following result:
Objective function count: 0
Objective function count: 1
Callback count: 0
Objective function count: 2
Callback count: 1
For the above mentioned example, both callback function and the objective function should have been called thrice but callback is called only twice.
Scipy/Numpy/Python version information:
1.2.1 1.16.4 sys.version_info(major=3, minor=7, micro=4, releaselevel='final', serial=0)Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
scipy.optimize.basinhopping — SciPy v1.9.3 Manual
A callback function which will be called for all minima found. x and f are the coordinates and function value of the trial...
Read more >scipy.optimize.basinhopping — SciPy v0.14.0 Reference Guide
A callback function which will be called for all minimum found. x and f are the coordinates and function value of the trial...
Read more >Scipy BasinHopping not returning correct global minima
Depending on the start position x0, it returns different local minima - not the global one at 0. If we set x_0 =...
Read more >https://subversion.xray.aps.anl.gov/pyGSAS/branch/...
basinhopping : The basinhopping global optimization algorithm """ from __future__ ... from a local minima if normal basin hopping # steps are not...
Read more >statsmodels.base.optimizer — statsmodels
(The limited memory BFGS method does not store the full hessian but uses this ... function value) between local minima. stepsize : float...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

@rgommers, @prince2110, I think I’ve got to the bottom of this.
niter+1callbacks fornitersteps.Sorry for closing the issue prematurely, @prince2110 is correct here.
I’ve already done one, #13029.