[英]How to plot the fitness of different generations in my GA using jenetics
一般来说,您将如何打印或绘制使用 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,但我只得到有限的代数。所以我想弄清楚适应度得分的变化接近于哪一代,以及打印每一代中最佳元素的适应度分数。
您可以使用Stream.peek
方法打印进化过程中的信息: java EvolutionResult<EnumGene<Integer>, Double> stream = engine.stream() .limit(100) .peek(er -> System.out.println(er.getBestPhenotype())) .collect(EvolutionResult.toBestEvolutionResult());
这将为每一代打印最佳表型。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.