Skip to content
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

MAINT: clarify dual_annealing-minimizer_kwargs docstring. Closes #20614 #20676

Merged
merged 8 commits into from
May 9, 2024

Conversation

andyfaff
Copy link
Contributor

@andyfaff andyfaff commented May 9, 2024

Closes #20614

This PR explains more clearly how keyword arguments are passed to a local minimiser as part of dual_annealing.

As part of understanding how the minimizer_kwargs is passed to minimize I realised that if args are provided to the original dual_annealing call, then they were automatically provided to func and possibly jac using a wrapping approach, and therefore don't need to be specified in minimizer_kwargs. The PR therefore states not to include args in that dict. I then realised that the same wrapping mechanism should be implemented for hess and hessp, and did that as well.

@andyfaff andyfaff requested a review from mdhaber May 9, 2024 06:16
@github-actions github-actions bot added scipy.optimize maintenance Items related to regular maintenance tasks labels May 9, 2024
rng = np.random.default_rng(94253637693657847462)
def f(x, power):
return np.sum(np.exp(x ** power))

def jac(x, power):
return np.exp(x ** power) * power * x ** (power - 1)

def hess(x, power):
# calculated using WolframAlpha as d^2/dx^2 e^(x^p)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!
image
👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did it by hand first :-). Do you use WolframAlpha at all?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All the time to get reference values of special/stats functions. Sometimes need to use Mathematics proper if it's not provided with Alpha.

Co-authored-by: Matt Haberland <mhaberla@calpoly.edu>
Copy link
Contributor

@mdhaber mdhaber left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Could/should args be removed from minimizer_kwargs if it is present?

@mdhaber mdhaber requested a review from dschmitz89 May 9, 2024 06:38
Copy link
Contributor

@dschmitz89 dschmitz89 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One comment inline.

@mdhaber
Copy link
Contributor

mdhaber commented May 9, 2024

Yeah, I saw that hessp wasn't tested, but figured it was a conscious decision not to add it, and judged the probability of a breaking change (and the impact of one, given that it has been broken until now) was sufficiently low to not mention it : ) But better to have it than not! Thanks @dschmitz89 @andyfaff ! I'll merge tomorrow morning unless you beat me to it.

@dschmitz89
Copy link
Contributor

Allright, looks like the new test actually uncovered an issue. Thanks @andyfaff @mdhaber .

@dschmitz89 dschmitz89 merged commit 3bd289f into scipy:main May 9, 2024
30 checks passed
@dschmitz89 dschmitz89 added this to the 1.14.0 milestone May 9, 2024
@andyfaff andyfaff deleted the gh20614 branch May 9, 2024 12:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
maintenance Items related to regular maintenance tasks scipy.optimize
Projects
None yet
Development

Successfully merging this pull request may close these issues.

DOC: dual_annealing optimizer does not pass bounds to minimizer when minimizer_kwargs is partially given
3 participants