Comments (3)
Thanks for the report @SterlingYM .
I understand that the API might be counter intuitive but passing bounds automatically to the local optimizer would break backwards compatibility. Another issue is that not all local optimizers support bounds.
I suggest that we add this behavior to the docstring explicitly. What do you think?
from scipy.
@dschmitz89 I understand changing the implementation comes with some difficulties. At least I think adding docstrings is worth it, since I spent many hours debugging this issue and I am sure someone else would do that in the future.
A few alternative ideas:
- Add a boolean option (something like
pass_bounds=False
) bounds are added to the user-defined kwargs when True. We can set it to False by default to maintain the backward compatibility. - Make additional option (
minimizer_kwargs_extra={}
) so that when this is used, these are strictly additional kwargs as the original docstrings suggest, not the only kwargs to be passed. If this is used only for updating the existing kwargs (whether user-defined or default), this is also backward compatible.
self.kwargs = minimizer_kwargs
self.kwargs_extra = minimizer_kwargs_extra
if not self.kwargs:
# define kwargs, same as the original implementation, and add the following
self.kwargs.update(self.kwargs_extra)
else:
self.kwargs.update(self.kwargs_extra) # this is not necessary but just in case
# (or we can have the kwargs.updateI() line outside the if statement)
I am suggesting this because the current workaround to specify bounds twice in a single function call of dual_annealing
seems silly and redundant, but again I understand if making such changes involves too much effort for this small issue. If that's the case, you can close the issue once the docstrings are changed.
from scipy.
@dschmitz89 I understand changing the implementation comes with some difficulties. At least I think adding docstrings is worth it, since I spent many hours debugging this issue and I am sure someone else would do that in the future.
A few alternative ideas:
- Add a boolean option (something like
pass_bounds=False
) bounds are added to the user-defined kwargs when True. We can set it to False by default to maintain the backward compatibility.- Make additional option (
minimizer_kwargs_extra={}
) so that when this is used, these are strictly additional kwargs as the original docstrings suggest, not the only kwargs to be passed. If this is used only for updating the existing kwargs (whether user-defined or default), this is also backward compatible.self.kwargs = minimizer_kwargs self.kwargs_extra = minimizer_kwargs_extra if not self.kwargs: # define kwargs, same as the original implementation, and add the following self.kwargs.update(self.kwargs_extra) else: self.kwargs.update(self.kwargs_extra) # this is not necessary but just in case # (or we can have the kwargs.updateI() line outside the if statement)I am suggesting this because the current workaround to specify bounds twice in a single function call of
dual_annealing
seems silly and redundant, but again I understand if making such changes involves too much effort for this small issue. If that's the case, you can close the issue once the docstrings are changed.
I fully agree that the current API seems silly. In fact, scipy.optimize
is not exactly an example of state of the art API design (3 different ways to specify bounds, arbitrary strings instead of enums just to name two). I have spent my fair share of time debugging API related issues as well .. class based optimizers would probably be the way improve things in the future but realistically, I do not see it happening. scipy.optimize
is used a LOT so downstream users/libraries will likely resist changes.
Adding one more option makes this already complex API even harder to grasp though in my opinion. Slightly related question: did you encounter the same issue with optimize.shgo
by any chance? It uses a similar API from what I know. Whatever we decide to do, it should be applied to shgo
as well.
from scipy.
Related Issues (20)
- DOC/BLD: Build uses python3 from wrong env HOT 2
- CI: adding a Windows CI job with MSVC + MKL + Intel Fortran (ifx) HOT 1
- MAINT: clean up `sparse._sputils.getdtype` HOT 1
- ENH: `ndimage.map_coordinates`: avoid array copy for big endian data HOT 4
- BUG: `interpolate.BSpline.basis_element` differs from `BSpline` on the last spline HOT 1
- BUG: scipy.optimize.curve_fit full_output and boundaries incompatible HOT 1
- DOC/DEV: Developer docs should mention Accelerate support HOT 5
- BUG: stats.kstest: units stripped from `astropy.unit.Quantity` objects starting with 1.12.0 HOT 1
- BUG: `zsh: abort python` after `scipy.linalg.sqrtm` on empty `np.array` on M1 Macbook via conda HOT 1
- BUG: special.lpmv(0,v,-1) returns incorrect value for non-integer v
- ENH: integrate: evaluate simultaneously a function and its jacobian for ODE integration HOT 2
- BUG: sparse.csgraph.dijkstra errors on inputs with int64 or no indices
- BUG: positional argument `DeprecationWarning` message is overly long HOT 10
- TST: TestEig.test_singular failing tolerance with generic BLAS installed HOT 2
- BUG: interpolate.griddata: memory leak in linear mode under Python 3.12 HOT 10
- DOC: Old SciPy version in embedded Jupyterlite notebooks HOT 12
- DOC: stats: wrong docstrings of `*Result` classes HOT 2
- BUG: Can't build scipy on main (1.15.0.dev0), PyObject_Vectorcall* not found HOT 3
- ENH: integrate: add array API-support HOT 2
- MAINT: Premature setting of attributes in `HBInfo` in `scipy.io._harwell_boeing`. HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from scipy.