Download presentation
Presentation is loading. Please wait.
1
Genetic Algorithms
2
Idea 5: genetic algorithms
Start with a set of k states Rather than pick from these, create new states by combining states Maintain a “population” of states
3
Idea 5: genetic algorithms
Start with a set of k states Rather than pick from these, create new states by combining states Maintain a “population” of states Inspired by the biological evolution process Uses concepts of “Natural Selection” and “Genetic Inheritance” (Darwin 1859) Originally developed by John Holland (1975)
4
The Algorithm Randomly generate an initial population.
Repeat the following: Select parents based on fitness “reproduce” offspring/next generation Use crossover + mutation Evaluate the fitness of the new generation Discard old generation
5
Genetic Algorithm Crossover
Parent 1 Parent 2 Child 1 Child 2
6
Genetic Algorithm Mutation
Parent 1 Parent 2 Child 1 Mutation Child 2
7
A Simple Example Goal: Find the binary string 11010010
String can represent a solution to a problem
8
Step 0: Initialization Start with 5 random binary strings of target length
9
Step 1: Choose Parents (Apply Fitness Function)
Good measure of fitness? (Lower the better).
10
Step 1: Choose Parents (Apply Fitness Function)
Good measure of fitness? (Lower the better). Negation of: the sum of the differences of digits between string and target. Target: fitness( ) = – ( ) = –3
11
Step 1: Choose Parents (Apply Fitness Function)
The target: fitness( )= –3 fitness( )= –3 fitness( )= –5 fitness( )= –4 fitness( )= –2
12
Step 1: Choose Parents (based on fitness)
Choose a constant number of parents Higher the fitness, greater the probability of being chosen fitness( )= –3 fitness( )= –3 fitness( )= –5 fitness( )= –4 fitness( )= –2
13
Step 1: Parent Selection
Get pairs of parents: fitness( )= –3 fitness( )= –3 fitness( )= –5 fitness( )= –4 fitness( )= –2
14
Step 2: Reproduce Offspring (Crossover)
Randomly choose a crossover point (ex. 3) Perform crossover on all pairs of parents 010| |11011 101| |10011
15
Step 2: Reproduce Offspring (Mutation)
For each digit in the offspring string, with low probability (ex. .04), flip the bit) New offspring:
16
Step 3: Evaluate New Fitnesses
Target: f( ) = – 3 f( ) = – 2 f( ) = – 3 f( ) = – 3
17
Step 3: Evaluate New Fitnesses
Target: f( ) = – 3 f( ) = – 2 f( ) = – 3 f( ) = – 3 Previous generation: f( )= –3 f( )= –3 f( )= –5 f( )= –4 f( )= –2
18
Repeat Repeat for multiple “generations” until some stopping criterion
When target is “Hello World”, target achieved after 65 generations
19
Genetic Algorithm for 8-Queens?
20
Genetic Algorithm for 8-Queens?
Binary string of length 64
21
Genetic Algorithm for 8-Queens?
Binary string of length 64: … Each substring of length 8 is the row # of a queen
22
Genetic Algorithm for 8-Queens?
Binary string of length 64: … Each substring of length 8 is the row # of a queen We want the entire string to match a target (target = board with no attacking queens)
23
Genetic Algorithm for 8-Queens
fitness(state) = # of queens that can be attacked fitness(state) = 8 fitness(state) = 7
24
After Crossover fitness(state) = # of queens that can be attacked
25
Genetic Algorithm to solve TSP
Traveling Salesperson Problem: Given a list of cities, find the lowest-cost path that visits every city exactly once (and returns to the start) NP-hard
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.