首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何用jenetics绘制遗传算法中不同世代的适应度图

如何用jenetics绘制遗传算法中不同世代的适应度图
EN

Stack Overflow用户
提问于 2017-12-22 09:18:49
回答 1查看 423关注 0票数 0

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

在我自己的代码上更具体:

代码语言:javascript
复制
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,并打印出每一代最佳元素的健身分数。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-12-22 10:27:23

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47938860

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档