Download as pdf or txt
Download as pdf or txt
You are on page 1of 12

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.
Representation
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,
Initialization

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.
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,
The strings of binary digits are called chromosomes. The
space of chromosomes is called the genotype space. The
chromosomes in the genotype space are abstract
mathematical objects on which the genetic operators
work. The parameter space (real values) is called
phenotype space.

The gene is the basic unit of inheritance. Genes are


pieces of DNA, which is the material inside he cell
nucleus, that carry the genetic instructions for making
living organisms. The gene constitution is called the
genotype. The expression of the genotype is the
phenotype.
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.
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.

You might also like