@Override public boolean test(final EvolutionResult<?, N> result) { final Number fitness = result.getBestFitness(); if (fitness != null) { _buffer.accept(fitness.doubleValue()); } return !_buffer.isFull() || _proceed.test( _buffer.doubleMoments(_shortFilterSize), _buffer.doubleMoments(_longFilterSize) ); }
@Test public void bufferDoubleMoments() { final long seed = 0xdeadbeef; final int capacity = 10; final Random random = new Random(seed); final Buffer buffer = new Buffer(capacity); DoubleMomentStatistics statistics = new DoubleMomentStatistics(); for (int i = 0; i < buffer.capacity(); ++i) { final double value = random.nextDouble()*1000; buffer.accept(value); statistics.accept(value); final DoubleMoments moments = DoubleMoments.of(statistics); Assert.assertEquals(moments, buffer.doubleMoments(1000)); } final Random sr = new Random(seed); for (int i = 0; i < buffer.capacity(); ++i) { statistics = statistics(new Random(seed), i + 1, buffer.capacity() - 1); final double value = random.nextDouble()*1000; buffer.accept(value); statistics.accept(value); final DoubleMoments moments = DoubleMoments.of(statistics); Assert.assertEquals(moments, buffer.doubleMoments(1000)); } }
/** * Return the double moment statistics of the buffer values. * * @return the double moment statistics of the buffer values */ public DoubleMoments doubleMoments() { return doubleMoments(_length); }