An implementation of the Wolfe Line Search algorithm described by Nocedal and Wright in Numerical Optimization (2nd edition) on pages 59-63. @author Edward Raff
| 14 | * @author Edward Raff |
| 15 | */ |
| 16 | public class WolfeNWLineSearch implements LineSearch |
| 17 | { |
| 18 | //default values that make setting in the constructor simple (shouldn't actually use) |
| 19 | private double c1 = Math.nextUp(0), c2 = Math.nextAfter(1, Double.NEGATIVE_INFINITY); |
| 20 | |
| 21 | /** |
| 22 | * Creates a new Wolfe line search with {@link #setC1(double) } set to |
| 23 | * {@code 1e-4} and {@link #setC2(double) } to {@code 0.9} |
| 24 | */ |
| 25 | public WolfeNWLineSearch() |
| 26 | { |
| 27 | this(1e-4, 0.9); |
| 28 | } |
| 29 | |
| 30 | /** |
| 31 | * Creates a new Wolfe line search |
| 32 | * @param c1 the <i>sufficient decrease condition</i> constant |
| 33 | * @param c2 the <i>curvature condition</i> constant |
| 34 | */ |
| 35 | public WolfeNWLineSearch(double c1, double c2) |
| 36 | { |
| 37 | setC1(c1); |
| 38 | setC2(c2); |
| 39 | } |
| 40 | |
| 41 | private AlphaInit initMethod = AlphaInit.METHOD1; |
| 42 | |
| 43 | double alpha_prev = -1, f_x_prev = Double.NaN, gradP_prev = Double.NaN; |
| 44 | |
| 45 | public enum AlphaInit |
| 46 | { |
| 47 | /** |
| 48 | * Initializes the new α value via α<sub>prev</sub> |
| 49 | * ∇f(x<sub>prev</sub>)<sup>T</sup>p<sub>prev</sub>/ |
| 50 | * ∇f(x<sub>cur</sub>)<sup>T</sup>p<sub>cur</sub> |
| 51 | */ |
| 52 | METHOD1, |
| 53 | /** |
| 54 | * Initializes the new α value via |
| 55 | * 2( f(x<sub>cur</sub>)-f(x<sub>prev</sub>))/φ'(0) |
| 56 | */ |
| 57 | METHOD2 |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * Sets the constant used for the <i>sufficient decrease condition</i> |
| 62 | * f(x+α p) ≤ f(x) + c<sub>1</sub> α p<sup>T</sup>∇f(x) |
| 63 | * <br> |
| 64 | * <br> |
| 65 | * This value must always be less than {@link #setC2(double) } |
| 66 | * @param c1 the <i>sufficient decrease condition</i> |
| 67 | */ |
| 68 | public void setC1(double c1) |
| 69 | { |
| 70 | if(c1 <= 0) |
| 71 | throw new IllegalArgumentException("c1 must be greater than 0, not " + c1); |
| 72 | else if(c1 >= c2) |
| 73 | throw new IllegalArgumentException("c1 must be less than c2"); |
nothing calls this directly
no outgoing calls
no test coverage detected