package optim.doubles;

import optim.AbstractFunction;

public final class LineSearch {
  
  final AbstractFunction f;
  final double c1;
  final double c2;
  final double f0;
  final double slope0;
  final double alphaMin;
  final double alphaMax;
  double stepLength;
  
  public LineSearch(final AbstractFunction f, final double c1, final double c2, final double alphaMin, final double f0,
          final double slope0) {
    this.f = f;
    this.c1 = c1;
    this.c2 = c2;
    this.f0 = f0;
    this.slope0 = slope0;
    this.alphaMin = alphaMin;
    this.alphaMax = -1.0 / slope0;
    
  }

}

@@ -47,16 +47,39 @@
 unction;
+%0Aimport optim.Function;
 %0A%0Apublic
@@ -108,40 +108,277 @@
 h %7B%0A
+%0A
   
-%0A  final AbstractFunction f;%0A 
+private static final int MAX_UPDATE_ITERATIONS = 100;%0A  private static final double DELTA_MIN = 7.0/12.0;%0A  private static final double DELTA_MAX = 2.0;%0A  %0A  private final AbstractFunction f;%0A  private final Function psi;%0A  private final Function psiSlope;%0A  private
  fin
@@ -389,24 +389,32 @@
 ouble c1;%0A  
+private 
 final double
@@ -416,24 +416,32 @@
 ouble c2;%0A  
+private 
 final double
@@ -443,24 +443,32 @@
 ouble f0;%0A  
+private 
 final double
@@ -474,24 +474,32 @@
 e slope0;%0A  
+private 
 final double
@@ -511,16 +511,24 @@
 aMin;%0A  
+private 
 final do
@@ -544,16 +544,24 @@
 aMax;%0A  
+private 
 double s
@@ -571,18 +571,16 @@
 Length;%0A
-  
 %0A  publi
@@ -651,16 +651,26 @@
 uble c2,
+%0A         
  final d
@@ -701,26 +701,16 @@
 uble f0,
-%0A         
  final d
@@ -890,16 +890,1821 @@
 e0;%0A    
+this.psi = (alpha) -%3E f.at(alpha) - f0 - c1 * alpha * slope0;%0A    this.psiSlope = (alpha) -%3E f.slopeAt(alpha) - c1 * slope0;%0A%0A  %7D%0A%0A  private final IntervalValues updateInterval(final IntervalValues alphas) %7B%0A    double alphaL = alphas.alphaL;%0A    double alphaU = alphas.alphaU;%0A    double alphaT = getTrialValue(alphaL, alphaU);%0A%0A    boolean continueUpdating = true;%0A    while (continueUpdating) %7B%0A      if (f.at(alphaT) %3E f.at(alphaL)) %7B%0A        // alphaL stays the same and...%0A        alphaU = alphaT;%0A        continueUpdating = false;%0A      %7D else if (f.slopeAt(alphaT) * (alphaL - alphaT) %3E 0) %7B%0A        alphaL = alphaT;%0A        alphaT = getTrialValue(alphaL, alphaU);%0A      %7D else %7B%0A        alphaU = alphaL;%0A        alphaL = alphaT;%0A        continueUpdating = false;%0A      %7D%0A    %7D%0A    return new IntervalValues(alphaL, alphaU, alphaT);%0A  %7D%0A%0A  private final double search() %7B%0A    double alphaL = alphaMin;%0A    double alphaU = alphaMax;%0A    double alphaK = getTrialValue(alphaL, alphaU);%0A    IntervalValues alphas = new IntervalValues(alphaL, alphaU, alphaK);%0A%0A    int k = 0;%0A    while (!converged() && k %3C MAX_UPDATE_ITERATIONS) %7B%0A      alphas = updateInterval(alphas);%0A      alphaL = alphas.alphaL;%0A      alphaU = alphas.alphaU;%0A      k++;%0A      alphaK = getTrialValue(alphaL, alphaU);%0A    %7D%0A    return alphas.alphaT;%0A  %7D%0A%0A  private final double getTrialValue(final double alphaL, final double alphaU) %7B%0A    return 0.0;%0A  %7D%0A%0A  private final boolean converged() %7B%0A    return false;%0A  %7D%0A  %0A  private final class IntervalValues %7B%0A    private final double alphaL;%0A    private final double alphaU;%0A    private final double alphaT;%0A%0A    IntervalValues(final double alphaL, final double alphaU, final double alphaT) %7B%0A      this.alphaL = alphaL;%0A      this.alphaU = alphaU;%0A      this.alphaT = alphaT;%0A    %7D
 %0A  %7D%0A%0A%7D%0A

Update LineSearch.