Genetic Algorithms - PowerPoint PPT Presentation

1 / 44
About This Presentation
Title:

Genetic Algorithms

Description:

Here the number of times an individual is expected to reproduce is equal to ... from the population average and truncates arbitrarily at 0. The mapping from ... – PowerPoint PPT presentation

Number of Views:31
Avg rating:3.0/5.0
Slides: 45
Provided by: richard114
Category:

less

Transcript and Presenter's Notes

Title: Genetic Algorithms


1
Genetic Algorithms
  • A technique for those who do
  • not know how to solve the problem!

2
Selection Methods
  • Fitness-Proportionate Selection
  • Roulette Wheel
  • Stochastic Universal Sampling
  • Rank Selection
  • Tournament Selection
  • Steady-State Selection
  • Sigma Scaling
  • Elitism

3
Fitness Proportionate Selection(Roulette Wheel)
  • Used by Hollands original GA
  • Here the number of times an individual is
    expected to reproduce is equal to
  • individual_Fitness/AveFitness N Pi
  • Method
  • 1. Sum the total expected values of individuals
    in Pop. Call this sum T
  • 2. Repeat N times where N is the number of
    individuals in Pop.
  • Choose a random integer r between 0 and T
  • Loop through the individuals in the pop.,
    summing the expected values, until the sum is
    greater than or equal to r. The individual whose
    expected value puts the sum over r is the one
    selected.
  • Faults Selection in small populations is often
    far from the expected values.

4
Stochastic Universal
  • In order to generate individuals that better
    follow their expected values we can use
    Stochastic Universal Sampling (SAS)
  • Here we make one call to rand() and select N
    equally spaced individuals from the population
  • The Roulette Wheel method made N random calls to
    select N individuals
  • Start with a random number between 1 and 1/N

5
Sigma Scaling
  • Fitness proportionate selection suffers from
    premature convergence. More emphasis is on
    exploitation as apposed to exploration. Sigma
    Scaling addresses this problem.
  • This keeps the selection pressure relatively
    constant over a run.
  • ExpVal(i,t) 1 (fitness(i)-mean(t))/2SD(t)
  • If SD(t) ltgt0 otherwise ExpVal(i,t)1.0
  • This, for example, gives an individual whose
    fitness is one SD above the mean 1.5 offspring
    out of N.

6
Elitism
  • First used by Kenneth De Jong(1975)
  • Here the best individuals are carried over to the
    new population.
  • This often significantly improves the GAs
    performance.
  • In GAlib we set this with the command
  • ga.elitist(gaTrue)
  • The best individual is copied over.

7
Rank Selection
  • This scheme is designed to prevent to-quick
    convergence.
  • Here the rank of an individual is used, instead
    of its absolute fitness, in the selection
    process.
  • The probability of selection is
  • Pi (N-i1)/(12..N)
  • Select by generating the array of partial sums
    and displace into it.

8
Tournament Selection
  • Fitness proportionate methods require two passes
    through the population
  • Rank scaling requires sorting.
  • Here k (often two) individuals are chosen from a
    population. The best is selected and inserted
    into the population.
  • Do this N times

9
Steady-State Selection
  • This scheme is used when we would like the two
    populations to overlap.
  • Here a percentage of the old population is first
    copied to the new population.
  • The remainder of the population is then filled
    using crossover etc.
  • The fraction of the new individuals at each
    generation is called the generation gap

10
GAlibs Selection Scheme Constructors
  • GARankSelector
  • The rank selector picks the best member of the
    population every time.
  • GARouletteWheelSelector
  • This selection method picks an individual based
    on the magnitude of the fitness score relative to
    the rest of the population. The higher the score,
    the more likely an individual will be selected.
    Any individual has a probability p of being
    chosen where p is equal to the fitness of the
    individual divided by the sum of the fitnesses of
    each individual in the population.

11
More Selection Schemes
  • GATournamentSelector
  • The tournament selector uses the roulette wheel
    method to select two individuals then picks the
    one with the higher score. The tournament
    selector typically chooses higher valued
    individuals more often than the
    RouletteWheelSelector.
  • GADSSelector
  • The deterministic sampling selector (DS) uses a
    two-staged selection procedure. In the first
    stage, each individual's expected representation
    is calculated. A temporary population is filled
    using the individuals with the highest expected
    numbers. Any remaining positions are filled by
    first sorting the original individuals according
    to the decimal part of their expected
    representation, then selecting those highest in
    the list. The second stage of selection is
    uniform random selection from the temporary
    population.

12
More Selection Schemes
  • GASRSSelector
  • The stochastic remainder sampling selector (SRS)
    uses a two-staged selection procedure. In the
    first stage, each individual's expected
    representation is calculated. A temporary
    population is filled using the individuals with
    the highest expected numbers. Any fractional
    expected representations are used to give the
    individual more likelihood of filling a space.
    For example, an individual with e of 1.4 will
    have 1 position then a 40 chance of a second
    position. The second stage of selection is
    uniform random selection from the temporary
    population.
  • GAUniformSelector
  • The stochastic uniform sampling selector picks
    randomly from the population. Any individual in
    the population has a probability p of being
    chosen where p is equal to 1 divided by the
    population size.

13
GAlib Scaling Constructors
  • GANoScaling()
  • The fitness scores are identical to the objective
    scores. No scaling takes place.
  • GALinearScaling(float c gaDefLinearScalingMultip
    lier)
  • The fitness scores are derived from the objective
    scores using the linear scaling method described
    in Goldberg's book. You can specify the scaling
    coefficient. Negative objective scores are not
    allowed with this method. Objective scores are
    converted to fitness scores using the relation f
    a obj b where a and b are calculated based
    upon the objective scores of the individuals in
    the population as described in Goldberg's book.

f
aobjb
obj
14
More Scalings
  • GASigmaTruncationScaling(float c
    gaDefSigmaTruncationMultiplier)
  • Use this scaling method if your objective
    scores will be negative. It scales based on the
    variation from the population average and
    truncates arbitrarily at 0. The mapping from
    objective to fitness score for each individual is
    given by
  • f obj - (obj_ave - c obj_dev)
  • GAlib Usage
  • GASigmaTruncationScaling sigmaTruncation
    //Declare object
  • ga.scaling(sigmaTruncation)

15
More Scalings
  • GAPowerLawScaling(int k gaDefPowerScalingFactor)
  • Power law scaling maps objective scores to
    fitness scores using an exponential relationship
    defined as
  • f obj k
  • GASharing(GAGenomeComparator func 0, float
    cutoff gaDefSharingCutoff, float alpha 1)
  • This scaling method is used to do speciation.
    The fitness score is derived from its objective
    score by comparing the individual against the
    other individuals in the population. If there are
    other similar individuals then the fitness is
    derated. The distance function is used to specify
    how similar to each other two individuals are. A
    distance function must return a value of 0 or
    higher, where 0 means that the two individuals
    are identical (no diversity).

16
Crossover Schemes available for GA1DArrayGenomeltTgt
  • There are many crossover methods built into
    GAlib. Generally they are genome specific.
  • Single point crossover
  • Two point crossover
  • Uniform Crossover
  • EvenOdd Crossover
  • Partial Match Crossover
  • Order Crossover
  • CycleCrossover.

17
Two Point Crossover
  • Chromosome 1 1101100100110110
  • Chromosome 2 0101111000011110
  • Offspring 1 1101111000110110
  • Offspring 2 0101100100011110



18
Uniform Crossover
  • In this method each gene of the offspring is
    selected randomly from the corresponding genes of
    the parents.
  • One-point and two-point crossover produce two
    offspring, whilst uniform crossover produces only
    one.

19
Creating your own Crossover
  • You can write your own crossover that is specific
    to your genome. In your GA you announce to the
    genome that you have done this by using the
    following command
  • Genome.crossover(MyCrossover)
  • You then must write the code for MyCrossover.

20
GAlib Sexual Crossover
  • Sexual crossover takes four arguments two
    parents and two children. If one child is nil,
    the operator should be able to generate a single
    child. The genomes have already been allocated,
    so the crossover operator should simply modify
    the contents of the child genome as appropriate.
    The crossover function should return the number
    of crossovers that occurred.
  • Your crossover function should be able to operate
    on one or two children, so be sure to test the
    child pointers to see if the genetic algorithm is
    asking you to create one or two children.

21
Example Crossover
  • int MyCrossover(const GAGenome p1, const
    GAGenome p2,

  • GAGenome c1, GAGenome c2)
  • GA1DBinaryStringGenome mom(GA1DBinaryStringGenom
    e )p1
  • GA1DBinaryStringGenome dad(GA1DBinaryStringGenom
    e )p2
  • int n0
  • unsigned int site GARandomInt(0, mom.length())
  • unsigned int len mom.length() - site
  • if(c1)
  • GA1DBinaryStringGenome sis(GA1DBinaryStringG
    enome )c1
  • sis.copy(mom, 0, 0, site)
  • sis.copy(dad, site, site, len) n
  • if(c2)
  • GA1DBinaryStringGenome bro(GA1DBinaryStringG
    enome )c2
  • bro.copy(dad, 0, 0, site)
  • bro.copy(mom, site, site, len)
  • n
  • return n

22
Permutation Crossovers
  • Required for TSP
  • Required for Decoding messages etc
  • Random crossover of two permutations seldom
    result in another permutation
  • A permutation space is N! in size.
  • SO!

23
Categories of Perm. Crossovers
  • Disqualification
  • Just kill the bad chromosomes. Why is this bad?
  • Repairing
  • Invalid chromosomes are fixed.
  • Inventing Specialized Operators
  • Crossovers generate only legal permutations
  • Transformation
  • Transform permutation space into a vector space
    and cross in vector space.

24
Permutation Operators
  • Partially mapped crossover (PMX)
  • Order crossover (X)
  • Uniform order crossover
  • Edge recombination
  • There are many other that we will not discuss.

25
Partially Mapped Crossover(Goldbert Lingle,
1985)
  • Given two parents s and t, PMX randomly picks
    two crossover points. The child is constructed
    in the following way. Starting with a copy of s,
    the positions between the crossover points are,
    one by one, set to the values of t in these
    positions. This is performs by applying a swap to
    s. The swap is defined by the corresponding
    values in s and t within the selected region.

26
PMX example
No change
6
2
3
4
1
7
5
6
2
3
1
4
7
5
6
2
4
1
3
7
5
6
2
3
4
1
7
5
7
5
2
4
1
3
7
6
7
6
2
3
4
1
7
5
7
5
2
4
1
3
7
6
7
6
2
3
4
1
7
5
7
5
2
4
1
3
7
6
7
First offspring
6
2
3
4
1
7
5
7
6
2
4
1
3
7
5
7
For the second offspring just swap the
parents and apply the same operation
27
Order Crossover(Davis 1985)
  • This crossover first determines to crossover
    points. It then copies the segment between them
    from one of the parents into the child. The
    remaining alleles are copied into the child (l to
    r) in the order that they occur in the other
    parents.
  • Switching the roles of the parents will generate
    the other child.

28
Order Crossover Example
1
2
3
4
5
6
7
8
9
4
5
6
7
3
4
7
2
8
9
1
6
5
The remaining alleles are 1 2 3 8 9. Their
order in the other parent is 3 2 8 9 1
3
4
7
2
8
9
1
6
5
3
2
8
4
5
6
7
9
1
29
Uniform Order Crossover(Davis 1991)
  • Here a randomly-generated binary mask is used to
    define the elements to be taken from that parent.
  • The only difference between this and order
    crossover is that these elements in order
    crossover are contiguous.

1
2
3
4
5
6
7
8
9
1
1
0
1
0
0
0
1
0
1
2
3
4
7
9
6
8
5
offspring
3
4
7
2
8
9
1
6
5
30
Edge Recombination(Whitley Starkweather Fuquay
1989 )
  • This operator was specially designed for the TSP
    problem.
  • This scheme ensures that every edge (link) in the
    child was shared with one or other of its
    parents.
  • This has been shown to be very effective in TSP
    applications.
  • Constructs an edge map, which for each site lists
    the edges available to it from the two parents
    that involve that city. Mark edges that occur in
    both with a .

31
Example Edge Table
  • g d m h b j f i a k e c
  • c e k a g b h i j f m d
  • a k, g ,i g a, b, c, d b h,g,i
  • h b, i, m c 3, d, g i h, j, a, f
  • d m, g, c j f, i, b e k, c
  • k e, a f j, m, i m d, f, h

32
Edge Recombination Algorithm
  • Pick a city at random
  • Set current_city to this city.
  • Remove reference to current_city form table.
  • Examine list for current_city
  • If there is a common entry() pick that
  • Else pick entry which has the shortest list
  • Split ties randomly
  • If stuck (list is empty), start from other end,
    or else pick a new city at random.

33
Example Continued
  • Randomly pick a, delete all as from table a
  • Select k (common neighbor) ak
  • Select e (only item in ks list) ake
  • Select c (only item in es list) akec
  • d or g pick d at random akecd
  • Select m (common edge with d) akecdm
  • f or h pick h at random akecdmh
  • Select b ( common edge) akecdmhb
  • Select g (shortest list -0) akecdmhbg
  • g has empty list so reverse direction
    gbhmdcdka
  • Select i (only item in as list) gbhmdcdkai
  • Select f at random, then j gbhmdcekaifj

34
Inversion Transformations
  • This scheme will allow normal crossover and
    mutation to operate as usual.
  • In order to accomplish this we map the
    permutation space to a set of contiguous vectors
    .
  • Given a permutation of the set 1,2,3,,N let aj
    denote the number of integers in the permutation
    which precede j but are greater than j. The
    sequence a1,a2,a3,,an is called the inversion
    sequence of the permutation.
  • The inversion sequence of 6 2 3 4 1 7 6 is
  • 4 1 1 1 2 0 0

There are 4 integers greater than 1
35
Inversion of Permutations
  • The inversion sequence of a permutation is
    unique! Hence there is a 1-1 correspondence
    between permutations and their inversion
    sequence. Also the right most inv number is 0 so
    dropped.

y
1
1 2
2 1
1
0
1 2 3
1 3 2
3 1 2
3 2 1
2 3 1
2 1 3
x
0 1 2
(0 0) (0 1) (1 1) (2 1) (2
0) (1 0)
36
Inversions Continued
  • What does a 4 digit permutation map to?
  • 1234 -gt (0 0 0)
  • 2134 -gt (1 0 0)
  • 4321 -gt (3 2 1)
  • 2413 -gt (2 0 1)
  • 1423 -gt (0 1 1)
  • etc
  • Maps to a partial 3D lattice structure

37
Converting Perm to Inv
  • Input perm array of permutation
  • Output inv array holding inv sequence
  • For (i1iltNi)
  • invi0
  • m1
  • while(permmltgti)
  • if (permmgti )then invi
  • m

38
Convert inv to Perm
  • Input inv
  • Output perm
  • For(i1iltNi)
  • for(mi1mltNm)
  • if (posmgtinvi1)posm
  • posiomvi1
  • For(i1iltNi) permii

39
So what do we do?
  • Our population is of course a set of
    permutations.
  • These permutations are each mapped to their inv
    to create a population of invs say
  • We do normal crossovers in this mapped population
    as well as normal mutations.
  • In order to determine fitness we of course must
    apply Fitness(Inverse(inv))
  • Is this all worth doing?

40
Mutations of Permutations
  • Swap Mutation
  • Scramble Mutation
  • 2-Swap
  • Insert
  • These will maintain legal permutations

41
Swap Mutation
  • Select two positions at random and swap the
    allele values at those positions.
  • Sometimes called the order-based mutation.
  • ABCDEFGJ gt AECDBFGJ

42
Scramble Mutation
  • Pick a subset of positions at random and reorder
    their contents randomly
  • Some research has shown swap is best and others
    have shown scramble is best in certain apps. Who
    knows?
  • ABCDEFGH gt AHFDECGB

43
Other Permutation Mutations
  • 2-Swap (nice for TSP)
  • Pick two point and invert subtour
  • AB.CDEF.GH gt AB.FEDC.GH
  • Insert Mutation
  • Pick a value at random (say E), insert into
    another (rand chosen position, say B) and shift
    the rest over
  • ABCDEFG gt AEBCDFG

44
How about code breaking
  • Assume that we have the 26 letters of the
    alphabet permutated. This permutation is used to
    encode a normal message. How do we decode this
    using a GA?
  • Is this even a good idea?
  • What is the fitness function?
Write a Comment
User Comments (0)
About PowerShow.com