-
Notifications
You must be signed in to change notification settings - Fork 9
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
root: add Brent's method for finding function roots #65
base: master
Are you sure you want to change the base?
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. |
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.