Giter Site home page Giter Site logo

Comments (3)

dschmitz89 avatar dschmitz89 commented on June 11, 2024

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.

SterlingYM avatar SterlingYM commented on June 11, 2024

@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:

  1. 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.
  2. 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 avatar dschmitz89 commented on June 11, 2024

@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:

  1. 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.
  2. 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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.