0

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.

NietzscheanAI
  • 966
  • 6
  • 16

2 Answers2

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
  • Please see my answer for my suggested alternative. – Robert Dodier May 15 '15 at 21:24