Extracted the gradient descent example into a separate class

This commit is contained in:
lluni 2022-05-25 02:40:58 +02:00
parent db0481e9cf
commit e02e79308f
2 changed files with 16 additions and 11 deletions

View file

@ -0,0 +1,16 @@
import org.ejml.simple.SimpleMatrix;
import java.util.function.Function;
public class ExampleGradientDescent {
public static void main(String[] args) {
GradientDescent gd = new GradientDescent();
Function<Double, Double> f = x -> x*x;
System.out.println(gd.findLocalMinimum(f, 1));
Function<SimpleMatrix, SimpleMatrix> g = x -> x.elementMult(x);
SimpleMatrix initialX = new SimpleMatrix(2, 1, true, new double[]{1, 0.5});
System.out.println(gd.findLocalMinimum(g, initialX));
}
}

View file

@ -86,17 +86,6 @@ public class GradientDescent {
return findLocalMinimum(f, initialX, STANDARD_MAX_ITERATIONS);
}
public static void main(String[] args) {
GradientDescent gd = new GradientDescent();
Function<Double, Double> f = x -> x*x;
System.out.println(gd.findLocalMinimum(f, 1));
Function<SimpleMatrix, SimpleMatrix> g = x -> x.elementMult(x);
SimpleMatrix initialX = new SimpleMatrix(2, 1, true, new double[]{1, 0.5});
System.out.println(gd.findLocalMinimum(g, initialX));
}
public double getPrecision() {
return precision;
}