@Override
    public NumberStatistics.Builder<G, R> evaluate(
        final Iterable<? extends Phenotype<G, R>> population,
        final int generation,
        final Optimize opt) {
      final Builder<G, R> builder = new Builder<>();
      builder.generation(generation);
      builder.optimize(opt);

      final MinMax<Phenotype<G, R>> minMax = new MinMax<>();
      final Variance<Integer> age = new Variance<>();
      final Variance<R> fitness = new Variance<>();

      accumulators.<Phenotype<G, R>>accumulate(
          population,
          minMax,
          age.map(Phenotype.Age(generation)),
          fitness.map(Phenotype.<R>Fitness()));
      builder.bestPhenotype(opt.best(minMax.getMax(), minMax.getMin()));
      builder.worstPhenotype(opt.worst(minMax.getMax(), minMax.getMin()));
      builder.fitnessMean(fitness.getMean());
      builder.fitnessVariance(fitness.getVariance());
      builder.samples((int) minMax.getSamples());
      builder.ageMean(age.getMean());
      builder.ageVariance(age.getVariance());
      builder.standardError(fitness.getStandardError());

      return builder;
    }
예제 #2
0
  /** Create a population of DoubleGenes */
  public static Population<DoubleGene, Double> newDoubleGenePopulation(
      final int ngenes, final int nchromosomes, final int npopulation) {
    final MSeq<DoubleChromosome> chromosomes = MSeq.ofLength(nchromosomes);

    for (int i = 0; i < nchromosomes; ++i) {
      chromosomes.set(i, DoubleChromosome.of(0, 10, ngenes));
    }

    final Genotype<DoubleGene> genotype = new Genotype<>(chromosomes.toISeq());
    final Population<DoubleGene, Double> population = new Population<>(npopulation);

    for (int i = 0; i < npopulation; ++i) {
      population.add(Phenotype.of(genotype.newInstance(), 0, FF).evaluate());
    }

    return population;
  }
예제 #3
0
  public static Population<EnumGene<Double>, Double> newPermutationDoubleGenePopulation(
      final int ngenes, final int nchromosomes, final int npopulation) {
    final Random random = new Random(122343);
    final MSeq<Double> alleles = MSeq.ofLength(ngenes);
    for (int i = 0; i < ngenes; ++i) {
      alleles.set(i, random.nextDouble() * 10);
    }
    final ISeq<Double> ialleles = alleles.toISeq();

    final MSeq<PermutationChromosome<Double>> chromosomes = MSeq.ofLength(nchromosomes);

    for (int i = 0; i < nchromosomes; ++i) {
      chromosomes.set(i, PermutationChromosome.of(ialleles));
    }

    final Genotype<EnumGene<Double>> genotype = new Genotype<>(chromosomes.toISeq());
    final Population<EnumGene<Double>, Double> population = new Population<>(npopulation);

    for (int i = 0; i < npopulation; ++i) {
      population.add(Phenotype.of(genotype.newInstance(), 0, PFF));
    }

    return population;
  }
예제 #4
0
 public static Phenotype<DoubleGene, Double> newDoublePhenotype(final double value) {
   return Phenotype.of(Genotype.of(DoubleChromosome.of(DoubleGene.of(value, 0, 10))), 0, FF)
       .evaluate();
 }