g enetic a lgorithms steve foster. i ntroduction genetic algorithms are based on the principals of...
TRANSCRIPT
INTRODUCTION
Genetic Algorithms are based on the principals of evolutionary biology in order to find solutions to problems
In nature the evolution of species is a successful and robust method for ensuring that biological systems survive in their environment
It can be seen as a search problem, in which the survival of solutions is determined by a form of natural selection
HOW WE EVOLVE
Natural SelectionStrong members of a population survive to
reproduce, passing on their ‘strong’ traits
CrossoverSome from parent A, some from parent B
MutationA strange flipped gene that cannot be traced back to a parent
BIOLOGY TO GENETIC ALGORITHM
Gene = smallest atom of dataUsually binary, so 0 or 1
Genome = string of genes0111010010010101
Genome Pool = set of genomesRepresents our population
THE BASIC IDEA
Start with a completely random genome poolEach of these decomposes to a (potential)
solution to our problem
Gradually evolve our way to a solution.
FITNESS / STRENGTH HEURISTIC
Turns a binary string into a single floating point value based on how close to our desired result it isMaps back to how well an organism can
survive in an environment
0.0f = terrible1.0f = absolute solution
A BASIC GENETIC ALGORITHM
Start with a random genome pool of n members.
Run strength heuristic on each random genome in the pool.
‘Randomly’ crossbreed strong members of the population until you have n new genomes.
Introduce some mutation. Repeat until the strength heuristic
returns a value within our threshold.
REAL WORLD PROBLEMS
There are a number of different issues that need to be addressedRepresenting the problem
Assessing fitness
Determining selection
Modelling crossover and mutation
SELECTION
Determines the survival of the fittest
How can we determine the value of genetic material? Could be a good substring within an overall poor
solution
Therefore it may be worth saving some of the weaker solutions
SELECTION
Roulette Wheel Selection Fitness proportionate
Probabilistically select a number of members of the population to add crossbreed
SELECTION
Rank selectionCalculate the fitness of each
hypothesis
Arrange them in decreasing order of fitness
Pick the fittest n hypothesis for mating
SELECTION
Tournament SelectionTwo hypothesis are chosen at
random from the current populationThe fittest solution is selected for
survival and matingThe selection criteria yields a more
diverse gene pool than roulette wheel selection
CROSSOVER
Crossover is the process of mating in order to combine the genetic material of fit solutions
There are a number of different ways to combine two hypothesis, which lead to differences in future populations
The simplest method takes the two parents and creates two children by combining the two halves of each solution
MUTATION
Random mutation is a feature of conventional genetics where accidents of nature lead to random changes in the genetic makeup
In some cases these changes can be disastrous, in other cases they can be highly advantageous
In binary strings Can be modelled by randomly flipping a small
percentage of bits In other representations
Randomly change one element of a child solution a very small percentage of the time
PATHFINDING EXAMPLE (2)
Break down binary string into movements across a 2D grid.00 = up
01 = right
10 = down
11 = left
PATHFINDING EXAMPLE (3)
Heuristic function:Simulate binary string movement
beginning at start point
Measure distance from finish (simple, Pythagorean)
Fitness score = 1 – (distance / max possible distance)
PATHFINDING EXAMPLE (4)
start
Genome A: 01 10 01 10 01 00 01 00
01 = Right
10 = Down
01 = Right (Bump)
10 = Down
01 = Right
00 = Up (Bump)
01 = Right
00 = Up
Fitness = 1 - (2 / 24)
finish
PATHFINDING EXAMPLE (5)
start
Genome B: 00 01 10 10 11 10 01 01
00 = Up
01 = Right
10 = Down
10 = Down
11 = Left
10 = Down
01 = Right
01 = Right
Fitness = 1 – (2 / 24)
finish
PATHFINDING EXAMPLE (6)
Genome A: 01 10 01 10 01 00 01 00Genome B: 00 01 10 10 11 10 01 01
Genome C: 01 10 01 10 01 00 01 01
This is how we take two genomes and create a new one:
(assumes no mutation for now)
PATHFINDING EXAMPLE (7)
start
01 = Right
10 = Down
01 = Right (Bump)
10 = Down
01 = Right
00 = Up (Bump)
01 = Right
01 = Right
Fitness = 1 – (0 / 24)
finish
Genome C: 01 10 01 10 01 00 01 01
THINGS WE CAN TWEAK
Mutation rate0.01 is a reasonable starting value
Crossover rate0.7 or so
Chromosome length Varies a lot based on specific problem
Population sizeTry maybe 150-250
USE IN GAMES
Computationally expensive, becoming easier to deal with as hardware speeds up
Most of the time is run offline with the results used in a ‘black box’ fashion in the actual game
Can be used to tune priorities, behaviors, parameters, etc