root: add Brent's method for finding function roots#65
root: add Brent's method for finding function roots#65sbinet merged 11 commits intogonum:masterfrom fumin:brent
Conversation
This change also introduces a new package: root. The root package is intended to contain algorithms for function root finding. Aside from Brent's method, another candidate algorithm to be included in the root package is Newton's method. Fixes gonum/gonum#483 partially.
|
Please consider adding the solver as a method on a type. I suggest using the following interface: You may find an adaptive newton's method solver I've used over the years here: https://github.com/soypat/glgl/blob/aae7eebe6ecdcdde211850267709f8e65e4ac642/math/md1/md1.go#L54 I've succesfully used it in many different applications thanks to it's flexible nature. |
This is because a common usage of the package is: root, err := root.Brent() resulting in conflicts between the variable and the package names. In this case, it is better for the package name to give way to common variable names.
|
@soypat the I feel that downstream users might find this interface difficult to use, due to the bifurcation of parameters and their implications. Nonetheless, thanks for sharing your implementation of Newton's method. |
|
I'm not convinced we need to explicitly satisfy an interface at this stage. Providing the primitive seems like a good start to me. If we need to having interface satisfaction to help that, then that should be added, and if in the future there is a need to allow polymorphic behaviour, that can be added based on these primitives, either here or by client code. |
|
The package doc says it's finding roots but the package name is 'root'. FYI, "my" package is also named 'roots': (Apologies for the bikeshedding) |
|
I agree with Dan that we can worry about designing interfaces in the future. this is experimental after all. That said I would like to note that the NewtonRaphson root finder is also implements a bracket mode, but the bracket is part of the type :) |
|
I'm not saying things shouldn't be encapsulated into types, just that the interface satisfaction can happen later. |
After more thought, the package name root shadowing variables names is not an issue, as the more common variable name might be simply r.
|
@sbinet Thanks for chiming in on a better package name. After a survey of the standard library, I think our situation is more akin to the encoding, hash, and signal packages. On the topic on interfaces, perhaps we can defer designing those after we have Newton's method added into the root package? |
|
BTW, I knew this discussion rang a very distant bell... |
Yes, I am aware of gonum/gonum#896 , and found it a bit of a pity that it wasn't merged. Hopefully, by starting from here in the exp repo, we can achieve the above goal by iterating bit by bit with more freedom to try out different designs. |
|
I think all comments have been addressed, I wonder could anyone give this pull request another look? Thanks. |
|
LGTM! We can add root functions to the package and eventually we'll find a common pattern for an interface, if that ever makes sense. |
kortschak
left a comment
There was a problem hiding this comment.
This is outside my area of expertise, so leaving to others, but for light review.
gonum takes too long to review pull requests: gonum/gonum#2026 gonum/exp#65
|
@sbinet I wonder if you can take another look at this change? All previous comments have been addressed. |
|
Is there anything blocking the merge? |
|
I'll try to carve out some time before next week to review the PR. (apologies for the belated answer.) |
There was a problem hiding this comment.
apologies for the belated answer.
here are a couple of comments.
@kortschak (and others, @chewxy ?) may want to chime in.
|
@sbinet thanks for the review, all comments have been addressed and incorporated. |
|
@sbinet thanks for the comments, they have been incorporated. |
sbinet
left a comment
There was a problem hiding this comment.
LGTM
Thanks for sticking with us.
I'll wait for a couple of days to let others chime in.
(and feel free to ping us if we let the ball fall on the floor)
|
@sbinet thanks for the review, it's great to have feedback from you guys experienced in numerical computing. |
|
@sbinet yes of course, I think gonum/gonum#2028 does this. Thanks for the review. |
This change also introduces a new package: root.
The root package is intended to contain algorithms for function root finding.
Aside from Brent's method, another candidate algorithm to be included in the root package is Newton's method.
For gonum/gonum#483.
Please take a look.