SimplePointChecker extends AbstractConvergenceChecker<PAIR> { @Override public boolean converged(final int iteration, final PAIR previous, final PAIR current) { if (maxIterationCount != ITERATION_CHECK_DISABLED && iteration >= maxIterationCount) { return true; } final double[] p = previous.getKey(); final double[] c = current.getKey(); for (int i = 0; i < p.length; ++i) { final double pi = p[i]; final double ci = c[i]; final double difference = FastMath.abs(pi - ci); final double size = FastMath.max(FastMath.abs(pi), FastMath.abs(ci)); if (difference > size * getRelativeThreshold() && difference > getAbsoluteThreshold()) { return false; } } return true; } SimplePointChecker(final double relativeThreshold,
                              final double absoluteThreshold);  SimplePointChecker(final double relativeThreshold,
                              final double absoluteThreshold,
                              final int maxIter); @Override boolean converged(final int iteration,
                             final PAIR previous,
                             final PAIR current);  }
@Test public void testIterationCheck() { final int max = 10; final SimplePointChecker<PointValuePair> checker = new SimplePointChecker<PointValuePair>(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 SimplePointChecker<PointValuePair> checker = new SimplePointChecker<PointValuePair>(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)); }