Test of optimize method, of class BFGS.
()
| 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 | } |
nothing calls this directly
no test coverage detected