Você está na página 1de 15

Genetic Algorithms

1. Initialize the population.


2. Calculate fitness for each individual in the
population.
3. Reproduce selected individuals to form a new
population.
4. Perform crossover and mutation on the
population.
5. Loop to step 2 until some condition is met.

Genetic Algorithms in Search, Optimization,


and Machine Learning- David E. Goldberg,
A Simple GA Example Problem

To find the value of x that maximizes the function ƒ(x) =


sin (π x/256) over the range 0 ≤ x ≤ 255, where
values of x are restricted to integers.
Represent each individual in the population with an
eight-bit binary string.
00000000- 0
11111111- 255
Decide how many individuals will make up the
population (10 to 100s). This example, the
population consists of eight individuals.
The next step is to initialize the population. This is
usually done randomly. Use a random number
generator to assign a 1 or 0 to each of the eight
positions in each of the eight individuals,
Sum=5.083
Calculate the fitness. Then reproduction.
Reproduction consists of forming a new population with the same total
number of individuals by selecting from members of the current
population with a stochastic process that is weighted by each of their
fitness values. We spin the roulette wheel by generating eight
random numbers between 0 and 1. If a random number is between 0
and 0.144, the first individual in the existing population is selected
for the next population. If the number is between 0.144 and (0.144 +
0.093) = 0.237, the second individual is selected, and so on. Finally, if
the random number is between (1 . 0.128) = 0.872 and 1.0, the last
individual is selected.
Roulette Wheel Selection

Individual 1
Individual 2
Individual 3
Individual 4
Individual 5
Individual 6
Individual 7
Individual 8
The eight random numbers generated are 0.293, 0.971,
0.160, 0.469, 0.664, 0.568, 0.371, and 0.109. This results
in initial population member
numbers 3, 8, 2, 5, 6, 5, 3, and 1 being chosen to make
up the population after reproduction, as shown
The next operation is crossover. Crossover is the process of
exchanging portions of the strings of two “parent” individuals.
An overall probability is assigned to the crossover process,
which is the probability that, given two parents, the crossover
process will occur. This crossover rate is often in the range of
0.65 to 0.80; we select a value of 0.75 for the sample problem.

For each pair, a random number is generated to determine


whether crossover will occur. It is thereby determined that
three of the four pairs will undergo crossover.

Next, for the pairs undergoing crossover, two crossover points are
selected at random. The portions of the strings between the
first and second crossover points (moving from left to right in
the string) will be exchanged.
Sum=6.313
Mutation consists of flipping bits at random, generally with a
constant probability for each bit in the population.
The probability of mutation can vary widely according to the
application and the preference of the user. Values of between
0.001 and 0.01 are usual for the mutation probability. This
means that the bit at each site on the bit string is flipped, on
average, between 0.1 and 1.0 percent of the time.
One fixed value is used for each generation and often is maintained
for an entire run.
Since there are 64 bits in the example problem’s population it is
quite possible that none would be altered as a result of
mutation, so we will consider the Figure 4.4 as the “final”
population after one iteration of the GA procedure.
This is the first generation.
Stopping Criteria
• Fixing the number of generations is not a good method. We may miss the
‘missing the best generation’.
• Lack of progress in improving fitness of the best individual in the
population is also not a good criterion. This is because ‘evolution often
proceeds in punctuated equilibria, with sudden improvements after long
period in which fitness remains relatively unchanged’

• The best criteria is to check the algorithm has ‘converged’ or not, i.e,
whether many candidate solutions in the current population are so similar to
one another that no further progress is likely to occur in the next few
generations. This you can implement by examining the variance of the
population fitness.
Encoding from phenotype into a genotype
If a variable has a range from 2.5 to 6.5 (a dynamic range of
4) and it is desired to have a resolution of three decimal
places, the product of the dynamic range and the
resolution requires a string 12 bits long, where the string
of zeroes represents the value 2.5.
A major advantage of being able to represent variables in this
way is that the user can think of the population individuals
as real-valued vectors rather than as bit strings, thus
simplifying the development of GA applications.
Suppose the phenotype is in the interval [xmin,xmax].
If we decide to use l bits to represent a point x, then this
corresponds to mapping the interval [xmin,xmax] into the discrete
genotype space [0,2l-1] consisting of 2l consisting binary space.
l determines the size of the genotype space and hence the
accuracy.
The value of l that determine the desired resolution r is
xmax  xmin
r
2l  1
Consider two variables (x1,x2) as (10010111). Each variable is a
four bit string that can be represented by an integer between 0
and 15.
x1,int  1 23  0  2 2  0  21  1 20  9
X2,int=7.
Then we convert it x1,int from the range[0, 2l-1] into the range
[0, x1max-x1min] by multiplying x1,int by xmax  xmin
2l  1
To obtain the corresponding value of x1, we add x1,min
Mapping from the
xmax  xmin
x1  x1,min  x1,int phenotype space into
2l  1 genotype space
If the range is [10-20], then the string 1001 will become 16
20  10
x1  10  9  16
2 1
4
Suppose the precision required is 6 places after the decimal point. Let
the range is [-1,2], domain length=3. To get this precision the range
must be divided into atleast 3,000,000 equal sized intervals. This
means 22 bits are required to represent one vector

1000101110110101000111=2,288,967 2 21  2,097152
x=-1+2,288,967*(3/4,194,303)=0.637197 2 22  4,194,304
Precision required is one place after decimal point.
Range is [2 3].
Divide the range into 10 equal sized intervals.
4 bits are required.
0000 2
0001 2.0666
0010 2.1333 2+2*(3-2)/15=2.1333
0011
0100
0101

0110
0111 w1 w2 w3
1000 111001 101110 101010
1001
1010
1011
1100
1101
1110
1111 3
Vocabulary
• Gene – An single encoding of part of the
solution space.
• Chromosome – A string of “Genes” that
represents a solution.
• Population - The number of
“Chromosomes” available to test.

Você também pode gostar