@@ -0,0 +1,1553 @@
+package edu.neu.ccs.pyramid.optimization;%0A%0Aimport org.apache.mahout.math.Vector;%0A%0A/**%0A * minimize the function along the line%0A * Numerical Optimization, Second Edition, Jorge Nocedal Stephen J. Wright%0A * algorithm: page 37%0A * default parameters: page 142%0A * Created by chengli on 12/9/14.%0A */%0Apublic class BackTrackingLineSearcher %7B%0A    private Optimizable.ByGradientValue function;%0A    private double initialStepLength = 1;%0A    private double shrinkage = 0.5;%0A    private double c = 1e-4;%0A%0A    public BackTrackingLineSearcher(Optimizable.ByGradientValue function) %7B%0A        this.function = function;%0A    %7D%0A%0A    public double findStepLength(Vector searchDirection)%7B%0A        double stepLength = initialStepLength;%0A        double value = function.getValue(function.getParameters());%0A        Vector gradient = function.getGradient();%0A        double product = gradient.dot(searchDirection);%0A        while(true)%7B%0A            Vector step = searchDirection.times(stepLength);%0A            Vector target = function.getParameters().plus(step);%0A            double targetValue = function.getValue(target);%0A            if (targetValue %3C= value + c*stepLength*product)%7B%0A                break;%0A            %7D%0A            stepLength *= shrinkage;%0A        %7D%0A        return stepLength;%0A    %7D%0A%0A%0A%0A    public void setInitialStepLength(double initialStepLength) %7B%0A        this.initialStepLength = initialStepLength;%0A    %7D%0A%0A    public void setShrinkage(double shrinkage) %7B%0A        this.shrinkage = shrinkage;%0A    %7D%0A%0A    public void setC(double c) %7B%0A        this.c = c;%0A    %7D%0A%7D%0A

add class BackTrackingLineSearcher