sass ga talk - slac · sass talk, may 4, 2011 patricia voll 1. what is a genetic algorithm?...

18
Genetic Algorithms SASS Talk, May 4, 2011 Patricia Voll 1

Upload: others

Post on 17-Oct-2020

2 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: SASS GA Talk - SLAC · SASS Talk, May 4, 2011 Patricia Voll 1. What is a Genetic Algorithm? Solution! Generate Random Population Evaluate Fitness ... •Gray Decoding vs. Standard

Genetic Algorithms SASS Talk, May 4, 2011

Patricia Voll

1

Page 2: SASS GA Talk - SLAC · SASS Talk, May 4, 2011 Patricia Voll 1. What is a Genetic Algorithm? Solution! Generate Random Population Evaluate Fitness ... •Gray Decoding vs. Standard

What is a Genetic Algorithm?

Solution!

Generate Random

Population

Evaluate Fitness

Generate New

Population:

Select Parents

Crossover

MutationReplace Old Population

Test for End Condition

Start

2

Page 3: SASS GA Talk - SLAC · SASS Talk, May 4, 2011 Patricia Voll 1. What is a Genetic Algorithm? Solution! Generate Random Population Evaluate Fitness ... •Gray Decoding vs. Standard

Outline• What are the

genes?

• Defining a Population

• Fitness

• Selection

• Mixing/Crossover

• Mutation

• Carry-Over

• End Condition

3

Page 4: SASS GA Talk - SLAC · SASS Talk, May 4, 2011 Patricia Voll 1. What is a Genetic Algorithm? Solution! Generate Random Population Evaluate Fitness ... •Gray Decoding vs. Standard

Simple Example• Problem: On a surface with hills and valleys, where

is the highest point?

�5

0

5

�5

0

5

�200

�100

0

100

4

Page 5: SASS GA Talk - SLAC · SASS Talk, May 4, 2011 Patricia Voll 1. What is a Genetic Algorithm? Solution! Generate Random Population Evaluate Fitness ... •Gray Decoding vs. Standard

Variables as Genetic Code

• An “individual” is a set of variables that form a possible solution to the problem.

• Ex: a set of x and y coordinates

Ex: (x, y) = (1, 3)

5

Page 6: SASS GA Talk - SLAC · SASS Talk, May 4, 2011 Patricia Voll 1. What is a Genetic Algorithm? Solution! Generate Random Population Evaluate Fitness ... •Gray Decoding vs. Standard

Variable “Genes”: Binary

• Gray Decoding vs. Standard Binary

• Set Minimum and Maximum

# - Binary0 - 0000001 - 0000012 - 0000103 - 0000114 - 000100

..........7 - 0001118 - 001000

..........15 - 00111116 - 010000

Ex: (x, y) = (1, 3)→ (001, 011)

6

Page 7: SASS GA Talk - SLAC · SASS Talk, May 4, 2011 Patricia Voll 1. What is a Genetic Algorithm? Solution! Generate Random Population Evaluate Fitness ... •Gray Decoding vs. Standard

Populations• A set of individuals• Populations need to be large enough to have

variety, but small enough to allow fast evaluation • Ex: a set of (x, y) coordinates

0.986674 −0.2285873.87339 −1.65946.41143 −2.60451−2.89927 −3.37351−6.58189 0.271406−3.25734 −5.20694−0.490348 2.43147−0.0859103 4.88067

5.45403 5.04831−3.5718 −1.16343

x y

7

Page 8: SASS GA Talk - SLAC · SASS Talk, May 4, 2011 Patricia Voll 1. What is a Genetic Algorithm? Solution! Generate Random Population Evaluate Fitness ... •Gray Decoding vs. Standard

Generating a Population• Start with random population covering solution

space

• Each generation is mixed to form next generation

8

Page 9: SASS GA Talk - SLAC · SASS Talk, May 4, 2011 Patricia Voll 1. What is a Genetic Algorithm? Solution! Generate Random Population Evaluate Fitness ... •Gray Decoding vs. Standard

Fitness• GAs require a way to evaluate the fitness

of each individual in order to determine the best solutions so far and to recognize when end conditions are met

• Ex: the height of the surface at the (x, y) locationFor (x, y) = (1, 3)z = −(x− 1)2 − (y − 4)2 + 200J2(y) sinx

= −(1− 1)2 − (3− 4)2 + 200J2(y) sin(1)= 80.8063

9

Page 10: SASS GA Talk - SLAC · SASS Talk, May 4, 2011 Patricia Voll 1. What is a Genetic Algorithm? Solution! Generate Random Population Evaluate Fitness ... •Gray Decoding vs. Standard

Selection• How to pick the parents of the next generation?

• Want to pick the more fit individuals to be parents to get the best solutions

• But, don’t want to constrain solution space too early

• Ex: Tournament Selection

(x,y, z) combatants →tournament →new parent(1, 3, 80.8063) vs. (2,−2, 27.1662) →80.8063 > 27.1662 →(1, 3, 80.8063) winner!(4, 5,−17.0481) vs. (−4,−5,−98.9519) →− 17.0481 > −98.9519 →(4, 5,−17.0481) winner!

10

Page 11: SASS GA Talk - SLAC · SASS Talk, May 4, 2011 Patricia Voll 1. What is a Genetic Algorithm? Solution! Generate Random Population Evaluate Fitness ... •Gray Decoding vs. Standard

Mixing/Crossover• In binary, pick cut points (randomly?) at which to cut and then

splice the binary genes together

• with variables that are not in binary, choose a new splice method:• pick a number between the two parent variables (randomly?)• include a weighting toward the parent variable with greater

fitness• include possibility of child variable outside the bounds of

parent variables

Ex: Parents: (10101010) and (01010101)One Cut Point: (10110101) and (01001010)Multiple Cuts: (11011001) and (00100110)

(x,y, z) parents →(x,y, z) children(1, 3, 80.8063) (1.5, 4, 72.3932)(4, 5,−17.0481) (2, 3.5, 82.1561)

11

Page 12: SASS GA Talk - SLAC · SASS Talk, May 4, 2011 Patricia Voll 1. What is a Genetic Algorithm? Solution! Generate Random Population Evaluate Fitness ... •Gray Decoding vs. Standard

Mutation• In binary: flip a digit

• set probability for mutation of an individual

• set probability for flip of each digit

• Ex:

• No binary: add or subtract a certain amount

• set probability of mutation

• set the bounds for the mutation

• how to determine the mutation amount? Random number? Weighting?

• Ex:

00010000001001

(1.5, 4, 72.3932)→ (1.7, 4, 71.7286)

12

Page 13: SASS GA Talk - SLAC · SASS Talk, May 4, 2011 Patricia Voll 1. What is a Genetic Algorithm? Solution! Generate Random Population Evaluate Fitness ... •Gray Decoding vs. Standard

Carry-over• You don’t want to lose your best individual!

• If the best fitness of the new population is less than the best fitness of the old population, carry over the old best

• How many to carry over?

13

Page 14: SASS GA Talk - SLAC · SASS Talk, May 4, 2011 Patricia Voll 1. What is a Genetic Algorithm? Solution! Generate Random Population Evaluate Fitness ... •Gray Decoding vs. Standard

End Condition• What is your fitness goal?

• How many generations?

• Convergence?

�5

0

5

�5

0

5

�200

�100

0

100

14

Page 15: SASS GA Talk - SLAC · SASS Talk, May 4, 2011 Patricia Voll 1. What is a Genetic Algorithm? Solution! Generate Random Population Evaluate Fitness ... •Gray Decoding vs. Standard

Convergence

15

Page 16: SASS GA Talk - SLAC · SASS Talk, May 4, 2011 Patricia Voll 1. What is a Genetic Algorithm? Solution! Generate Random Population Evaluate Fitness ... •Gray Decoding vs. Standard

Possible Issues• Local Maxima

• to avoid, don’t converge too quickly

• Repeated fitness evaluation can take a lot of computing power

• Tweaking required to get the parameters right for each individual problem

�5

0

5

�5

0

5

�200

�100

0

100

16

Page 17: SASS GA Talk - SLAC · SASS Talk, May 4, 2011 Patricia Voll 1. What is a Genetic Algorithm? Solution! Generate Random Population Evaluate Fitness ... •Gray Decoding vs. Standard

Advantages

• Adaptability to complex problems

• Can change parameters as the population evolves

• Helpful when there is a huge parameter space

17

Page 18: SASS GA Talk - SLAC · SASS Talk, May 4, 2011 Patricia Voll 1. What is a Genetic Algorithm? Solution! Generate Random Population Evaluate Fitness ... •Gray Decoding vs. Standard

Discussion Problem

http://xkcd.com/720/

18