【问题标题】:How to plot the fitness of different generations in my GA using jenetics如何使用 jenetics 在我的 GA 中绘制不同世代的适应度
【发布时间】:2018-06-04 22:49:54
【问题描述】:

一般来说,您将如何打印或绘制使用 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 jenetics


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2017-08-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-07-23
      • 1970-01-01
      • 2022-01-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多