2011-02-02 62 views
8

我在寫一個遺傳算法,我打算從輪盤選擇轉移到錦標賽選擇,但我懷疑我的理解可能有缺陷。遺傳算法錦標賽選擇

如果我只是在人羣中選擇n/2個最佳解決方案,那麼我肯定會很快用完人口數量?

我對算法的理解是:

for(Member m in currentPopulation){ 
    Member randomMember1 = random member of currentPopulation which is then removed from currentPopulation 
    Member randomMember2 = as above; 
    //Mutate and crossover 

    if(randomMember1.getScore() > randomMember2.getScore()){ 
     nextGeneration.add(randomMember1); 
    } else { 
     nextGeneration.add(randomMember2); 
    } 
} 

我是否理解正確嗎?

+0

請相應地格式化你的代碼。 http://stackoverflow.com/editing-help – bdhar 2011-02-02 10:22:07

+0

哦,對不起! 看起來像別人已經有了,我會記住下次。 – Reu 2011-02-02 10:25:13

回答

9

在錦標賽選擇中,選定的個人不會從人口中移除。您可以選擇同一個人蔘加多個錦標賽。

看着你的代碼更接近一點,我發現你還有另一個誤解。你通常不會改變/交叉比賽的所有成員。相反,你進行一場比賽,選擇該比賽的勝者作爲個體進行突變/交叉。這意味着對於突變,你的錦標賽尺寸必須至少爲2,而對於交叉的尺寸必須至少爲3,最好的2勝(或者你可以執行2個單獨的錦標賽來選擇每個父母交叉)。

一些僞代碼可以幫助:

while (nextPopulation too small) { 
    Members tournament = randomly choose x members from currentPopulation 

    if(crossover){ 
     Member parents = select best two members from tournament 
     Member children = crossover(parents) 
     nextPopulation.add(children); 
    } else { 
     Member parent = select best one member from tournament 
     Member child = mutate(parent) 
     nextPopulation.add(child); 
    } 
} 
1

如果你在每一代中選擇從人口N/2個人,你最終會達到一個點,你必須爲1的人羣,你什麼除了選擇之外,還想要爲下一代使用變異或交叉來創造新成員,通常是那些在錦標賽中獲勝的人。

因此,對於每一代人,您都有一個大小爲n的人口 - 通過您的選擇將其減少到n/2,然後這些n/2成員重現和/或變異以產生大約n/2個成員你的下一代(平均而言,這將比那些沒有從上一代進步的人更加'更健康')。

0

錦標賽選擇:

  • 錦標賽選擇是從個體的羣體中選擇的個體的方法。
  • 錦標賽選擇包括在從羣體中隨機選擇的幾個人中進行幾次「錦標賽」。
  • 每個錦標賽的勝者(具有最佳身體素質的)被選爲交叉。
  • 當錦標賽規模較小時,錦標賽選擇也給所有人選擇機會,因此它保留了多樣性,但保持多樣性可能會降低收斂速度。
  • 但是,如果錦標賽規模較大,弱個體選擇機會較小會導致多樣性的喪失。

僞代碼:

choose k (the tournament size) individuals from the population at random 
choose the best individual from pool/tournament with probability p 
choose the second best individual with probability p*(1-p) 
choose the third best individual with probability p*((1-p)^2) 
and so on... 

確定性錦標賽選擇選擇最佳個體(當p = 1)在任何比賽。單向錦標賽(k = 1)選擇相當於隨機選擇。如果需要,所選擇的個體可以從選擇的羣體中移除,否則個體可以爲下一代選擇不止一次。與(隨機)健身比例選擇方法相比,比賽選擇通常由於缺乏隨機噪聲而在實踐中實施。

錦標賽選擇MatLab中:

Matepool=randi(PopLength,PopLength,2);%%select two individuals randomly for tournament and chooose the one with best fitness value 
%% number of tournament is equal to the number of population size 
for i=1:PopLength 
    if Fitness(Matepool(i,1))>= Fitness(Matepool(i,2)) 
     SelectedPop(i,1:IndLength)=CurrentPop(Matepool(i,1),1:IndLength); 
    else 
     SelectedPop(i,1:IndLength)=CurrentPop(Matepool(i,2),1:IndLength); 
    end 
end