package edu.neu.ccs.pyramid.optimization;

import org.apache.mahout.math.Vector;

/**
 * Created by chengli on 12/7/14.
 */
public class GradientDescent {
    private Optimizable.ByGradient function;
    double learningRate;

    public GradientDescent(Optimizable.ByGradient function, double learningRate) {
        this.function = function;
        this.learningRate = learningRate;
    }

    public void optimize(int numIterations){



    }

    public void update(){
        Vector parameters = function.getParameters();
        Vector gradient = function.getGradient();
        Vector updatedParams = parameters.minus(gradient.times(learningRate));
        parameters.assign(updatedParams);
        function.refresh();

    }
}

@@ -174,32 +174,37 @@
 zable.ByGradient
+Value
  function;%0A    d
@@ -206,28 +206,55 @@
     
-double learningRate;
+private BackTrackingLineSearcher lineSearcher;%0A
 %0A%0A  
@@ -300,16 +300,21 @@
 Gradient
+Value
  functio
@@ -319,375 +319,662 @@
 ion,
- double learningRate) %7B%0A        this.function = function;%0A        this.learningRate = learningRate;%0A    %7D%0A%0A    public void optimize(int numIterations)%7B%0A%0A%0A%0A    %7D%0A%0A    public void update()%7B%0A        Vector parameters = function.getParameters();%0A        Vector gradient = function.getGradient();%0A        Vector updatedParams = parameters.minus(gradient.times(learningRate
+%0A                           double initialStepLength) %7B%0A        this.function = function;%0A        this.lineSearcher = new BackTrackingLineSearcher(function);%0A        lineSearcher.setInitialStepLength(initialStepLength);%0A    %7D%0A%0A    public void optimize(int numIterations)%7B%0A%0A%0A%0A    %7D%0A%0A    public void update()%7B%0A        Vector parameters = function.getParameters();%0A        Vector gradient = function.getGradient();%0A        Vector direction = gradient.times(-1);%0A        double stepLength = lineSearcher.findStepLength(direction);%0A        System.out.println(%22stepLength=%22+stepLength);%0A        Vector updatedParams = parameters.plus(direction.times(stepLength
 ));%0A
@@ -1043,17 +1043,16 @@
 resh();%0A
-%0A
     %7D%0A%7D%0A

rename variables