SimpleValueChecker extends AbstractConvergenceChecker<PointValuePair> { @Override public boolean converged(final int iteration, final PointValuePair previous, final PointValuePair current) { if (maxIterationCount != ITERATION_CHECK_DISABLED && iteration >= maxIterationCount) { return true; } final double p = previous.getValue(); final double c = current.getValue(); final double difference = FastMath.abs(p - c); final double size = FastMath.max(FastMath.abs(p), FastMath.abs(c)); return difference <= size * getRelativeThreshold() || difference <= getAbsoluteThreshold(); } SimpleValueChecker(final double relativeThreshold,
                              final double absoluteThreshold);  SimpleValueChecker(final double relativeThreshold,
                              final double absoluteThreshold,
                              final int maxIter); @Override boolean converged(final int iteration,
                             final PointValuePair previous,
                             final PointValuePair current);  }
@Test public void testIterationCheck() { final int max = 10; final SimpleValueChecker checker = new SimpleValueChecker(1e-1, 1e-2, max); Assert.assertTrue(checker.converged(max, null, null)); Assert.assertTrue(checker.converged(max + 1, null, null)); }
@Test public void testIterationCheckDisabled() { final SimpleValueChecker checker = new SimpleValueChecker(1e-8, 1e-8); final PointValuePair a = new PointValuePair(new double[] { 1d }, 1d); final PointValuePair b = new PointValuePair(new double[] { 10d }, 10d); Assert.assertFalse(checker.converged(-1, a, b)); Assert.assertFalse(checker.converged(0, a, b)); Assert.assertFalse(checker.converged(1000000, a, b)); Assert.assertTrue(checker.converged(-1, a, a)); Assert.assertTrue(checker.converged(-1, b, b)); }