Genetic Algorithms Yohai
-
Upload
nagarajuvcc123 -
Category
Documents
-
view
220 -
download
0
description
Transcript of Genetic Algorithms Yohai
![Page 1: Genetic Algorithms Yohai](https://reader037.fdocuments.in/reader037/viewer/2022102915/55cf87e755034664618b5d36/html5/thumbnails/1.jpg)
Genetic Algorithms
Yohai Trabelsi
![Page 2: Genetic Algorithms Yohai](https://reader037.fdocuments.in/reader037/viewer/2022102915/55cf87e755034664618b5d36/html5/thumbnails/2.jpg)
Outline• Evolution in the nature• Genetic Algorithms and Genetic Programming• A simple example for Genetic Algorithms• An example for Genetic programming
![Page 3: Genetic Algorithms Yohai](https://reader037.fdocuments.in/reader037/viewer/2022102915/55cf87e755034664618b5d36/html5/thumbnails/3.jpg)
• Evolution in the nature• Genetic Algorithms and Genetic Programming• A simple example for Genetic Algorithms• An example for Genetic programming
![Page 4: Genetic Algorithms Yohai](https://reader037.fdocuments.in/reader037/viewer/2022102915/55cf87e755034664618b5d36/html5/thumbnails/4.jpg)
Evolution in the nature
• A Chromosome:o A string of DNA.o Each living cell has some.
• Image by Magnus Manske
![Page 5: Genetic Algorithms Yohai](https://reader037.fdocuments.in/reader037/viewer/2022102915/55cf87e755034664618b5d36/html5/thumbnails/5.jpg)
• Each chromosome contains a set of genes.• A gene is a block of DNA.• Each gene determines some aspect of the organism (e.g., eye colour).
![Page 6: Genetic Algorithms Yohai](https://reader037.fdocuments.in/reader037/viewer/2022102915/55cf87e755034664618b5d36/html5/thumbnails/6.jpg)
Reproduction in the nature
• Reproduction involves: 1. Recombination of genes from parents. 2. Small amounts of mutation (errors) in copying.
• One type of recombination is crossover.
![Page 7: Genetic Algorithms Yohai](https://reader037.fdocuments.in/reader037/viewer/2022102915/55cf87e755034664618b5d36/html5/thumbnails/7.jpg)
• Reproduction involves: 1. Recombination of genes from parents. 2. Small amounts of mutation (errors) in copying.
• Right image by Jerry Friedman.
![Page 8: Genetic Algorithms Yohai](https://reader037.fdocuments.in/reader037/viewer/2022102915/55cf87e755034664618b5d36/html5/thumbnails/8.jpg)
• In the nature, fitness describes the ability to survive and reproduce.
Images by ShwSie
![Page 9: Genetic Algorithms Yohai](https://reader037.fdocuments.in/reader037/viewer/2022102915/55cf87e755034664618b5d36/html5/thumbnails/9.jpg)
The evolution cycle
Upper left image by 慕尼黑啤酒
Parent selectio
n
Recombination
Mutation
Surv
ivor
selec
tion
Initialization
![Page 10: Genetic Algorithms Yohai](https://reader037.fdocuments.in/reader037/viewer/2022102915/55cf87e755034664618b5d36/html5/thumbnails/10.jpg)
• Evolution in the nature• Genetic Algorithms and Genetic
Programming• A simple example for Genetic Algorithms• An example for Genetic programming
![Page 11: Genetic Algorithms Yohai](https://reader037.fdocuments.in/reader037/viewer/2022102915/55cf87e755034664618b5d36/html5/thumbnails/11.jpg)
Some history• First work of computer simulation of evolution-
Nils Aall Barricelli(1954)• In the 1950s and 1960s several researchers
began independently studying evolutionary systems.
• The field has experienced impressive growth over the past two decades.
![Page 12: Genetic Algorithms Yohai](https://reader037.fdocuments.in/reader037/viewer/2022102915/55cf87e755034664618b5d36/html5/thumbnails/12.jpg)
Genetic Algorithms• The research on Genetic Algorithms focuses on
imitating the evolution cycle in Algorithms.• That method is applicable for many hard search
and optimization problems.
![Page 13: Genetic Algorithms Yohai](https://reader037.fdocuments.in/reader037/viewer/2022102915/55cf87e755034664618b5d36/html5/thumbnails/13.jpg)
Initialization• Initialization is the process of making the first
generation.• During the algorithm our goal will be to improve
them by imitating the nature.
![Page 14: Genetic Algorithms Yohai](https://reader037.fdocuments.in/reader037/viewer/2022102915/55cf87e755034664618b5d36/html5/thumbnails/14.jpg)
Termination.• In the nature we don’t have (yet) a point that the
process stops. • In many cases an algorithm that runs forever is
useless.• We should try to find the correct time for
terminating the whole process.o That time may be after the results are good and/or before the
running time is too long.
![Page 15: Genetic Algorithms Yohai](https://reader037.fdocuments.in/reader037/viewer/2022102915/55cf87e755034664618b5d36/html5/thumbnails/15.jpg)
The modified evolution cycle
Upper left image by 慕尼黑啤酒
Parent selectio
n
Recombination
Mutation
Surv
ivor
selec
tion
Initialization
termination
![Page 16: Genetic Algorithms Yohai](https://reader037.fdocuments.in/reader037/viewer/2022102915/55cf87e755034664618b5d36/html5/thumbnails/16.jpg)
GA-Some definitions• In any generation there is a group of
individuals that belongs to that generation. We call that group population.• Fitness will be a function from individuals to real
numbers.• The product of the recombination process is an
offspring.
![Page 17: Genetic Algorithms Yohai](https://reader037.fdocuments.in/reader037/viewer/2022102915/55cf87e755034664618b5d36/html5/thumbnails/17.jpg)
Genetic Programming
• Genetic Programming is Genetic Algorithm wherein the population contains programs rather than bitstrings.
![Page 18: Genetic Algorithms Yohai](https://reader037.fdocuments.in/reader037/viewer/2022102915/55cf87e755034664618b5d36/html5/thumbnails/18.jpg)
• Evolution in the nature• Genetic Algorithms and Genetic Programming• A simple example for Genetic Algorithms• An example for Genetic programming
![Page 19: Genetic Algorithms Yohai](https://reader037.fdocuments.in/reader037/viewer/2022102915/55cf87e755034664618b5d36/html5/thumbnails/19.jpg)
A simple example• Problem: “Find” the binary number 11010010.
![Page 20: Genetic Algorithms Yohai](https://reader037.fdocuments.in/reader037/viewer/2022102915/55cf87e755034664618b5d36/html5/thumbnails/20.jpg)
Initialization • We start with 5 random binary numbers with 8
digits each.1. 01001010 2. 100110113. 011000014. 101001105. 01010011
![Page 21: Genetic Algorithms Yohai](https://reader037.fdocuments.in/reader037/viewer/2022102915/55cf87e755034664618b5d36/html5/thumbnails/21.jpg)
The fitness function• We define the fitness of a number to be the sum
of the distances of its digits from these in the target, with the sign minus.
• The target: 11010010 • fitness(01001010)=
![Page 22: Genetic Algorithms Yohai](https://reader037.fdocuments.in/reader037/viewer/2022102915/55cf87e755034664618b5d36/html5/thumbnails/22.jpg)
The target: 11010010
1. fitness(01001010)=-32. fitness(10011011)=-33. fitness(01100001)=-54. fitness(10100110)=-45. fitness(01010011)=-2
![Page 23: Genetic Algorithms Yohai](https://reader037.fdocuments.in/reader037/viewer/2022102915/55cf87e755034664618b5d36/html5/thumbnails/23.jpg)
Parent Selection• In each generation, some constant number of
parents, say, 4 are chosen. Higher is the fitness, greater is the probability of choosing the individual.
![Page 24: Genetic Algorithms Yohai](https://reader037.fdocuments.in/reader037/viewer/2022102915/55cf87e755034664618b5d36/html5/thumbnails/24.jpg)
• {-3,-3, -5,-4,-2}• Assume we select , .• fitness() > fitness() selected. …• We get {}
![Page 25: Genetic Algorithms Yohai](https://reader037.fdocuments.in/reader037/viewer/2022102915/55cf87e755034664618b5d36/html5/thumbnails/25.jpg)
Recombination• Two selected parents will be coupled with
probability 0.5.• () , (, ), ()• 3 is selected as a random number from 1…8• Then we do a crossover: From () we get ()
• We repeat that for each selected couple.
![Page 26: Genetic Algorithms Yohai](https://reader037.fdocuments.in/reader037/viewer/2022102915/55cf87e755034664618b5d36/html5/thumbnails/26.jpg)
Mutation• For each digit in each of the offsprings , we make
the bit flip with probability 0.05.• For we have .
![Page 27: Genetic Algorithms Yohai](https://reader037.fdocuments.in/reader037/viewer/2022102915/55cf87e755034664618b5d36/html5/thumbnails/27.jpg)
The process and it’s termination
• We repeat the cycle until one of the numbers that we get would have fitness 0 (that is would be identical to the desired one).
• We expect that it will not be too long in comparison to checking the fitness of all the numbers in the range.
• Our hope is based on choosing parents with higher fitness and on producing next generations similarly to the nature.
![Page 28: Genetic Algorithms Yohai](https://reader037.fdocuments.in/reader037/viewer/2022102915/55cf87e755034664618b5d36/html5/thumbnails/28.jpg)
Some Results• Similar example, where the target was “Hello
world” achieved the score in generation 65. (population size=40 options)• In our simple case there are options in total.
![Page 29: Genetic Algorithms Yohai](https://reader037.fdocuments.in/reader037/viewer/2022102915/55cf87e755034664618b5d36/html5/thumbnails/29.jpg)
• Evolution in the nature• Genetic Algorithms and Genetic Programming• A simple example for Genetic Algorithms• An example for Genetic programming
![Page 31: Genetic Algorithms Yohai](https://reader037.fdocuments.in/reader037/viewer/2022102915/55cf87e755034664618b5d36/html5/thumbnails/31.jpg)
Lose Checkers • The rules are the same as in the original game.• The goal is opposite to the goal in the original
game: Each player tries to lose all of his pieces.• Player wins if he doesn’t have any pieces or if he
can’t do any move.
![Page 32: Genetic Algorithms Yohai](https://reader037.fdocuments.in/reader037/viewer/2022102915/55cf87e755034664618b5d36/html5/thumbnails/32.jpg)
The complexity• There are roughly legal positions.• In chess there are .
![Page 33: Genetic Algorithms Yohai](https://reader037.fdocuments.in/reader037/viewer/2022102915/55cf87e755034664618b5d36/html5/thumbnails/33.jpg)
Previous work• There are few recent results on Lose checkers.• They concentrate either on search or on finding a
good evaluation function.• They can help to improve good players but they
can’t produce good players.• Improvements on a random player don’t worth
much.
![Page 34: Genetic Algorithms Yohai](https://reader037.fdocuments.in/reader037/viewer/2022102915/55cf87e755034664618b5d36/html5/thumbnails/34.jpg)
The algorithm• The individuals will be trees. • Each tree will behave like evaluation function for
the board states (more details later).• A tree represents a chromosome.• Each tree contains nodes.• A node represents a gene.• There are three kinds of nodes:
o Basic Terminal Nodes.o Basic Function Nodes.o Domain-Specific Terminal Nodes.
![Page 35: Genetic Algorithms Yohai](https://reader037.fdocuments.in/reader037/viewer/2022102915/55cf87e755034664618b5d36/html5/thumbnails/35.jpg)
Basic terminal nodesReturnvalue
Return type
Node name
Ephemeral Random Constant
Floating point
ERC
Boolean false value
Boolean False
Boolean true value
Boolean True
1 Floating point
One
0 Floating point
Zero
![Page 36: Genetic Algorithms Yohai](https://reader037.fdocuments.in/reader037/viewer/2022102915/55cf87e755034664618b5d36/html5/thumbnails/36.jpg)
Basic function nodesReturnvalue
Node name
Logical AND of parametersTrue iff F1 ≤ F2Logical NAND of parametersLogical NOR of parametersLogical NOT of B1Logical OR of parametersF1 if B1 is true and F2 otherwiseF1 − F2F1 multiplied by preset random numberF1F1 + F2
![Page 37: Genetic Algorithms Yohai](https://reader037.fdocuments.in/reader037/viewer/2022102915/55cf87e755034664618b5d36/html5/thumbnails/37.jpg)
Domain-specific nodesEnemyKingCountEnemyManCountEnemyPieceCountFriendlyKingCountFriendlyManCountFriendlyPieceCount
FriendlyKingCount − EnemyKingCount
KingCount
FriendlyManCount − EnemyManCount
ManCount
FriendlyPieceCount −EnemyPieceCount
PieceCount
King factor value KingFactorThe number of plies available to the player
Mobility
![Page 38: Genetic Algorithms Yohai](https://reader037.fdocuments.in/reader037/viewer/2022102915/55cf87e755034664618b5d36/html5/thumbnails/38.jpg)
Domain specific- details of a square
True iff square empty IsEmptySquare(X,Y)True iff square occupied by friendly piece
IsFriendlyPiece(X,Y)
True iff square occupied by king IsKingPiece(X,Y)True iff square occupied by man IsManPiece(X,Y)
![Page 39: Genetic Algorithms Yohai](https://reader037.fdocuments.in/reader037/viewer/2022102915/55cf87e755034664618b5d36/html5/thumbnails/39.jpg)
An example for board evaluation tree
![Page 40: Genetic Algorithms Yohai](https://reader037.fdocuments.in/reader037/viewer/2022102915/55cf87e755034664618b5d36/html5/thumbnails/40.jpg)
The algorithm• Make initial population• While the termination condition didn’t reached:
o Select the best candidates for being parents.o Make the new generation by crossover and mutationo Evaluate the fitness of the new generation.
![Page 41: Genetic Algorithms Yohai](https://reader037.fdocuments.in/reader037/viewer/2022102915/55cf87e755034664618b5d36/html5/thumbnails/41.jpg)
• Make initial population• While the termination condition didn’t reached:
o Select the best candidates for being parents.o Make the new generation by crossover and mutationo Evaluate the fitness of the new generation.
![Page 42: Genetic Algorithms Yohai](https://reader037.fdocuments.in/reader037/viewer/2022102915/55cf87e755034664618b5d36/html5/thumbnails/42.jpg)
The initial population • The size of the population is one of the running
parameters.• We select the trees randomly.• Their maximum allowed depth is also a running
parameter.• We omit the details of the random selection.
![Page 43: Genetic Algorithms Yohai](https://reader037.fdocuments.in/reader037/viewer/2022102915/55cf87e755034664618b5d36/html5/thumbnails/43.jpg)
• Make initial population• While the termination condition didn’t reached:
o Select the best candidates for being parents.o Make the new generation by crossover and mutationo Evaluate the fitness of the new generation.
![Page 44: Genetic Algorithms Yohai](https://reader037.fdocuments.in/reader037/viewer/2022102915/55cf87e755034664618b5d36/html5/thumbnails/44.jpg)
Selection
![Page 45: Genetic Algorithms Yohai](https://reader037.fdocuments.in/reader037/viewer/2022102915/55cf87e755034664618b5d36/html5/thumbnails/45.jpg)
Fitness evaluation • We define GuideArr to be an array of guide
players.• Some of them are random players which are
useful for evaluating initial runs.• Others, alpha-beta players, are based on search
up to some level and random behavior since that level.
• CoPlayNum is the number of players which are selected randomly from the current population for playing with the individual
under evaluation.Image by Jon Sullivan
![Page 46: Genetic Algorithms Yohai](https://reader037.fdocuments.in/reader037/viewer/2022102915/55cf87e755034664618b5d36/html5/thumbnails/46.jpg)
Fitness evaluation
• back
![Page 47: Genetic Algorithms Yohai](https://reader037.fdocuments.in/reader037/viewer/2022102915/55cf87e755034664618b5d36/html5/thumbnails/47.jpg)
• Make initial population• While the termination condition didn’t reached:
o Select the best candidates for being parents.o Make the new generation by crossover and mutationo Check whether the termination condition reached
![Page 48: Genetic Algorithms Yohai](https://reader037.fdocuments.in/reader037/viewer/2022102915/55cf87e755034664618b5d36/html5/thumbnails/48.jpg)
Crossover• Randomly choose two different previously
unselected individuals from the population.• If then
o Perform one-way crossover with I1 as donor and I2 as receiver• Else
o Perform two-way crossover with I1 and I2• End if.
![Page 49: Genetic Algorithms Yohai](https://reader037.fdocuments.in/reader037/viewer/2022102915/55cf87e755034664618b5d36/html5/thumbnails/49.jpg)
Two way crossover• Randomly select an internal node in each of the
two individuals.• Swap the subtrees rooted at these nodes.
![Page 50: Genetic Algorithms Yohai](https://reader037.fdocuments.in/reader037/viewer/2022102915/55cf87e755034664618b5d36/html5/thumbnails/50.jpg)
One way crossover• Randomly select an internal node in each of the
two individuals as a root of selected subtree.• One individual (donor) inserts a copy of its
selected sub-tree into another individual(receiver), in place of its selected sub-tree, while the donor itself remains unchanged.
Similar to gene transfer in bacteria, image by Y tambe
![Page 51: Genetic Algorithms Yohai](https://reader037.fdocuments.in/reader037/viewer/2022102915/55cf87e755034664618b5d36/html5/thumbnails/51.jpg)
• Using the one way crossover gives the fitter individuals an additional survival advantage.
• They still can change due to the standard two-way crossover.
![Page 52: Genetic Algorithms Yohai](https://reader037.fdocuments.in/reader037/viewer/2022102915/55cf87e755034664618b5d36/html5/thumbnails/52.jpg)
Mutation• We randomly choose a node in the tree for
mutation.• We do probabilistic decision whether to use the
traditional tree building mutation method or the Local mutation method.
• The probability for each method is given as a parameter to our algorithm.
![Page 53: Genetic Algorithms Yohai](https://reader037.fdocuments.in/reader037/viewer/2022102915/55cf87e755034664618b5d36/html5/thumbnails/53.jpg)
Traditional mutation• Traditional tree building mutation:
o Done by replacing the selected node with a new subtree.
• The drawback of using only the traditional mutation is that a mutation can change dramatically the fitness of an individual.
![Page 54: Genetic Algorithms Yohai](https://reader037.fdocuments.in/reader037/viewer/2022102915/55cf87e755034664618b5d36/html5/thumbnails/54.jpg)
Local mutation• Each node that returns a floating-point value
has a floating-point variable attached with it (initialized to 1).
• The returned value of the node was the normal value multiplied by the variable.
• The mutation is a small change in the variable.
![Page 55: Genetic Algorithms Yohai](https://reader037.fdocuments.in/reader037/viewer/2022102915/55cf87e755034664618b5d36/html5/thumbnails/55.jpg)
• Make initial population• While the termination condition didn’t reached:
o Select the best candidates for being parents.o Make the new generation by crossover and mutationo Check whether the termination condition reached
![Page 56: Genetic Algorithms Yohai](https://reader037.fdocuments.in/reader037/viewer/2022102915/55cf87e755034664618b5d36/html5/thumbnails/56.jpg)
Termination• The number of Generations until the termination
will be a parameter of our program.
![Page 57: Genetic Algorithms Yohai](https://reader037.fdocuments.in/reader037/viewer/2022102915/55cf87e755034664618b5d36/html5/thumbnails/57.jpg)
The Players• Use alpha-beta search algorithm.• Evaluate non-terminal states using the individual • The depth of the search is 3.• There are more methods.
![Page 58: Genetic Algorithms Yohai](https://reader037.fdocuments.in/reader037/viewer/2022102915/55cf87e755034664618b5d36/html5/thumbnails/58.jpg)
Some Results• 1000 games were played against some alpha-beta
players.
• The Score: 1 point was given for win and 0.5 For drawn.