@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()));
  }
Пример #2
0
  @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);
        });
  }