Extracted the gradient descent example into a separate class
This commit is contained in:
parent
db0481e9cf
commit
e02e79308f
2 changed files with 16 additions and 11 deletions
16
src/main/java/ExampleGradientDescent.java
Normal file
16
src/main/java/ExampleGradientDescent.java
Normal 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));
|
||||||
|
}
|
||||||
|
}
|
|
@ -86,17 +86,6 @@ public class GradientDescent {
|
||||||
return findLocalMinimum(f, initialX, STANDARD_MAX_ITERATIONS);
|
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() {
|
public double getPrecision() {
|
||||||
return precision;
|
return precision;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue