GEAIO_lab3

Embed Size (px)

Citation preview

  • 8/13/2019 GEAIO_lab3

    1/51

    GEAIO16/04/12

    Slide 1

    Gesti Aeroporturia i del Espai Aeri

    iInvestigaci Operativa

    Genetic Algorithm Genetic Algorithm ToolBox

    University of Sheffield

    05/11/2012

  • 8/13/2019 GEAIO_lab3

    2/51

    GEAIO16/04/12

    Slide 2

    Genetic Algorithm

    Introduction

    Basic algorithm

    Population representation and initialization Objective and fitness functions

    Selection

    Crossover

    Mutation

    Reinsertion

    Termination of the GA

    Data structures

    Multiple population

    Simple GA

    Multi-population GA

    Problem

    [Chipperfield, 1994]

  • 8/13/2019 GEAIO_lab3

    3/51

    GEAIO16/04/12

    Slide 3

    Introduction

    [Weise, 2009]

  • 8/13/2019 GEAIO_lab3

    4/51

    GEAIO16/04/12

    Slide 4

    Chromosomes

    Genotypes chromosome values

    Phenotype meaning of the genotype

    Different codification possibilities:

    Real values

    Binary representation

    Introduction

    0 0 1 1 0 1 0 0 1 0 0

    x1 x2

    Different length might imply

    different precision

    Once decoded it is possible to assess performance fitness (Objective function)

  • 8/13/2019 GEAIO_lab3

    5/51

    GEAIO16/04/12

    Slide 5

    Reproduction phase

    Probability of being chosen in function fitness

    Reproduction uses genes

    Simplest combination: One point crossover. Done with a probability (Px)

    Introduction

    X1a X2a X3a X4a X5a X1n X2n X3n X4n X5nSa Sn

    One point crossover

    X1n X2n X3n X4a X5a

  • 8/13/2019 GEAIO_lab3

    6/51

    GEAIO16/04/12

    Slide 6

    Reproduction phase

    Probability of being chosen in function fitness

    Reproduction uses genes

    Simplest combination: One point cross-over. Done with a probability (Px)

    Mutation applied with a probability to ensure search in all the search space.

    Introduction

    Mutation

    X1b X2b X3b X4b X5bSb

    X1b X2b X3b X4b X5b

  • 8/13/2019 GEAIO_lab3

    7/51

    GEAIO16/04/12

    Slide 7

    Some differences with other optimization algorithms

    Search with a population not with a single point

    Dont require derivate information. Only objective function and fitness levels

    Probabilistic behavior, not deterministic

    Works with encoded parameters not with the parameters themselves

    Ends with a set of solutions. If Pareto might find all of them

    Introduction

  • 8/13/2019 GEAIO_lab3

    8/51

    GEAIO16/04/12

    Slide 8

    Basic Algorithm

    Begin

    t=0;

    initialize P(t);

    evaluate P(t);

    while not finished do

    begin

    t=t+1;

    select P(t) from P(t-1);

    reproduce pairs in P(t);

    evaluate P(t);

    end

    end

  • 8/13/2019 GEAIO_lab3

    9/51

    GEAIO16/04/12

    Slide 9

    Population representation and init ialization

    Population representation

  • 8/13/2019 GEAIO_lab3

    10/51

    GEAIO16/04/12

    Slide 10

    Population representation and init ialization

    Usually population between 30 and 100 individuals

    Most common representation binary string

    Other representations:

    Gray coding instead of binary coding

    Logarithmic coding

    Real-value coding

    Population representation

    Binary, Integer and floating point chromosome representationGA

    toolbox

    Dec Gray Binary0 000 000

    1 001 001

    2 011 010

    3 010 011

    4 110 100

    5 111 101

    6 101 1107 100 111

  • 8/13/2019 GEAIO_lab3

    11/51

    GEAIO16/04/12

    Slide 11

    Population representation and init ialization

    Initialization

  • 8/13/2019 GEAIO_lab3

    12/51

    GEAIO16/04/12

    Slide 12

    Population representation and init ialization

    Random

    Using problem information to maximize the search space used and avoid local minima

    Initialization

    crtbpcreate binary population

    ctrbasebuilds a vector describing integer representation used

    crtrpinitialize real-value population

    bs2rvconversion between binary string and real values. Support Gray and logarithmic

    scale codification.

    GA

    toolbox

  • 8/13/2019 GEAIO_lab3

    13/51

    GEAIO16/04/12

    Slide 13

    Objective and fitness functions

    Objective function

  • 8/13/2019 GEAIO_lab3

    14/51

    GEAIO

    16/04/12

    Slide 14

    Objective and fitness functions

    Used to provide a measure of how individuals have performed in the problem domain.

    In a minimization problem the most fit the individual the lowest value of the objective

    function

    Used as an intermediate stage in determining the relative performance of individuals in

    GA

    Objective function

    Must be created by the user. Example functions starts with objGA

    toolbox

  • 8/13/2019 GEAIO_lab3

    15/51

    GEAIO

    16/04/12

    Slide 15

    Objective and fitness functions

    Fitness function

  • 8/13/2019 GEAIO_lab3

    16/51

    GEAIO

    16/04/12

    Slide 16

    Objective and fitness functions

    Used to transform the objective function value into a measure of relative fitness

    Fitness function

    f: objective function

    g: transform the objective function in non-negative value

    F: the result of the fitness

    This mapping is always needed when minimizing as minimal objective value implies

    maximum fitness value

    The probability of having offspring is generally proportional to the fitness value.

    Therefore F(x) can be computed relative to the whole population:

    Nind: the population size

    xi: the phenotypic value of individual i

    Ensure all probability reproducing but problem with negative values scaling

    O f f

  • 8/13/2019 GEAIO_lab3

    17/51

    GEAIO

    16/04/12

    Slide 17

    Objective and fitness functions

    Linear transformation prior to fitting to ensure non-negative value and

    minimization/maximization

    Fitness function

    a: positive scaling factor if maximizing, negative value if

    minimizing

    b: ensure non-negative value

    Problem with rapid convergence. Best individuals too good

    Obj ti d fit f ti

  • 8/13/2019 GEAIO_lab3

    18/51

    GEAIO

    16/04/12

    Slide 18

    Objective and fitness functions

    Fitness function

    Option to avoid rapid convergence: Limit the reproduce range of individuals. Fitting

    according to rank in population instead of just performance. MAX used to determine

    selective pressure

    MIN = 2.0 MAX

    INC = 2.0 x (MAX-1.0)/Nind

    LOW = INC/2.0

    MIN is the lower bound, INC is the difference between fitness of adjacent individuals,

    LOW is expected number of times selected. MAX between [1.1, 2.0].

    Obj ti d fit f ti

  • 8/13/2019 GEAIO_lab3

    19/51

    GEAIO

    16/04/12

    Slide 19

    Objective and fitness functions

    Fitness function

    ranking supports linear and non-linear ranking methods

    scaling a simple linear scaling function. Linear scaling is not suitable for use with objective

    functions that return negative values.

    GAtoolbox

    S l ti

  • 8/13/2019 GEAIO_lab3

    20/51

    GEAIO

    16/04/12

    Slide 20

    Selection

    Selection

    S l ti

  • 8/13/2019 GEAIO_lab3

    21/51

    GEAIO

    16/04/12

    Slide 21

    Selection

    Process to determine the number of times, trials, a particular individual is chosen for

    reproduction.

    It is done in two different processes:

    1. Determination of the number of trials an individual can expect to receive

    2. Conversion of the expected number of trials into a discrete number of offspring

    The first part consist on the transformation of the fitness into a probability to reproduce.

    The second part is the probabilistic selection of individuals based on the fitness of

    individuals relative to one another: sampling

    Selection

    S l ti

  • 8/13/2019 GEAIO_lab3

    22/51

    GEAIO

    16/04/12

    Slide 22

    Selection

    Create an interval between [0,Sum] where Sum is determined by the fitness of the

    individuals.

    The size of each individual interval correspond to the fitness value associated to each

    individual.

    To select an individual, a random number is generated in the interval [0,Sum]

    Roulette wheel selection methods

    S l ti

  • 8/13/2019 GEAIO_lab3

    23/51

    GEAIO

    16/04/12

    Slide 23

    Selection

    Stochastic Sampling with Replacement (SSR): Segment size and selection probability

    remains the same during the selection. Any individual with segment size > 0 could fill

    the next population.

    Stochastic Sampling with Partial Replacement (SSPR): resize individuals segment

    when selected by reducing it by 1.0.

    Remainder Stochastic Sampling with Replacement (RSSR): Select deterministically by

    their expected trials and then the remaining use a SSR.

    Roulette wheel selection methods

    Selection

  • 8/13/2019 GEAIO_lab3

    24/51

    GEAIO

    16/04/12

    Slide 24

    Selection

    Stochastic Universal Sampling (SUS): single-phase sampling algorithm. Generate N

    pointers on the population by dividing Sum/N then shuffle the individuals and randomly

    select a points. Select the individuals pointed by the pointers spaced by 1.

    Stochastic Universal Sampling

    4 2 3 7 1 5 8 6

    Selection

  • 8/13/2019 GEAIO_lab3

    25/51

    GEAIO

    16/04/12

    Slide 25

    Selection

    rws Stochastic Sampling with Replacement algorithm

    sus Stochastic Universal Sampling function

    GA

    toolbox

    Crossover

  • 8/13/2019 GEAIO_lab3

    26/51

    GEAIO

    16/04/12

    Slide 26

    Crossover

    Crossover

  • 8/13/2019 GEAIO_lab3

    27/51

    GEAIO

    16/04/12

    Slide 27

    Crossover

    Single-point Crossover

    X1a X2a X3a X4a X5a X1n X2n X3n X4n X5nSa Sn

    One point crossover

    X1n X2n X3n X4a X5a

    Crossover

  • 8/13/2019 GEAIO_lab3

    28/51

    GEAIO

    16/04/12

    Slide 28

    Crossover

    Parts of the chromosome representation that contribute to the most to the performance

    of an individual might not be adjacent substrings

    Multi-point Crossover

    Crossover

  • 8/13/2019 GEAIO_lab3

    29/51

    GEAIO

    16/04/12

    Slide 29

    Crossover

    Randomly create a mask to do the cross over

    Allow the crossing of any loci

    Uniform Crossover

    Crossover

  • 8/13/2019 GEAIO_lab3

    30/51

    GEAIO

    16/04/12

    Slide 30

    Crossover

    A single cross-point is selected, but before exchanging the bits they are randomly

    shuffled in both parents. The bits are unshuffled after the recombination.

    Shuffle

    Ensure always produce new individuals.

    Reduced surrogate

    Crossover

  • 8/13/2019 GEAIO_lab3

    31/51

    GEAIO

    16/04/12

    Slide 31

    Crossover

    With a real-valued encoding of the chromosome generate offspring with the rule:

    Intermediate recombination

    Each variable in the offspring is the results of combining the variables in the parents

    with a new

    for each pair of genes.

    : scaling factor chosen randomly at an interval i.e. [-0.25,

    1.25]

    P1, P2: parent chromosomes

    Crossover

  • 8/13/2019 GEAIO_lab3

    32/51

    GEAIO

    16/04/12Slide 32

    Crossover

    Intermediate recombination

    10 8 7 10 4 6

    4 3 9 11 3 8

    P1

    P2

    0.01 0.2 1.1 -0.1 0.8 0.75 randomly from

    [-0.25,1.25]

    -6 -5 2 1 -1 2P2-P1

    -0,06 -1 2,2 -0,1 -0,8 1,5(P2-P1)

    -0,6 -8 15,4 -1 -3,2 9O=P1 x (P2-P1)

    Crossover

  • 8/13/2019 GEAIO_lab3

    33/51

    GEAIO

    16/04/12Slide 33

    Crossover

    Similar to Intermediate Recombination but just an used in the recombination.

    Line Recombination

    Crossover

  • 8/13/2019 GEAIO_lab3

    34/51

    GEAIO

    16/04/12Slide 34

    Crossover

    xovsp single-point crossover. Can operate on any chromosome representation.

    xovdp double-point crossover. Can operate on any chromosome representation. xovsh shuffle crossover. Can operate on any chromosome representation.

    xovsprs reduced surrogate crossover with single-point crossover.

    xovdprs reduced surrogate crossover with double-point crossover.

    xovshrs reduced surrogate crossover with shuffle crossover.

    xovmp general multi-point crossover routine.

    recdis discrete recombination, crossover on real-valued individuals similar to crossover

    operators.

    reclin line recombination for real-valued individuals.

    recint intermediate recombination for real-valued individuals.

    recombinhigh-level entry function to all of the crossover operators.

    GA

    toolbox

    Mutation

  • 8/13/2019 GEAIO_lab3

    35/51

    GEAIO

    16/04/12Slide 35

    Mutation

    Mutation

  • 8/13/2019 GEAIO_lab3

    36/51

    GEAIO

    16/04/12Slide 36

    Mutation

    Usually applied with a low probability (between 0.001 and 0.01)

    Guarantee that all the search space is potentially searched

    In non-binary representations, mutation can be achieved by perturbing the gene values

    Options to mutate more low fitted individuals or mutate with higher probability weak

    genes in an individual

    mut binary mutation.

    mutbga real-valued mutation.

    mutatehigh-level entry function mutation operators.

    GA

    toolbox

    Reinsertion

  • 8/13/2019 GEAIO_lab3

    37/51

    GEAIO

    16/04/12Slide 37

    Reinsertion

    Reinsertion

  • 8/13/2019 GEAIO_lab3

    38/51

    GEAIO

    16/04/12Slide 38

    Reinsertion

    The population should be kept with the same number after each iteration

    Generation gap = How extra individuals are created in each iteration

    New individuals have to be reinserted in old population

    Randomly

    Always pass the best fitted (elitist strategy)

    Remove the oldest

    reinsdo the reinsertion into population. Parameters allow to use uniform random or fitness-based reinsertion. Can be used to reinsert fewer offspring than generated after

    recombination.

    GA

    toolbox

    Termination of the GA

  • 8/13/2019 GEAIO_lab3

    39/51

    GEAIO

    16/04/12Slide 39

    Termination of the GA

    Termination of the GA

  • 8/13/2019 GEAIO_lab3

    40/51

    GEAIO

    16/04/12Slide 40

    Termination of the GA

    As GA is a stochastic search method, it is difficult to specify convergence criteria.

    Terminate the GA after a number of generations

    If best individual not very good reinitialize the algorithm and restart.

    When genes are similar then stop

    Data structures

  • 8/13/2019 GEAIO_lab3

    41/51

    GEAIO

    16/04/12Slide 41

    Data structures

    Data to be represented:

    Chromosomes

    Phenotypes

    Objective function values

    Fitness values

    Data structures

  • 8/13/2019 GEAIO_lab3

    42/51

    GEAIO

    16/04/12Slide 42

    Data structures

    GA

    toolbox

    Chromosomes data structure stores a whole population in a matrix Nind x Lind

    Nind number of individuals

    Lind length of the genotypic representation of the individuals

    Each row corresponds to an individuals genotype, of base-n, typically binary

    Chromosomes

    Only restriction: all chromosomes are of the same length.

    Need a suitable decoding function to transform chromosomes to phenotypes.

    Data structures

  • 8/13/2019 GEAIO_lab3

    43/51

    GEAIO

    16/04/12Slide 43

    GA

    toolbox

    The decision variables, phenotype, is obtained by applying a mapping between a

    chromosome into the variable space.

    Each chromosome decodes into a row vector of order Nvar

    The decision variables are stored in a numerical matrix of size Nind x Nvar

    Phenotypes

    The mapping between chromosome and phenotype depends on the DECODE function

    implemented.

    Data structures

  • 8/13/2019 GEAIO_lab3

    44/51

    GEAIO

    16/04/12Slide 44

    GA

    toolbox

    The objective function is used to evaluate the phenotypes in the problem domain.

    Objective functions can be scalar or vectorial

    Objective values are not necessarily the same as the fitness values

    Objectives values are stored in a numerical matrix of size Nind x Nobj, where Nobj is

    the number of objectives.

    Objective funct ion values

    OBJFUN is an arbitrary objective function.

    Data structures

  • 8/13/2019 GEAIO_lab3

    45/51

    GEAIO

    16/04/12Slide 45

    GA

    toolbox

    Fitness values are derived from objective function values through a scaling or ranking

    function.

    Fitness are non-negative scalars and are stored in column vectors of Nind.

    Fitness values

    FITNESS is an arbitrary fitness function.

    For multi-objective functions, the fitness of an individual is a function of a vector of

    objective function values.

    Multiple population

  • 8/13/2019 GEAIO_lab3

    46/51

    GEAIO

    16/04/12Slide 46

    p p p

    Possibility to have more than one population in parallel and migrate individuals between

    populations

    Multiple population

  • 8/13/2019 GEAIO_lab3

    47/51

    GEAIO

    16/04/12Slide 47

    p p p

    GA toolbox supports multi-population with the functions:

    mutate mutation operators.

    recombin crossover and recombination operators.

    resins uniform random and fitness-based reinsertion.

    select independent subpopulation selection.

    migrate

    to migrate individuals between populations

    GA

    toolbox

    Simple GA

  • 8/13/2019 GEAIO_lab3

    48/51

    GEAIO

    16/04/12Slide 48

    p

    Optimize the De Jongs function:

    With n dimensions.

    In this problem n=20

    Minimum at xi=0

    Simple GA

  • 8/13/2019 GEAIO_lab3

    49/51

    GEAIO

    16/04/12Slide 49

    p

    Optimize the De Jongs function:

    N individuals = 40

    Max Generations = 300

    Number of variables = 20

    Precision = 20 bits per variable

    Generation gap = 0.9

    Gray codification

    Arithmetic

    Maximum value all variables 512

    Minimum value all variables -512

    Use stochastic universal sampling

    Single-point crossover

    Fitness-based reinsertion

    To create the FieldD use matlab function rep

    The project

  • 8/13/2019 GEAIO_lab3

    50/51

    GEAIO

    16/04/12Slide 50

    X1

    Y1

    X2

    Y2

    X3

    Y3

    X4

    Y4

    X5

    Y5

    Sectorisation defined by coordinates of Voronoi points

  • 8/13/2019 GEAIO_lab3

    51/51

    GEAIO

    References

    [Weise, 2009] T. Weise, Global Optimization Algorithms Theory and

    Applications, 2ndEdition, electronic book available at: www.it-weise.de

    [Chipperfield, 1994] A. Chipperfield et al, Genetic Algorithm ToolBox Users

    Guide, version 1.2

    http://www.it-weise.de/http://www.it-weise.de/