public void testTestValueAndGradient () { SimplePoly maxable = new SimplePoly (); testValueAndGradient (maxable); try { WrongSimplePoly badMaxable = new WrongSimplePoly (); testValueAndGradient (badMaxable); fail ("WrongSimplyPoly should fail testMaxmiziable!"); } catch (Exception e) {} }
public void testLinearLBFGS() { SimplePoly poly = new SimplePoly(); Optimizer bfgs = new LimitedMemoryBFGS(poly); bfgs.optimize(); assertEquals(5.0 / 6.0, poly.params[0], 1e-3); }
public static void main(String[] args) { junit.textui.TestRunner.run(suite()); } }// TestMaximizer
/** * Tests that getValue and getValueGradient are consistent * at a random parameter setting. * @see #testValueAndGradientCurrentParameters testValueAndGradientCurrentParameters * @throws IllegalStateException If the test fails. */ public static boolean testValueAndGradientRandomParameters (Optimizable.ByGradientValue maxable, Random r) { double[] params = new double [maxable.getNumParameters()]; for (int i = 0; i < params.length; i++) { params[i] = r.nextDouble (); if (r.nextBoolean ()) params [i] = -params[i]; } maxable.setParameters (params); testValueAndGradientCurrentParameters (maxable); return true; }
public static void main (String[] args) { junit.textui.TestRunner.run (suite()); }
public void testRandomMaximizable () { MaxEntTrainer trainer = new MaxEntTrainer(); Alphabet fd = dictOfSize (6); String[] classNames = new String[] {"class0", "class1"}; InstanceList ilist = new InstanceList (new Randoms(1), fd, classNames, 20); Optimizable.ByGradientValue maxable = trainer.getOptimizable (ilist); TestOptimizable.testValueAndGradient (maxable); }
public void testOrthantWiseLBFGSWithoutL1() { SimplePoly poly = new SimplePoly(); Optimizer bfgs = new OrthantWiseLimitedMemoryBFGS(poly); bfgs.optimize(); assertEquals(5.0 / 6.0, poly.params[0], 1e-3); }
public void testTestValueAndGradient () { SimplePoly maxable = new SimplePoly (); testValueAndGradient (maxable); try { WrongSimplePoly badMaxable = new WrongSimplePoly (); testValueAndGradient (badMaxable); fail ("WrongSimplyPoly should fail testMaxmiziable!"); } catch (Exception e) {} }
/** * Tests that getValue and getValueGradient are consistent * at a random parameter setting. * @see #testValueAndGradientCurrentParameters testValueAndGradientCurrentParameters * @throws IllegalStateException If the test fails. */ public static boolean testValueAndGradientRandomParameters (Optimizable.ByGradientValue maxable, Random r) { double[] params = new double [maxable.getNumParameters()]; for (int i = 0; i < params.length; i++) { params[i] = r.nextDouble (); if (r.nextBoolean ()) params [i] = -params[i]; } maxable.setParameters (params); testValueAndGradientCurrentParameters (maxable); return true; }
public static void main(String[] args) { junit.textui.TestRunner.run(suite()); } }// TestMaximizer
public static void main (String[] args) { junit.textui.TestRunner.run (suite()); }
public void testOrthantWiseLBFGSWithoutL1() { SimplePoly poly = new SimplePoly(); Optimizer bfgs = new OrthantWiseLimitedMemoryBFGS(poly); bfgs.optimize(); assertEquals(5.0 / 6.0, poly.params[0], 1e-3); }
public void testTrainedMaximizable () { MaxEntTrainer trainer = new MaxEntTrainer(); Alphabet fd = dictOfSize (6); String[] classNames = new String[] {"class0", "class1"}; InstanceList ilist = new InstanceList (new Randoms(1), fd, classNames, 20); MaxEnt me = (MaxEnt)trainer.train(ilist); Optimizable.ByGradientValue maxable = trainer.getOptimizable (ilist, me); TestOptimizable.testValueAndGradientCurrentParameters (maxable); }
public void testConjugateGradient() { SimplePoly poly = new SimplePoly(); Optimizer cg = new ConjugateGradient(poly); cg.optimize(); assertEquals(5.0 / 6.0, poly.params[0], 1e-3); }
public void testGradientAscent() { SimplePoly poly = new SimplePoly(); Optimizer gd = new GradientAscent(poly); gd.optimize(); assertEquals(5.0 / 6.0, poly.params[0], 1e-3); }
public void testLinearLBFGS() { SimplePoly poly = new SimplePoly(); Optimizer bfgs = new LimitedMemoryBFGS(poly); bfgs.optimize(); assertEquals(5.0 / 6.0, poly.params[0], 1e-3); }
public void testOrthantWiseLBFGSWithL1() { SimplePoly poly = new SimplePoly(); Optimizer bfgs = new OrthantWiseLimitedMemoryBFGS(poly, 3.0); bfgs.optimize(); assertEquals(2.0 / 6.0, poly.params[0], 1e-3); }
public void testConjugateGradient() { SimplePoly poly = new SimplePoly(); Optimizer cg = new ConjugateGradient(poly); cg.optimize(); assertEquals(5.0 / 6.0, poly.params[0], 1e-3); }
public void testGradientAscent() { SimplePoly poly = new SimplePoly(); Optimizer gd = new GradientAscent(poly); gd.optimize(); assertEquals(5.0 / 6.0, poly.params[0], 1e-3); }
public void testOrthantWiseLBFGSWithL1() { SimplePoly poly = new SimplePoly(); Optimizer bfgs = new OrthantWiseLimitedMemoryBFGS(poly, 3.0); bfgs.optimize(); assertEquals(2.0 / 6.0, poly.params[0], 1e-3); }