Genetic Algorithms

bigskymanAI and Robotics

Oct 24, 2013 (3 years and 9 months ago)

115 views

G
ENETIC

A
LGORITHMS

Steve Foster

I
NTRODUCTION


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

H
OW

WE

EVOLVE


Natural Selection


Strong members of a population survive to
reproduce, passing on their ‘strong’ traits



Crossover


Some from parent A, some from parent B



Mutation


A strange flipped gene that cannot be traced
back to a parent


B
IOLOGY

TO

GENETIC

ALGORITHM


Gene = smallest atom of data


Usually binary, so 0 or 1



Genome = string of genes


0111010010010101



Genome Pool = set of genomes


Represents our population


T
HE

BASIC

I
DEA


Start with a completely random
genome pool


Each of these decomposes to a (potential)
solution to our problem



Gradually evolve our way to a
solution.

F
ITNESS

/ S
TRENGTH

H
EURISTIC


Turns a binary string into a single
floating point value based on how
close to our desired result it is


Maps back to how well an organism can
survive in an environment



0.0f = terrible


1.0f = absolute solution


A B
ASIC

G
ENETIC

A
LGORITHM


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.


R
EAL

W
ORLD

P
ROBLEMS


There are a number of different
issues that need to be addressed


Representing the problem



Assessing fitness



Determining selection



Modelling crossover and mutation

S
ELECTION


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


S
ELECTION


Roulette Wheel Selection


Fitness proportionate



Probabilistically select a number of members of the
population to add crossbreed



S
ELECTION


Rank selection


Calculate the fitness of each hypothesis



Arrange them in decreasing order of
fitness



Pick the fittest
n

hypothesis for mating

S
ELECTION


Tournament Selection


Two hypothesis are chosen at random
from the current population


The fittest solution is selected for
survival and mating


The selection criteria yields a more
diverse gene pool than roulette wheel
selection

C
ROSSOVER


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


S
IMPLE

C
ROSSOVER

Parents

Children

M
ULTIPLE

P
OINT

C
ROSSOVER

Parents

Children

M
UTATION


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

P
ATHFINDING

E
XAMPLE

(1)


Example:


2D grid



Arbitrary number of boundaries



1 start point



1 finish point


P
ATHFINDING

E
XAMPLE

(2)


Break down binary string into
movements across a 2D grid.


00 = up



01 = right



10 = down



11 = left

P
ATHFINDING

E
XAMPLE

(3)


Heuristic function:


Simulate binary string movement
beginning at start point



Measure distance from finish (simple,
Pythagorean)



Fitness score = 1


(distance / max
possible distance)


P
ATHFINDING

E
XAMPLE

(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

P
ATHFINDING

E
XAMPLE

(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

P
ATHFINDING

E
XAMPLE

(6)

Genome A: 01 10 01 10 01 00 01 00

Genome 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)

P
ATHFINDING

E
XAMPLE

(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

T
HINGS

WE

CAN

T
WEAK


Mutation rate


0.01 is a reasonable starting value


Crossover rate


0.7 or so


Chromosome length


V
aries a lot based on specific problem


Population size


Try maybe 150
-
250


U
SE

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


E
XAMPLES


Some games run it in real time


Black and White



Quake 3 bot AI


Used to optimize the fuzzy logic controller AI


I am:


45% in favor of grabbing that rocket launcher


62% in favor of picking up the red armor


89% in favor of the Quad Damage


Check out the source code (GPL)