Unit - 5
Unit - 5
Genetic Algorithms
Genetic Algorithms (GAs) are optimization techniques inspired by the
process of natural selection. They are used to solve complex problems by
evolving a population of candidate solutions over multiple generations. A
key aspect of GAs is how hypotheses (candidate solutions) are
represented.
Representing Hypotheses
a) Binary Representation
Each hypothesis is represented as a binary string (0s and 1s).
Each bit in the string is called a gene.
Example: A hypothesis for a 4-bit binary string could be 1010.
Real-Time Example:
Knapsack Problem:
o You have a knapsack with a limited capacity and a set of items
with specific weights and values.
o Each hypothesis represents a selection of items (1 = included,
0 = not included).
o Example: 1010 means items 1 and 3 are included, while items
2 and 4 are not.
b) Integer Representation
Each hypothesis is represented as a string of integers.
Useful for problems where the solution involves discrete values.
Example: A hypothesis for a 3-integer string could be [5, 2, 7].
Steps in Genetic Algorithms
1. Initialization:
o Create an initial population of random hypotheses
(chromosomes).
2. Evaluation:
o Evaluate the fitness of each hypothesis using a fitness
function.
3. Selection:
o Select the best-performing hypotheses for reproduction.
4. Crossover:
o Combine pairs of hypotheses to create offspring.
5. Mutation:
o Randomly modify some genes in the offspring.
6. Replacement:
o Replace the old population with the new population.
7. Termination:
o Repeat the process until a stopping condition is met (e.g.,
maximum generations or satisfactory fitness).
Genetic Operators
In genetic algorithms (GAs), the fitness function and selection are two
critical components that guide the evolution of the population toward
better solutions
1. Fitness Function
Selection