Allow root finding functions to use “models”
The “Models” that are part of the regression namespace are kind of like classed versions of closures. We could create a parent object which includes a simple derivative() function, which could be overridden by a child if the child had a simple derivative. This accurate derivative could be used in the root-finding algorithm instead of the estimate.
For PowerModel, for instance, there would be a derivative method that returned a function that would evaluate ab * xᵇ⁻¹ based on what a and b were already set to, taking only x as a parameter I presume.
If performing root-finding, Newton’s method would only need (∂y / ∂x), but for nonlinear least squares, there would need to be (∂y / ∂a) and (∂y / ∂b).
Even better, derivative() could return a new PowerLaw model with $new_a = $this->a* $this->b and $new_b = $this->b-1.