46
Genetic Algorithms By: Jacob Noyes 4/16/2013

Genetic Algorithms

  • Upload
    stash

  • View
    36

  • Download
    0

Embed Size (px)

DESCRIPTION

Genetic Algorithms. By: Jacob Noyes 4/16/2013. Traveling Salesman Problem. Given: A list of cities Distances between each city Find: Shortest path to reach every city once. Traveling Salesman Problem. Brute force Exact Algorithms Pro: Will find the right answer Con: - PowerPoint PPT Presentation

Citation preview

Page 1: Genetic Algorithms

Genetic Algorithms

By: Jacob Noyes4/16/2013

Page 2: Genetic Algorithms

Traveling Salesman Problem

Given: A list of cities Distances between each city

Find: Shortest path to reach every city once

Page 3: Genetic Algorithms

Traveling Salesman Problem

Brute force Exact Algorithms

Pro: Will find the right answer

Con: Does not scale well

Page 4: Genetic Algorithms

Evolution

Change in inherited characteristics over timeNatural Selection:

A mechanism through which evolution happens Survival of the fittest Genes of the more suitable organisms get passed on more

oftenDeoxyribonucleic acid(DNA):

Genes encoded in amino acids Used to pass genes from parent to offspring

Page 5: Genetic Algorithms

Genetic Algorithms: The Basics

Genetic algorithms are specialized searchheuristics which use the fundamental principles of evolution through natural selection to find the best solution to a problem.

Page 6: Genetic Algorithms

Genetic Algorithms: The Basics

EncodingInitializationSelectionCrossoverMutation

Page 7: Genetic Algorithms

Encoding

Changeable representation of individual's traits is created

Completed only at the startIts “string” is designed a series of bitsConcatenate multiple parameters

Page 8: Genetic Algorithms

Examples: Max y-values?

Example 1: y = -x^2 + 255x

0 ≤ x ≤ 255

String: 00000000 ≤ x ≤ 11111111Example 2:

y = 2w + x + 3z

0 ≤ w ≤ 7, 0 ≤ x ≤ 7, 0 ≤ z ≤ 7 String: 000/000/000 – 111/111/111

Page 9: Genetic Algorithms

Initialization

Beginning population is created

Each bit(gene) is randomly generated to create variety

Performed only for the first generation and not repeated

Page 10: Genetic Algorithms

Example: Initialization

Given y = -x^2 + 255x 0 ≤ x ≤ 255

X Binary x188 1011110048 0011000075 01001011104 01101000249 1111100110 00001010134 10000110125 01111101

Page 11: Genetic Algorithms

Selection

Assign a fitness measure of how close a solution is to fulfilling the problem Assigned to each individual

Select individuals Individuals with higher fitness will reproduce more often Non-selected individuals will “die off”

Page 12: Genetic Algorithms

Example: Fitness

Given y = -x^2 + 255x 0 ≤ x ≤ 255

X Binary x Fitness188 10111100 1259648 00110000 9936 75 01001011 13500104 01101000 15704249 11111001 1494 10 00001010 2450 134 10000110 16214125 01111101 16250

Page 13: Genetic Algorithms

Optimums

Local optimum: A point where small changes will lead to worse results

Overall optimum: The best solution

Page 14: Genetic Algorithms

Selection: Categories

Proportionate Selection: Fitness relative to other individuals

Ranking Selection: Chance to reproduce based on order

Tournament Selection: Pits individuals against each other in smaller brackets

Gender Specific Selection: Splits Individuals into groups based on “sex”

Genetic Relatedness Based Selection: Individuals are selected based on their genetic distance from others in the population

Page 15: Genetic Algorithms

Selection: Proportionate Selection

Roulette wheel selectionDeterministic SamplingStochastic Remainder Sampling with ReplacementStochastic Remainder Sampling without ReplacementStochastic Universal Selection

Page 16: Genetic Algorithms

Roulette Wheel Selection

1. Find Pf: Population fitness = sum of all fitness factors2. Find Psel: Each individual's probability of selection

Psel = (fitness factor) / Pf3. Load each Psel into an array4. Generate random number between 0-1005. Start at beginning of array, subtract each Psel from number until number <= 0

Page 17: Genetic Algorithms

Deterministic Sampling

1. Average fitness is found2. Individual fitnesses are divided by the average3. Whole number results = number of spots in the mating pool4. Extra slots filled starting by highest decimal5. Random numbers generated to select individuals from the mating pool

Page 18: Genetic Algorithms

Stochastic Remainder with Replacement

Uses Deterministic Sampling to fill slots with whole number resultsLeft over slots are then filled using the remainders with the Roulette Wheel

Selection Method

Page 19: Genetic Algorithms

Stochastic Remainder without Replacement

Uses Deterministic Sampling to fill slots with whole number resultsUses a “weighted-coin toss” to determine the rest

1. Each remainder multiplied by 100 2. Random number between 0-100 generated 3. If random number <= remainder, accept 4. Loop until all spots are filled

Page 20: Genetic Algorithms

Ranking Selection

Chance to breed based on order of fitness, not proportionPro: Easy to implement and understandCon: Generally less accurate, less efficient, and

phase out diversity too quicklyDue to cons, not used oftenTypes:

Linear ranking selection Truncate Selection

Page 21: Genetic Algorithms

Linear Ranking Selection

1. Probabilities are set up for each rank before fitnesses are even assessed

2. Individuals are ordered based on fitness level

3. The predefined probabilities are assigned to their rank

4. Individuals are selected based on the probabilities

Page 22: Genetic Algorithms

Truncate Selection

1. Candidates are put in order based on fitness2. The top predefined percentage are chosen to reproduce

Page 23: Genetic Algorithms

Tournament Selection

Individuals are pitted against each other in smaller bracketsThe winner(s) of each bracket reproducesBracket participants only need to know fitness levels of others in bracket

No need for total or average population fitness factors Good for situations when it is impossible or implausible to

calculate totals

Page 24: Genetic Algorithms

Tournament Selection: Categories

Binary Tournament SelectionLarger Tournament SelectionBoltzmann Tournament SelectionCorrelative Tournament Selection

Page 25: Genetic Algorithms

Binary Tournament Selection

1. Two candidates are randomly selected out of possible solutions

2. Candidate with best fitness factor is chosen to reproduce

Page 26: Genetic Algorithms

Larger Tournament Selection

1. More than two candidates are randomly selected out of possible solutions

2. Candidate with best fitness factor is chosen to reproduce

Only difference from Binary Tournament Selection is number of candidates in each bracket

More candidates = higher selection pressure

Page 27: Genetic Algorithms

Boltzmann Tournament Selection

N = temperature = variable describing number of differences in bit string between two individuals

1. First candidate is chosen randomly2. Second candidate is chosen as having exactly n differences in gene

string from first candidate3. Third candidate is chosen

Half of the time has exactly n differences in gene string from first AND second candidate (strict choice)

Other half of the time has exactly n difference in gene string from ONLYfirst candidate (relaxed choice)

4. Choose the winner of the three to reproduce

Page 28: Genetic Algorithms

Correlative Tournament Selection

Not so much a separate selection method as much as an extension of othertournament selections

Once mating pool is selected, pairs are created based on how closely theyare related

Pairing similar individuals allows a better chance of passing on their (probably) good similar trait

Page 29: Genetic Algorithms

Gender Specific Selection

Genetic Algorithm with Chromosome Differentiation(GACD)Restricted MatingCorrelative Family-based Selection

Page 30: Genetic Algorithms

Genetic Algorithms with Chromosome Differentiation

Every individual has an extra 00 or 01 attached to their bit string 00 = female, 01 = male When a male and female mate each parent randomly selects a bit to pass

onto the child Females(00) can pass on 0 or 0 Males(01) can pass on 0 or 1

Hamming distance: the sum of the differences between each bit of two individuals Ex: 00011111 and 11111111 have a hamming distance of 3.

Page 31: Genetic Algorithms

Genetic Algorithm With Chromosome Differentiation

1. Males generated first randomly2. Females created for each male with maximum hamming distance3. Select individuals to put into mating pool by either:

Using a separate selection method for each sex Or, lumping them together and using one selection method over all of them

4. Mate each individual in the mating pool twice5. If there are fewer of one sex in the mating pool, mate leftovers with the

highest fitness individual of the opposite sex

Page 32: Genetic Algorithms

Restricted Mating

In nature, different species cannot or will not mateRestricted mating is based on species differentiationsCertain traits (predefined sections of the bit string) must be the same to

mate two candidatesKeeps several variations from converging to a local optimum

Page 33: Genetic Algorithms

Correlative Family-based Selection

1. Two candidates are mated together twice2. Between the two candidates and the two children, the most fit

solution is chosen3. The hamming distance is calculated for each individual compared

to the other three4. The individual with the highest hamming distance is also chosen

to reproduce

Page 34: Genetic Algorithms

Genetic Relatedness Based Selection

Purpose is to search unexplored areas of the search spaceGroups candidates based on similar fitness factorsDoes not try to find most fit candidatesIncludes:

Fitness Uniform Selection Scheme(FUSS) Reserve Selection

Page 35: Genetic Algorithms

Fitness Uniform Selection Scheme

Candidates with similar fitness factors are grouped togetherRandom numbers are generated from the range of minimum fitness to

maximum fitnessCandidates with fitnesses closest to the random number are selectedThis gives a higher probability of selecting unexplored areasHelps avoid local optimums

Page 36: Genetic Algorithms

Reserve Selection

Candidates split into two categories Non-reserved: Normal candidates with normal selection process applied Reserved: Specific less fit candidates that are carried over from generation

to generation to keep variety in the populationKeeps pool out of local maximums

Page 37: Genetic Algorithms

Elitism

Automatically carry over most fit individual to next generationExtension of other selection methodsMakes sure best fit does not just get unlucky

Page 38: Genetic Algorithms

Example: Selection

Given y = -x^2 + 255x 0 ≤ x ≤ 255 Top half truncate selection

Gene pool01111101100001100110100001001011

X Binary x Fitness188 10111100 12596 48 00110000 9936 75 01001011 13500 104 01101000 15704 249 11111001 1494 10 00001010 2450 134 10000110 16214 125 01111101 16250

Page 39: Genetic Algorithms

Crossover

Genes(bit strings) are combined from both parents to create offspringLocus: the randomly generated point(s) at which each parent's bit string

is separated

Page 40: Genetic Algorithms

Example: Crossover

Candidate Gene pool Locus1 01111101 32 10000110 1 3 01101000 1 4 01001011 6

Parents P1 String P2 String Offspring1, 2 011 00110 011001102, 1 100 11101 100111012, 3 1 1101000 111010003, 2 0 0000110 000001103, 4 0 1001011 010010114, 3 0 1101000 011010004, 1 010010 01 010010011, 4 011111 11 01111111

Page 41: Genetic Algorithms

Mutation in The Natural World

Brings diversity to a populationWithout mutation, just different combinations of the same traitsMutations happen when DNA is not copied properlyIf the mutation has a benefit, or is just not a hindrance, it may be passed

on to new generations

Page 42: Genetic Algorithms

Mutation in Genetic Algorithms

Purposely inject after crossover Rate of mutation is decided beforehand

Ex: 1/2000th chance of mutation per bitFor every bit in a population, a random number is generatedIf the probability hits, the bit is XOR'ed with 1

Page 43: Genetic Algorithms

Given mutation rate: 1/64

Example: Mutation

Pre-mutated XOR Offspring01100110 00000000 0110011010011101 00000000 1001110111101000 00000010 1110101000000110 00000000 0000011001001011 00000000 0100101101101000 00000000 0110100001001001 00000000 0100100101111111 00000000 01111111

Page 44: Genetic Algorithms

Genetic Algorithms: End

Fitness threshold based Each solution's fitness level is checked after each generation If a given minimum fitness level is achieved, the algorithm finishes

running and outputs the maximum fitness candidateGeneration threshold based

Genetic algorithm runs for a predefined number of generations Most fit solution over all generations is outputted

Page 45: Genetic Algorithms

Uses of Genetic Algorithms

Optimal water network layoutsFacial recognitionRoboticsTrajectories for spacecraftFun with walkingMuch More

Page 46: Genetic Algorithms

Questions?