Logo Search packages:      
Sourcecode: python-biopython version File versions

def Bio::GA::Selection::RouletteWheel::RouletteWheelSelection::_set_up_wheel (   self,
  population 
) [private]

Set up the roulette wheel based on the fitnesses.

This creates a fitness proportional 'wheel' that will be used for
selecting based on random numbers.

Returns:

o A dictionary where the keys are the 'high' value that an
individual will be selected. The low value is determined by
the previous key in a sorted list of keys. For instance, if we
have a sorted list of keys like:

[.1, .3, .7, 1]

Then the individual whose key is .1 will be selected if a number
between 0 and .1 is chosen, the individual whose key is .3 will
be selected if the number is between .1 and .3, and so on.

The values of the dictionary are the organism instances.

Definition at line 86 of file RouletteWheel.py.

00086                                        :
        """Set up the roulette wheel based on the fitnesses.

        This creates a fitness proportional 'wheel' that will be used for
        selecting based on random numbers.

        Returns:
        
        o A dictionary where the keys are the 'high' value that an
        individual will be selected. The low value is determined by
        the previous key in a sorted list of keys. For instance, if we
        have a sorted list of keys like:

        [.1, .3, .7, 1]

        Then the individual whose key is .1 will be selected if a number
        between 0 and .1 is chosen, the individual whose key is .3 will
        be selected if the number is between .1 and .3, and so on.

        The values of the dictionary are the organism instances.
        """
        # first sum up the total fitness in the population
        total_fitness = 0
        for org in population:
            total_fitness += org.fitness

        # now create the wheel dictionary for all of the individuals
        wheel_dict = {}
        total_percentage = 0
        for org in population:
            org_percentage = float(org.fitness) / float(total_fitness)

            # the organisms chance of being picked goes from the previous
            # percentage (total_percentage) to the previous percentage
            # plus the organisms specific fitness percentage
            wheel_dict[total_percentage + org_percentage] = copy.copy(org)

            # keep a running total of where we are at in the percentages
            total_percentage += org_percentage

        return wheel_dict
        return wheel_dict


Generated by  Doxygen 1.6.0   Back to index