3

I have implemented Roulette wheel selection in GA.

   TotalFitness=sum(Fitness);
    ProbSelection=zeros(PopLength,1);
    CumProb=zeros(PopLength,1);

    for i=1:PopLength
        ProbSelection(i)=Fitness(i)/TotalFitness;
        if i==1
            CumProb(i)=ProbSelection(i);
        else
            CumProb(i)=CumProb(i-1)+ProbSelection(i);
        end
    end

    SelectInd=rand(PopLength,1);

    for i=1:PopLength
        flag=0;
        for j=1:PopLength
            if(CumProb(j)<SelectInd(i) && CumProb(j+1)>=SelectInd(i))
                SelectedPop(i,1:IndLength)=CurrentPop(j+1,1:IndLength);
                flag=1;
                break;
            end
        end
        if(flag==0)
            SelectedPop(i,1:IndLength)=CurrentPop(1,1:IndLength);
        end
    end

Now i was trying to implement rank selection in GA. I learned that:

  • Rank selection first ranks the population and then every chromosome receives fitness from this ranking.

  • The worst will have fitness 1, second worst 2 etc. and the best will have fitness N (number of chromosomes in population).

I saw these link1 and link2 and what i understood is that:

  1. First i will sort the Fitness value of the Population.

  2. Then if the Population number is 10 then i will give the probability of selection to the Population like 0.1,0.2,0.3,...,1.0 .

  3. Then i will calculate cumulative Fitness like roulette wheel.
  4. And the next steps is same as roulette wheel.

My Implementation:

  NewFitness=sort(Fitness);
    NewPop=round(rand(PopLength,IndLength));

    for i=1:PopLength
        for j=1:PopLength
            if(NewFitness(i)==Fitness(j))
                NewPop(i,1:IndLength)=CurrentPop(j,1:IndLength);
                break;
            end
        end
    end
    CurrentPop=NewPop;

    ProbSelection=zeros(PopLength,1);
    CumProb=zeros(PopLength,1);

    for i=1:PopLength
        ProbSelection(i)=i/PopLength;
        if i==1
            CumProb(i)=ProbSelection(i);
        else
            CumProb(i)=CumProb(i-1)+ProbSelection(i);
        end
    end

    SelectInd=rand(PopLength,1);

    for i=1:PopLength
        flag=0;
        for j=1:PopLength
            if(CumProb(j)<SelectInd(i) && CumProb(j+1)>=SelectInd(i))
                SelectedPop(i,1:IndLength)=CurrentPop(j+1,1:IndLength);
                flag=1;
                break;
            end
        end
        if(flag==0)
            SelectedPop(i,1:IndLength)=CurrentPop(1,1:IndLength);
        end
    end



Am i understanding the algo wrong?? If it is then can anyone give me any idea how to modify my roulette wheel to rank selection??

Community
  • 1
  • 1
Setu Kumar Basak
  • 11,460
  • 9
  • 53
  • 85

1 Answers1

7

If the population has N individuals, the best individual gets rank N and the worst 1 then

TotalFitness = sum(Fitness);

should be changed with:

TotalFitness = (N + 1) * N / 2;

(probably TotalFitness isn't anymore the right name for the variable, but let it go)

(N + 1) * N / 2 is just the sum of the ranks:

1 + 2 + ... + N = (N + 1) * N / 2

The probability of selection should be changed from:

ProbSelection(i) = Fitness(i) / TotalFitness;

to

ProbSelection(i) = i / TotalFitness;

Here using the rank instead of the fitness and assuming that the first individual of the population is the worst and the last is the best (sorted population).

Hence the complexity of the rank selection algorithm is dominated by the complexity of the sorting (O(N * log(N)).

You can see that the probability of selection for the worst individual is:

1 / ((N + 1) * N / 2) = 2 / ((N + 1) * N)

and the probability for the best individual is:

N / (((N + 1) * N / 2)) = 2 * (N + 1)

This is a linear rank selection: the ranks are in a linear progression. There are other schemes of rank selection (e.g. exponential).

manlio
  • 18,345
  • 14
  • 76
  • 126
  • I have implemented code and I implemented like giving 0.1,0.2,0.3,...1.0 when popLength=10.But you are telling me to give 1/55,2/55,3/55... like that.so the last candidate will get 10/55.Is it right?? – Setu Kumar Basak Jan 23 '16 at 13:21
  • 1
    Right (the answer has been written before your edit). The key point is that the "fitness" assigned to each individual depends **only** on its position and not on the actual fitness. The values associated with the rank (.1, .2 or 1/55, 2/55...) are related to the _selective pressure_ which is very important for the performance of the algorithm but isn't the main aspect. The main aspect is that rank-based selection maintains a constant pressure in the evolutionary search not being influenced by "super-individuals". – manlio Jan 23 '16 at 13:45