Upload
others
View
1
Download
0
Embed Size (px)
Citation preview
GENETIC ALGORITHMGENETIC ALGORITHM
Introduction
A biologically inspired model of intelligence
The principles of biological evolution are applied to findsolutions to difficult problems
The problems are not solved by reasoning logically aboutthem; rather populations of competing candidate solutionsare spawned and then evolved to become better solutionsthrough a process patterned after biological evolution
1
GENETIC ALGORITHMGENETIC ALGORITHM
Introduction
Less worthy candidate solutions tend to die out, while thosethat show promise of solving a problem survive andp g preproduce by constructing new solutions out of theircomponents
GA begin with a population of candidate problem solutions
Candidate solutions are evaluated according to their ability to solve problem instances: only the fittest survive and combine with each other to produce the next generation of possible
2
p g psolutions
GENETIC ALGORITHMGENETIC ALGORITHM
Introduction
Thus increasingly powerful solutions. Learning is viewed as acompetition among a population of evolving candidatep g p p gproblem solutions
This method is heuristic in nature and it was introduced byThis method is heuristic in nature and it was introduced byJohn Holland in 1975
3
GENETIC ALGORITHMGENETIC ALGORITHM
Basic Algorithm
beginset time t = 0;set time t 0;initialise population P(t) = {x1
t, x2t, …, xn
t} of solutions;while the termination condition is not met do
beginbeginevaluate fitness of each member of P(t);select some members of P(t) for creating offspring;produce offspring by genetic operators;replace some members with the new offspring;set time t = t + 1;
4
;end
end
GENETIC ALGORITHMGENETIC ALGORITHM
Chromosome
5
GENETIC ALGORITHMGENETIC ALGORITHM
Representation of Solutions: The Chromosome
Gene: A basic unit, which represents one characteristic of theindividual. The value of each gene is called an alleleg
Chromosome: A string of genes; it represents an individual i.e.a possible solution of a problem Each chromosomea possible solution of a problem. Each chromosomerepresents a point in the search space
Population: A collection of chromosomes
An appropriate chromosome representation is important for
6
pp p p pthe efficiency and complexity of the GA
GENETIC ALGORITHMGENETIC ALGORITHM
Representation of Solutions: The Chromosome
The classical representation scheme for chromosomes isbinary vectors of fixed length. However, real valuedy g ,chromosomes are also possible
In binary coded chromosomes every gene has two allelesIn binary coded chromosomes, every gene has two allelesIn real coded chromosomes, a gene can be assigned any value from a domain of values
In the case of an I-dimensional search space, eachchromosome consists of I variables with each variable
7
encoded as a bit string
GENETIC ALGORITHMGENETIC ALGORITHM
Representation of Solutions: The Chromosome
Example: Cookies Problem
Two parameters sugar and flour (in kgs). The range for bothis 0 to 9 kgs. Therefore a chromosome will comprise of twogenes called sugar and flourgenes called sugar and flour
5 1 Chromosome # 01
2 4 Chromosome # 02
8
GENETIC ALGORITHMGENETIC ALGORITHM
Representation of Solutions: The Chromosome
Example: Expression satisfaction Problem
F = (¬a ∨ c) ∧ (¬a ∨ c ∨ ¬e)∧ (¬b ∨ c ∨ d ∨ ¬e) ∧ (a ∨ ¬b ∨ c)∧ (¬b ∨ c ∨ d ∨ ¬e) ∧ (a ∨ ¬b ∨ c)∧ (¬e ∨ f)
Ch Si bi b d f 100111Chromosome: Six binary genes a b c d e f e.g. 100111
9
GENETIC ALGORITHMGENETIC ALGORITHM
Representation of Solutions: The Chromosome
Example: Model Learning
Use GA to learn the concept Yes Reaction from the FoodAllergy problem’s data
10
GENETIC ALGORITHMGENETIC ALGORITHM
Example: Model Learning
A potential model of the data can be represented as achromosome with the genetic representation:g p
Gene # 1 Gene # 2 Gene # 3 Gene # 4Restaurant Meal Day CostRestaurant Meal Day Cost
The alleles of genes are:
Restaurant gene: Sam, Lobdell, SarahMeal gene: breakfast, lunch
11
gDay gene: Friday, Saturday, SundayCost gene: cheap, expensive
GENETIC ALGORITHMGENETIC ALGORITHM
Representation of Solutions: The Chromosome
Rules Representation
Rules are often represented by bit strings (because they canbe easily manipulated by genetic operators), but othernumerical and symbolic representations are also possiblenumerical and symbolic representations are also possible
Set of if-then rules:S ifi i f iSpecific sub-strings are allocated for encoding eachrule pre-condition and post-condition
12
Example: Suppose we have an attribute “Outlook”which can take on values: Sunny, Overcast or Rain
GENETIC ALGORITHMGENETIC ALGORITHM
Representation of Solutions: The Chromosome
Rules Representation
We can represent it with 3 bits:100 would mean the value Sunny,010 would mean Overcast &010 would mean Overcast &001 would mean Rain
110 ld S O110 would mean Sunny or Overcast111 would mean that we don’t care about its value
13
The pre-conditions & post-conditions of a rule are encodingby concatenating the individual representation of attributes
GENETIC ALGORITHMGENETIC ALGORITHM
Representation of Solutions: The Chromosome
Rules Representation
Example:If (Outlook = Overcast or Rain) and Wind = strong
then PlayTennis = Nothen PlayTennis No
can be encoded as 0111001
Another ruleIf Wind = Strong then PlayTennis = Yes
14
g y
can be encoded as 1111000
GENETIC ALGORITHMGENETIC ALGORITHM
Representation of Solutions: The Chromosome
Rules Representation
An hypothesis comprising of both of these rules can beencoded as a chromosome 01110011111010
Note that even if an attribute does not appear in a rule, wereserve its place in the chromosome, so that we can havefi d l th hfixed length chromosomes
15
GENETIC ALGORITHMGENETIC ALGORITHM
Fitness Function
16
GENETIC ALGORITHMGENETIC ALGORITHM
Fitness Function
Also called “evaluation function”
It is used to determine the fitness of a chromosome
Creating a good fitness function is one of the challengingCreating a good fitness function is one of the challengingtasks of using GA
17
GENETIC ALGORITHMGENETIC ALGORITHM
Fitness Function
Example: Cookies Problem
Two parameters sugar and flour (in kgs). The range for bothis 0 to 9 kgs. Therefore a chromosome will comprise of twogenes called sugar and flourgenes called sugar and flour
5 1
2 4
18
The fitness function for a chromosome is the taste of theresulting cookies; values can be from 1 to 100
GENETIC ALGORITHMGENETIC ALGORITHM
Fitness Function
Example: Expression satisfaction Problem
F = (¬a ∨ c) ∧ (¬a ∨ c ∨ ¬e)∧ (¬b ∨ c ∨ d ∨ ¬e) ∧ (a ∨ ¬b ∨ c)∧ (¬b ∨ c ∨ d ∨ ¬e) ∧ (a ∨ ¬b ∨ c)∧ (¬e ∨ f)
Ch Si bi b d f 100111Chromosome: Six binary genes a b c d e f e.g. 100111
Fitness function: Number of clauses having truth value of 1
19
ge.g. 010010 has fitness 2
GENETIC ALGORITHMGENETIC ALGORITHM
Fitness Function
Example: Model Learning
Use GA to learn the concept Yes Reaction from the data
The fitness function can be the score of the classificationThe fitness function can be the score of the classificationaccuracy of the rule-set over a set of provided trainingexamples (number of training samples correctly classified by
h )a chromosome)
Often other criteria may be included as well, such as the
20
ycomplexity of the rules or the size of the rule set
GENETIC ALGORITHMGENETIC ALGORITHM
Reproduction Operators
21
GENETIC ALGORITHMGENETIC ALGORITHM
Reproduction Operators
Genetic operators are applied to chromosomes that areselected to be parents, to create offspringp , p g
Basically of two types: Crossover and Mutation
Crossover operator create offspring by recombining thechromosomes of selected parents
Mutation is used to make small random changes to achromosome in an effort to add diversity to the population
22
y p p
GENETIC ALGORITHMGENETIC ALGORITHM
Reproduction Operators: Crossover
Crossover operation takes two candidate solutions anddivides them, swapping components to produce two new, pp g p pcandidates
23
GENETIC ALGORITHMGENETIC ALGORITHM
Reproduction Operators: Crossover
Figure illustrates crossover on bit string patterns of length 8
The operator splits them and forms two children whose initialsegment comes from one parent and whose tail comes fromthe otherthe other
Input Bit Strings1 1 # 0 1 0 1 # # 1 1 0 # 0 # 1
Resulting Strings
24
g g1 1 # 0 # 0 # 1 # 1 1 0 1 0 1 #
GENETIC ALGORITHMGENETIC ALGORITHM
Reproduction Operators: Crossover
Two genes sugar and flour (in kgs)Crossover operation on chromosomesp
5 1 5 45 1 5 4
2 4 2 1
25
GENETIC ALGORITHMGENETIC ALGORITHM
Reproduction Operators: Crossover
The place of split in the candidate solution is an arbitrarychoice. This split may be at any point in the solutionp y y p
This splitting point may be randomly chosen or changedsystematically during the solution processsystematically during the solution process
Crossover can unite an individual that is doing well in onedi i ith th i di id l th t i d i ll i thdimension with another individual that is doing well in theother dimension
26
GENETIC ALGORITHMGENETIC ALGORITHM
Reproduction Operators: Crossover (Important Similarities)
Suppose we have these chromosomes and their fitness values
A) 01101 169B) 11000 576C) 01000 64C) 01000 64D) 10011 361
If l th t i hi h h hi h fit l h b th t thIf we analyze the strings which have high fitness value, we have observe that theyboth have a 1 in the 1st column, whereas the low fitness strings have a 0. Inthe second column we have a 1 in B and 0 in D, and 1 in the low fitnessstrings. We wonder that if 1 in the 2nd column is associated with low fitness, so
27
gwe may improve the score of B by putting a 0 in place of 1 in the 2nd column
GENETIC ALGORITHMGENETIC ALGORITHM
Problem solving through GA
Optimize value of ( )f x x( ) sin= π2 6 over 0 255≤ ≤xOptimize value of ( )f x( ) sin= 256 over 0 255≤ ≤x
where x is restricted to integers.The maximum value of 1 occurs at x = 128.
GENETIC ALGORITHMGENETIC ALGORITHM
Problem solving through GA
• One variable• Use binary alphabet
g g
• Use binary alphabet• Therefore, represent each individual as 8-bit binary
string• Set number of population members to (artificially
low) 8• Randomize populationp p• Calculate fitness for each member of (initialized)
population
GENETIC ALGORITHMGENETIC ALGORITHM
References
Engelbrecht Chapter 8 & 9
30