-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
ENH: optimize.elementwise: vectorized scalar optimization and root finding tools #20800
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
Conversation
…ding tools [docs only]
For the naming I think I would do
Or use verbs for the above to have |
It sounds like you are suggesting to change from verbs to nouns, but then at the end you write that verbs are OK? They are all intended to be verbs right now. "bracket" is a verb already, and whether it's "bracket_minimum" or "bracket_minimizer" is a separate question noted in the top post. The one that is questionable as a verb is "rootfind". "root-finding" is a present participle verb that is often used as an adjective, suggesting that "root-find" could be used as a verb. It's not common to do so in English, but there are a fair number of functions named |
I meant that I would either use nouns or verbs. Not mix. Also this could work
|
Right. I interpret the existing names as verbs. (To use verb or noun for a function is an age-old debate, and we are inconsistent in "minimize" is a verb. "bracket" is a verb or a noun - it seems you (@tupui) can interpret it as a verb, too, given the suggestion of |
For root and find, I think that it would be better to harmonise it with minimize as I proposed above (modulo the grammar). So if we have a |
I interpret that as mixing verbs and nouns, though. There, |
Yeah I mean, |
This is getting quite long, so this will be my last post about the names until we hear from others. Assuming by As a compromise, I can live with
Making these all look consistent as nouns may be tricky. |
I prefer It just so happens that there isn't a good verb to describe finding roots of a function, but I don't think that means we should abandon a good verb for finding the minimum/minimizer. I like using I like |
OK, so with
I think whichever way we go, I would prefer to pair |
My vote is on
Symmetric for users |
I'd accept either |
Great. How about questions 1 and 3? |
Yes to both for me. I prefer to keep this focused and for the arrays I personally preferred when my data is not modified by the function using it. |
For question 1) +1 for keeping the diff small by writing a wrapper like you described. |
Right.
I assume you mean that this should be a separate PR. Probably - I think it can/should be changed in the EIM infrastructure anyway, not this code. I'll add the tests. |
I'm not sure why the CircleCI doc build job is not showing up above, but the link is here. As you can see in the rendered docs, I'm not getting the expected TOC from |
6565ce2 demonstrates what I mean for the tests, item 1. LMK if that looks good and I'll repeat that for the other functions. |
That looks good to me. |
I'll try to fix the failure after the doc build finishes.
|
[skip ci] Co-authored-by: Matt Haberland <mhaberla@calpoly.edu>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks Matt. This has gone through the forum and LGTM 🚀
Reference issue
Closes gh-7242
Closes gh-18445
Toward gh-6379
Toward gh-18867
What does this implement/fix?
There have been requests for scalar rootfinders and minimizers to have a callback interface and be vectorized like
newton
. It would also be nice for such rootfinders and minimizers to have a consistent interface, accept both absolute and relative tolerances on the abscissa and function value, provide detailed output information, and be array-API compatible. This PR attempts to address these needs by providing a public interface to the following private functions:scipy.optimize._chandrupatla._chandrupatla
(rootfinding) →scipy.optimize.elementwise.rootfind
scipy.optimize._chandrupatla._chandrupatla_minimize
(minimization) →scipy.optimize.elementwise.minimize
scipy.optimize._bracket._bracket_root
(root bracketing) →scipy.optimize.elementwise.bracket_root
scipy.optimize._bracket._bracket_minimum
(minimum bracketing) →scipy.optimize.elementwise.bracket_minimum
Rationale for adding new functions rather than extending
root_scalar
androot_minimize
can be found in #7242 (comment) and #20624 (comment), respectively. These functions are put in a newelementwise
namespace rather than the baseoptimize
namespace to keep the function names manageable without conflicting with existing function names. The APIs forrootfind
andminimize
have been designed with the option to add amethod
argument in mind; they will be equally appropiate for other common bracketing and derivative-based rootfinding and minimization methods.Additional information
Currently, only
elementwise.rootfind
has array API support (see gh-20689); the rest will be converted over the summer.Questions:
test_chandrupatla.py
andtest_bracket.py
. In this PR, I don't want to convert the tests completely to use the new interfaces; this can be done when new methods are added and the tests are parameterized over all methods. For this PR, how about we leave the tests untouched but a) rather than importing the private functions in the test file, we import only the public functions and b) include in the test file a wrapper that exposes the public function with the interface of the private function. (Yes, effectively, the arguments and returns would get converted back and forth.) This would keep the diff tiny so that this PR can focus on the API rather than the nitty gritty. Update: Done.bracket_minimum
might not be consistent withbracket_root
; perhapsbracket_minimum
should bebracket_minimizer
orbracket_root
should bebracket_zero
. This is worth discussing. Update: "minimum" is acceptable. "minimizer" could be confused with an algorithm or function for performing minimization.To do: