【发布时间】:2012-09-28 05:57:59
【问题描述】:
我正在为遗传算法实施轮盘赌选择方法。从本质上讲,我的问题非常简单,但我无法完全理解它。在我的适应度函数中,如果答案非常错误,它可能会返回 -3000% 左右。我的问题是,当我尝试为我的结果分配概率时,它们会倾向于错误的答案。
例如: 如果我的百分比在数组中并且是 [92, 68, 5, -4, -3546] (从高到低) 我需要让较低指数中的数字比具有较高指数的数字更有可能被选中。
忽略我的适应度函数,如何在考虑大负数的情况下基于此创建概率?
我在另一个问题中发现的一些基本代码:
public Individual rouletteWheelSelection() {
double randNum = m_rand.nextDouble() * this.totalFitness;
int idx;
for (idx=0; idx<POP_SIZE && randNum>0; ++idx) {
randNum -= m_population[idx].getFitnessValue();
}
return m_population[idx-1];
}
(原文链接:GA written in Java)
我让我的 GA 使用不同的选择方法,但现在我正在尝试修改这个方法来代替它。任何帮助将不胜感激。
***编辑
以下代码是我修改的rouletteWheelSelection:
private Chromosome rouletteWheelSelection(){
double randNum = Math.abs(rand_num.nextDouble() * totalFitness);
int idx;
for (idx=0;idx<NUM_CHROMOSOMES && randNum>0;++idx){
randNum -= Math.abs(population[idx].getFitness());
}
return population[NUM_CHROMOSOMES-idx];
}
这是我的适应度函数:
public double getFitness()
{
String working = bitString;
int x1 = Integer.parseInt(working.substring(0,6),2);
int x2 = Integer.parseInt(working.substring(6),2);
double result = ScratchGA.functionTest(x1,x2);
double percentAccuracy = (1- Math.abs(((ScratchGA.getDesired() - result)/ScratchGA.getDesired())))*100;
if (percentAccuracy <= 100)
{
return percentAccuracy;
}
else
{
return -percentAccuracy;
}
}
当时的想法是一个值与我需要的值相差超过 100%,我把它推到排序列表的末尾是负面的。
【问题讨论】:
标签: java genetic-algorithm genetic-programming roulette-wheel-selection