Is there a simple way to find the optimum of a PolynomialFunction (which is also a UnivariateDifferentiableFunction) in commons.math? There are a bewildering array of multidimensional optimizers, but AFAICS the only explicitly univariate optimizer is Brent, which doesn't take advantage of the differentiability.
Asked
Active
Viewed 364 times
0
-
Can you provide the mathematical function ? – ortis May 15 '15 at 08:01
-
It will be some arbitrary polynomial (supplied in the form of an array of coefficients to the PolynomialFunction constructor). – NietzscheanAI May 15 '15 at 08:28
-
What about the `NewtonRaphsonSolver` ? – ortis May 15 '15 at 08:40
-
So the idea is to use NR to find a zero of the derivative? – NietzscheanAI May 15 '15 at 08:49
-
yes. Once you have reached a zero derivative, you have an optimal solution (except for local minimum). – ortis May 15 '15 at 08:52
-
Presumably one could also happen to find a maximum or a point of inflection, so these conditions would have to be tested for. – NietzscheanAI May 15 '15 at 09:01
-
Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/77878/discussion-between-user217281728-and-ortis). – NietzscheanAI May 15 '15 at 09:27
2 Answers
1
Polynomials are special functions (in the general sense of "special") and have lots of distinctive, useful properties. My advice is to exploit those properties instead of trying to use a method for more general functions. Specifically, the extreme values of a polynomial are the roots of its derivative (where the second derivative is nonzero). The derivatives of a polynomial are easy to construct and evaluate, even in Java. I see that Apache Commons Math has LaguerreSolver to find the roots of a polynomial.

Robert Dodier
- 16,905
- 2
- 31
- 48
-
OK, this seems like a superior approach. Given the complex roots of a real polynomial, how do I determine which corresponds to the optimum (w.l.o.g. maximum)? – NietzscheanAI May 16 '15 at 07:39
-
Evaluate the polynomial at each root and see which one has the greatest or least value. Note that polynomials are unbounded as you go towards positive or negative infinity, so what you're finding are perhaps only local extrema. – Robert Dodier May 16 '15 at 19:32
-
I'm guessing that for your purposes you are looking for real extreme values so you can ignore complex roots. But only you know what you are trying to do. – Robert Dodier May 18 '15 at 17:20
-1
Here's some code in the spirit of the answer from ortis:
Optional< Double >
optimizeNR( PolynomialFunction f, double min, double max, double tol ) {
NewtonRaphsonSolver solver = new NewtonRaphsonSolver();
final double opt = solver.solve( MAX_EVAL, f.polynomialDerivative(), min, max);
if( f.value( opt - tol ) < opt && f.value( opt + tol ) < opt )
return Optional.of( opt );
else
return Optional.empty();
}

NietzscheanAI
- 966
- 6
- 16
-
I don't think this is good advice. Newton's method applied to polynomials has [interesting behavior](http://classes.yale.edu/fractals/mandelset/complexnewton/newtonbasins/Basins3.html) which is great if one is studying the problem abstractly but, I believe, only causes trouble if one needs to solve it concretely. – Robert Dodier May 15 '15 at 18:59
-
@Robert Dodier - do you have a suggested alternative - preferably from within commons math as per the question? – NietzscheanAI May 15 '15 at 20:20
-