@Test(dataProvider = "alterProbabilityParameters") public void alterProbability( final Integer ngenes, final Integer nchromosomes, final Integer npopulation, final Double p) { final Population<DoubleGene, Double> population = newDoubleGenePopulation(ngenes, nchromosomes, npopulation); // The mutator to test. final SinglePointCrossover<DoubleGene, Double> crossover = new SinglePointCrossover<>(p); final long nallgenes = ngenes * nchromosomes * npopulation; final long N = 200; final double mean = crossover.getOrder() * npopulation * p; final long min = 0; final long max = nallgenes; final Range<Long> domain = new Range<>(min, max); final Histogram<Long> histogram = Histogram.ofLong(min, max, 10); final LongMomentStatistics variance = new LongMomentStatistics(); for (int i = 0; i < N; ++i) { final long alterations = crossover.alter(population, 1); histogram.accept(alterations); variance.accept(alterations); } // Normal distribution as approximation for binomial distribution. System.out.println(histogram); // TODO: Implement test // assertDistribution(histogram, new NormalDistribution<>(domain, mean, // variance.getVariance())); }
@Test(invocationCount = 5) public void toDouble2_long() { final Random random = new LCG64ShiftRandom(); final Histogram<Double> histogram = Histogram.ofDouble(0.0, 1.0, 15); for (int i = 0; i < 100000; ++i) { histogram.accept(toDouble2(random.nextLong())); } assertUniformDistribution(histogram); }
@Test(invocationCount = 5) public void toDouble_int_int() { final Random random = new LCG64ShiftRandom(); final Histogram<Double> histogram = Histogram.ofDouble(0.0, 1.0, 15); for (int i = 0; i < 100000; ++i) { final long value = random.nextLong(); histogram.accept(toDouble((int) (value >>> 32), (int) value)); } assertUniformDistribution(histogram); }
@Test(invocationCount = 20, successPercentage = 95) public void newInstanceDistribution() { using( new Random(12345), r -> { final CharSeq characters = new CharSeq("0123456789"); final Factory<CharacterGene> factory = CharacterGene.of(characters); final Histogram<Long> histogram = Histogram.ofLong(0L, 10L, 10); final int samples = 100000; for (int i = 0; i < samples; ++i) { final CharacterGene g1 = factory.newInstance(); final CharacterGene g2 = factory.newInstance(); Assert.assertNotSame(g1, g2); histogram.accept(Long.valueOf(g1.getAllele().toString())); histogram.accept(Long.valueOf(g2.getAllele().toString())); } assertUniformDistribution(histogram); }); }