computer implementation 1 computer implementation of genetic algorithm by: moch. rif’an

31
Computer Implementation Computer Implementation 1 Computer Computer Implementation of Implementation of Genetic Algorithm Genetic Algorithm By: By: Moch. Rif’an Moch. Rif’an

Upload: madlyn-welch

Post on 27-Dec-2015

220 views

Category:

Documents


0 download

TRANSCRIPT

Computer ImplementationComputer Implementation 11

Computer Implementation Computer Implementation of Genetic Algorithmof Genetic Algorithm

By:By:

Moch. Rif’anMoch. Rif’an

Moch. Rif'an, ST.,MT.

Computer ImplementationComputer Implementation 22

CodingsCodings

The principle of meaningful building The principle of meaningful building blocks is simply this:blocks is simply this:• The user should select a coding so that The user should select a coding so that

short, low order schemata are relevant short, low order schemata are relevant to the underlying problem and reltively to the underlying problem and reltively unrelated to schemata over fixed unrelated to schemata over fixed position.position.

Computer ImplementationComputer Implementation 33

The second coding rule, the principle The second coding rule, the principle of minimall alphabets, is simply of minimall alphabets, is simply stated:stated:• The user should select the smallest The user should select the smallest

alphabet that permits a natural alphabet that permits a natural expression of the problemexpression of the problem

Computer ImplementationComputer Implementation 44

Encoding MethodsEncoding Methods Binary Encoding – Binary Encoding – Most common method of encoding. Chromosomes are Most common method of encoding. Chromosomes are

strings of 1s and 0s and each position in the chromosome represents a strings of 1s and 0s and each position in the chromosome represents a particular characteristic of the problem.particular characteristic of the problem.

Permutation Encoding – Permutation Encoding – Useful in ordering problems such as the Useful in ordering problems such as the Traveling Salesman Problem (TSP). Example. In TSP, every chromosome Traveling Salesman Problem (TSP). Example. In TSP, every chromosome is a string of numbers, each of which represents a city to be visited.is a string of numbers, each of which represents a city to be visited.

1111111000000001111111111110000000011111Chromosome BChromosome B

1011001011001110010110110010110011100101Chromosome AChromosome A

8  5  6  7  2  3  1  4  98  5  6  7  2  3  1  4  9Chromosome BChromosome B

1  5  3  2  6  4  7  9  81  5  3  2  6  4  7  9  8Chromosome AChromosome A

Computer ImplementationComputer Implementation 55

Encoding Methods (contd.)Encoding Methods (contd.)

Value Encoding –Value Encoding – Used in problems where complicated values, such as Used in problems where complicated values, such as real numbers, are used and where binary encoding would not suffice.real numbers, are used and where binary encoding would not suffice.

Good for some problems, but Good for some problems, but often necessary to develop some specific often necessary to develop some specific crossover and mutation techniques for these chromosomes. crossover and mutation techniques for these chromosomes.

(left), (back), (left), (right), (forward)(left), (back), (left), (right), (forward)ChromosomeChromosome BB

1.235  5.323  0.454  2.321  2.4541.235  5.323  0.454  2.321  2.454Chromosome AChromosome A

Computer ImplementationComputer Implementation 66

Encoding Methods (contd.)Encoding Methods (contd.) Tree Encoding –Tree Encoding – This encoding is used mainly for evolving programs or This encoding is used mainly for evolving programs or

expressions, i.e. for Genetic programming.expressions, i.e. for Genetic programming. Tree Encoding -Tree Encoding - every chromosome is a tree of some objects, such as every chromosome is a tree of some objects, such as

values/arithmetic operators or commands in a programming language.values/arithmetic operators or commands in a programming language.

( +  x  ( /  5  y ) ) ( do_until  step  wall )

Citation:

http://ocw.mit.edu/NR/rdonlyres/Aeronautics-and-Astronautics/16-888Spring-2004/D66C4396-90C8-49BE-BF4A-4EBE39CEAE6F/0/MSDO_L11_GA.pdf

Computer ImplementationComputer Implementation 77

4 individu4 individu

Citation: examples taken from: www.genetic-programming.com/c2003lecture1modified.ppt

Computer ImplementationComputer Implementation 88

Mapping Objective function to Mapping Objective function to Fitness FormFitness Form

minimization rather than maximizationminimization rather than maximization Transform from minimization to Transform from minimization to

maximization problem:maximization problem:• Multiply the cost function by a minus one Multiply the cost function by a minus one

(insufficient)(insufficient)• Commonly used:Commonly used:

.otherwise 0

,)( when )()( maxmax CxgxgC

xf

Computer ImplementationComputer Implementation 99

A problem with negative utility function A problem with negative utility function u(x)u(x) value in maximization, transform value in maximization, transform fitness according to the equation:fitness according to the equation:

.otherwise 0

,0)( when )()( minmin CxuCxu

xf

Computer ImplementationComputer Implementation 1010

Fitness ScalingFitness Scaling

1.1. Linear scalingLinear scaling

To ensure each average population To ensure each average population member contribute one expected member contribute one expected offspring to the next generationoffspring to the next generation

baff

avgavg ff

Computer ImplementationComputer Implementation 1111

To control the number of offspring given to the To control the number of offspring given to the population member with maximum raw fitness.population member with maximum raw fitness.

ccMultMult=the number of expected copies desired for =the number of expected copies desired for the best population member. For typical small the best population member. For typical small population (n=50 to 100) a cpopulation (n=50 to 100) a cMultMult=1,2 to 2 has =1,2 to 2 has been used successfullybeen used successfully

avgmult fCf .max

Computer ImplementationComputer Implementation 1212

0minmin ff

minf avgfmaxf

minf

avgf avgf .2

Computer ImplementationComputer Implementation 1313

2.2. Sigma (Sigma () truncation:) truncation: Using population variance informationUsing population variance information

c is choosen as reasonable multiple of population c is choosen as reasonable multiple of population standard deviation (between 1 and 3)standard deviation (between 1 and 3)

Negative result (f’<0) are arbitrarily set to 0Negative result (f’<0) are arbitrarily set to 0

3.3. Power Low ScalingPower Low Scaling

)( cfff

ff

Computer ImplementationComputer Implementation 1414

A multiparameter, mapped, fixed-A multiparameter, mapped, fixed-point codingpoint coding

Tidak sukaTidak suka

GunakanGunakan

Carefully control the range and precision Carefully control the range and precision of the decision variable. The precision:of the decision variable. The precision:

lx 2,0 maxmin ,uu

12minmax

l

uu

Computer ImplementationComputer Implementation 1515

Single USingle U11 parameter parameter

• 0000 0000 u uminmin

• 1111 1111 u umaxmax

Multiparameter Coding (10 Multiparameter Coding (10 parameter):parameter):• 0001| 0101|…|1100|1111|0001| 0101|…|1100|1111|

• UU1 1 | | UU1 1 |…| |…| UU1 1 | | UU1 1 ||

Computer ImplementationComputer Implementation 1616

DiscretizationDiscretization

Computer ImplementationComputer Implementation 1717

Computer ImplementationComputer Implementation 1818

ConstraintsConstraints

Minimize Minimize g(x)g(x) Subject to Subject to bbii(x)≥0 i=1,2,…,n(x)≥0 i=1,2,…,n Where Where xx is an is an mm vector vector

Tranform to the unconstraint form:Tranform to the unconstraint form:

tcoefficienpenalty :r

functionpenalty :Φ

where

)(.)( minimize1

n

ii xbrxg

Computer ImplementationComputer Implementation 1919

Example:Example:The Traveling Salesman Problem The Traveling Salesman Problem

(TSP)(TSP)

The traveling salesman must visit every city in his territory exactly once and then return to the starting point; given the cost of travel between all cities, how should he plan his itinerary for minimum total cost of the entire tour?

TSP NP-Complete

Note: we shall discuss a single possible approach to approximate the TSP by GAs

Computer ImplementationComputer Implementation 2020

TSP (Representation, Evaluation, TSP (Representation, Evaluation, Initialization and Selection)Initialization and Selection)

A vector v = (i1 i2… in) represents a tour (v is a permutation of {1,2,…,n})

Fitness f of a solution is the inverse cost of the corresponding tour

Initialization: use either some heuristics, or a random sample of permutations of {1,2,…,n}

We shall use the fitness proportionate selection

Computer ImplementationComputer Implementation 2121

Notation (schema)Notation (schema)

{0,1,#} is the symbol alphabet, where # is a special wild card symbol

A schema is a template consisting of a string composed of these three symbols

Example: the schema [01#1#] matches the strings: [01010], [01011], [01110] and [01111]

Computer ImplementationComputer Implementation 2222

Notation (order)Notation (order)

The order of the schema S (denoted by o(S)) is the number of fixed positions (0 or 1) presented in the schema

Example: for S1 = [01#1#], o(S1) = 3

for S2 = [##1#1010], o(S2) = 5

The order of a schema is useful to calculate survival probability of the schema for mutations

There are 2 l-o(S)

different strings that match S

Computer ImplementationComputer Implementation 2323

Notation (defining length)Notation (defining length)

The defining length of schema S (denoted by (S)) is the distance between the first and last fixed positions in it

Example: for S1 = [01#1#], (S1) = 4 – 1 = 3,

for S2 = [##1#1010], (S2) = 8 – 3 = 5

The defining length of a schema is useful to calculate survival probability of the schema for crossovers

Computer ImplementationComputer Implementation 2424

Notation (cont)Notation (cont)

m(S,t) is the number of individuals in the population belonging to a particular schema S at time t (in terms of generations)

fS(t) is the average fitness value of strings belonging to schema S at time t

f (t) is the average fitness value over all strings in the population

Computer ImplementationComputer Implementation 2525

The effect ofThe effect of SelectionSelection

Under fitness-proportionate selection the expected number of individuals belonging to schema S at time (t+1) is m (S,t+1) = m (S,t) ( fS(t)/f (t) )

Assuming that a schema S remains above average by 0 c, (i.e., fS(t) = f (t) + c f (t) ), then

m (S,t) = m (S,0) (1 + c)t

Significance: “above average” schema receives an exponentially increasing number of strings in the next generation

Computer ImplementationComputer Implementation 2626

The effect ofThe effect of CrossoverCrossover

The probability of schema S (|S| = l) to survive crossover is ps(S) 1 – pc((S)/(l – 1))

The combined effect of selection and crossover yields

m (S,t+1) m (S,t) ( fS(t)/f (t) ) [1 - pc((S)/(l – 1))]

Above-average schemata with short defining lengths would still be sampled at exponentially increasing rates

Computer ImplementationComputer Implementation 2727

The effect ofThe effect of MutationMutation

The probability of S to survive mutation is:

ps(S) = (1 – pm)o(S)

Since pm<< 1, this probability can be approximated by:

ps(S) 1 – pm·o(S)

The combined effect of selection, crossover and mutation yields

m (S,t+1) m (S,t) ( fS(t)/f (t) ) [1 - pc((S)/(l – 1)) -pmo(S)]

Computer ImplementationComputer Implementation 2828

Schema TheoremSchema Theorem

Short, low-order, above-average schemata receive exponentially increasing trials in subsequent generations of a genetic algorithm

Result: GAs explore the search space by short, low-order schemata which, subsequently, are used for information exchange during crossover

Computer Implementation 29

Computer Implementation 30

Computer Implementation 31