The Rosenbrock function is a function with at least one minima with the value zero. It is often used as a benchmark for optimization problems. The minima is the vector of all ones. Once N %gt; 3, more then one minima can occur. @author Edward Raff
| 15 | * @author Edward Raff |
| 16 | */ |
| 17 | public class RosenbrockFunction implements Function |
| 18 | { |
| 19 | |
| 20 | private static final long serialVersionUID = -5573482950045304948L; |
| 21 | |
| 22 | @Override |
| 23 | public double f(double... x) |
| 24 | { |
| 25 | return f(DenseVector.toDenseVec(x)); |
| 26 | } |
| 27 | |
| 28 | @Override |
| 29 | public double f(Vec x) |
| 30 | { |
| 31 | int N = x.length(); |
| 32 | double f = 0.0; |
| 33 | for(int i = 1; i < N; i++) |
| 34 | { |
| 35 | double x_p = x.get(i-1); |
| 36 | double xi = x.get(i); |
| 37 | f += pow(1.0-x_p, 2)+100.0*pow(xi-x_p*x_p, 2); |
| 38 | } |
| 39 | |
| 40 | return f; |
| 41 | } |
| 42 | |
| 43 | /** |
| 44 | * Returns the gradient of the Rosenbrock function |
| 45 | * @return the gradient of the Rosenbrock function |
| 46 | */ |
| 47 | public FunctionVec getDerivative() |
| 48 | { |
| 49 | return GRADIENT; |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * The gradient of the Rosenbrock function |
| 54 | */ |
| 55 | public static final FunctionVec GRADIENT = new FunctionVec() |
| 56 | { |
| 57 | @Override |
| 58 | public Vec f(double... x) |
| 59 | { |
| 60 | return f(DenseVector.toDenseVec(x)); |
| 61 | } |
| 62 | |
| 63 | @Override |
| 64 | public Vec f(Vec x) |
| 65 | { |
| 66 | Vec s = x.clone(); |
| 67 | f(x, s); |
| 68 | return s; |
| 69 | } |
| 70 | |
| 71 | @Override |
| 72 | public Vec f(Vec x, Vec drv) |
| 73 | { |
| 74 | int N = x.length(); |
nothing calls this directly
no outgoing calls
no test coverage detected