Artificial Intelligence 101
Rajdeep Chatterjee, Ph.D.
Amygdala AI, Bhubaneswar, India *
January 2024
Genetic Algorithms
P
1 Introduction to Genetic Algorithms
EE
Genetic Algorithms (GAs) are search heuristics inspired by the process of natural selection. They are used to
solve optimization and search problems by evolving solutions over generations. The steps involved in a GA
are:
1. Initialization
JD
2. Selection
3. Crossover
A
4. Mutation
5. Termination
ER
2 Step-by-Step Process
2.1 Initialization
A population of candidate solutions (chromosomes) is generated randomly. Each solution is represented as a
CS
binary string.
Example: Consider a toy population for minimizing the function f (x) = x2 .
Chromosome Decimal Value (x) Fitness ( f (x) = x2 )
1010 10 100
0100 4 16
1110 14 196
0011 3 9
* Amygdala AI, is an international volunteer-run research group that advocates for AI for a better tomorrow [Link]
org/.
1
2
2.2 Selection
Select parents based on their fitness. A common method is roulette wheel selection, where solutions with
lower fitness are more likely to be chosen.
Example: Assign probabilities based on fitness:
Chromosome Fitness Probability Cumulative Probability
1010 100 0.32 0.32
0100 16 0.52 0.84
1110 196 0.11 0.95
0011 9 0.05 1.00
2.3 Crossover
Combine pairs of parents to create offspring. A single-point crossover is used, where a random point in the
chromosome is selected, and the genes are swapped beyond that point.
P
Example: Crossover between 1010 and 0100 at position 2:
Parent 1: 1010
EE
Parent 2: 0100
Offspring 1: 1000
Offspring 2: 0110
JD
2.4 Mutation
Introduce small random changes to maintain diversity and avoid premature convergence.
Example: Mutate a bit in 1000 (flip the 2nd bit):
A
Original: 1000
Mutated: 1100
ER
2.5 Termination
The algorithm terminates when a stopping criterion is met, such as a maximum number of generations or
convergence to an optimal solution.
CS
3 Visual Representation
4 Conclusion
The genetic algorithm evolves a solution by mimicking natural selection. Through repeated cycles of selec-
tion, crossover, and mutation, the algorithm converges to an optimal or near-optimal solution for the given
problem.
Copyright ©cserajdeep, 2024
3
Initialize Population
P
Evaluate Fitness
Select Parents
EE Check Termination
JD
Perform Crossover
A
ER
Apply Mutation
CS
New Population
Copyright ©cserajdeep, 2024