如何使用jenetics在我的GA中绘制不同世代的适应度

问题描述 投票:0回答:1

一般来说,您如何打印或绘制使用jenetics库创建的每一代的健身分数?

更具体的我自己的代码:

private static double clashes(final Genotype<EnumGene<Integer>> gt) {
        // Calculate the path distance.



                final int[] intTriplets=gt.getChromosome().stream().mapToInt(EnumGene<Integer>::getAllele).toArray();
                ArrayList<Triplet> triplets=new ArrayList<Triplet>();
                for(int i=0;i<intTriplets.length;i++)
                {
                    Triplet e=intToTriplet.get(intTriplets[i]);
                    triplets.add(e);
                }
                double clashes=returnScore(triplets);

        return (clashes);



public static void main(String[] args) {
        final Engine<EnumGene<Integer>, Double> engine = Engine
            .builder(
                GA::clashes,
                PermutationChromosome.ofInteger(REQUIREMENTS))
            .optimize(Optimize.MINIMUM)
                        .offspringFraction(0.75)//0.6 standaard
                        .survivorsSelector (new TournamentSelector <>(7) )  //standaard new TournamentSelector <>(3)
                        .offspringSelector (new RouletteWheelSelector <>() )  //standaard new TournamentSelector <>(3)
            .maximalPhenotypeAge(40)//standaard 70
            .populationSize(1000)

                       //.selector(new TournamentSelector<>(5))
            .alterers(
                new SwapMutator<>(0.02),
                new PartiallyMatchedCrossover<>(0.7))
            .build();

我注意到可能会有早熟收敛,因为尽管将稳态健身限制设定为200,我只能获得有限的几代人。所以我想弄清楚健身分数的变化接近0,以及打印每一代中最佳元素的健身分数。

java genetic-algorithm
1个回答
0
投票

您可以使用Stream.peek方法在进化过程中打印出信息:java EvolutionResult<EnumGene<Integer>, Double> stream = engine.stream() .limit(100) .peek(er -> System.out.println(er.getBestPhenotype())) .collect(EvolutionResult.toBestEvolutionResult()); 这将打印每一代的最佳表型。

© www.soinside.com 2019 - 2024. All rights reserved.