MCPcopy Create free account
hub / github.com/EdwardRaff/JSAT / testOptimize

Method testOptimize

JSAT/test/jsat/math/optimization/BFGSTest.java:49–72  ·  view source on GitHub ↗

Test of optimize method, of class BFGS.

()

Source from the content-addressed store, hash-verified

47 * Test of optimize method, of class BFGS.
48 */
49 @Test
50 public void testOptimize()
51 {
52 System.out.println("optimize");
53 Random rand = RandomUtil.getRandom();
54 Vec x0 = new DenseVector(3);//D=3 means one local minima for easy evaluation
55 for(int i = 0; i < x0.length(); i++)
56 x0.set(i, rand.nextDouble()+0.5);//make sure we get to the right local optima
57
58 RosenbrockFunction f = new RosenbrockFunction();
59 FunctionVec fp = f.getDerivative();
60 BFGS instance = new BFGS();
61
62 for(LineSearch lineSearch : new LineSearch[]{new BacktrackingArmijoLineSearch(), new WolfeNWLineSearch()})
63 {
64 instance.setLineSearch(lineSearch);
65 Vec w = new DenseVector(x0.length());
66 instance.optimize(1e-4, w, x0, f, fp, null);
67
68 for(int i = 0; i <w.length(); i++)
69 assertEquals(1.0, w.get(i), 1e-4);
70 assertEquals(0.0, f.f(w), 1e-4);
71 }
72 }
73}

Callers

nothing calls this directly

Calls 9

getRandomMethod · 0.95
lengthMethod · 0.95
setMethod · 0.95
getDerivativeMethod · 0.95
setLineSearchMethod · 0.95
optimizeMethod · 0.95
getMethod · 0.95
fMethod · 0.95
nextDoubleMethod · 0.45

Tested by

no test coverage detected