KEMBAR78
Machine Learning Lecture 5 (Genetic Algorithm) | PDF
Learning ML
Partha Dey,
PhD
Ant Colony
Optimization
Genetic
Algorithm
GA operators
Flowcharts
R Codes
Acknowledge
Learning Machine Learning :: Session 3
Partha Dey, PhD
Dept. of Mechanical Engineering
Academy of Technology
18th
November 2018
1 / 10
Learning ML
Partha Dey,
PhD
Ant Colony
Optimization
Genetic
Algorithm
GA operators
Flowcharts
R Codes
Acknowledge
Overview
1 Ant Colony Optimization
2 Genetic Algorithm
Genetic Operators
3 The ACO/GA flowchart
4 The ACO/GA code
5 Acknowledgements
2 / 10
Learning ML
Partha Dey,
PhD
Ant Colony
Optimization
Genetic
Algorithm
GA operators
Flowcharts
R Codes
Acknowledge
Travelling Salesman Problem (TSP)
A salesperson has been given the assignment to visit
. Bengaluru,
. Guwahati,
. Chennai and
. Mumbai,
from Kolkata and come back to her hometown. . .
along the shortest route
3 / 10
Learning ML
Partha Dey,
PhD
Ant Colony
Optimization
Genetic
Algorithm
GA operators
Flowcharts
R Codes
Acknowledge
Travelling Salesman Problem (TSP)
A salesperson has been given the assignment to visit
. Bengaluru,
. Guwahati,
. Chennai and
. Mumbai,
from Kolkata and come back to her hometown. . .
along the shortest route
3 / 10
Learning ML
Partha Dey,
PhD
Ant Colony
Optimization
Genetic
Algorithm
GA operators
Flowcharts
R Codes
Acknowledge
Travelling Salesman Problem (TSP)
A salesperson has been given the assignment to visit
. Bengaluru,
. Guwahati,
. Chennai and
. Mumbai,
from Kolkata and come back to her hometown. . .
along the shortest route
3 / 10
Learning ML
Partha Dey,
PhD
Ant Colony
Optimization
Genetic
Algorithm
GA operators
Flowcharts
R Codes
Acknowledge
Travelling Salesman Problem (TSP)
A salesperson has been given the assignment to visit
. Bengaluru,
. Guwahati,
. Chennai and
. Mumbai,
from Kolkata and come back to her hometown. . .
along the shortest route
3 / 10
Learning ML
Partha Dey,
PhD
Ant Colony
Optimization
Genetic
Algorithm
GA operators
Flowcharts
R Codes
Acknowledge
Travelling Salesman Problem (TSP)
A salesperson has been given the assignment to visit
. Bengaluru,
. Guwahati,
. Chennai and
. Mumbai,
from Kolkata and come back to her hometown. . .
along the shortest route
She first 1 finds out
the inter-city distances —
3 / 10
Learning ML
Partha Dey,
PhD
Ant Colony
Optimization
Genetic
Algorithm
GA operators
Flowcharts
R Codes
Acknowledge
Travelling Salesman Problem (TSP)
A salesperson has been given the assignment to visit
. Bengaluru,
. Guwahati,
. Chennai and
. Mumbai,
from Kolkata and come back to her hometown. . .
along the shortest route
She first 1 finds out
the inter-city distances —
Kol Ben Guw Che Mum
Kol
Ben 1560
Guw 524 2082
Che 1356 290 1884
Mum 1654 846 1034 2088
Source : www.distancecalculator.net
3 / 10
Learning ML
Partha Dey,
PhD
Ant Colony
Optimization
Genetic
Algorithm
GA operators
Flowcharts
R Codes
Acknowledge
Travelling Salesman Problem (TSP)
A salesperson has been given the assignment to visit
. Bengaluru,
. Guwahati,
. Chennai and
. Mumbai,
from Kolkata and come back to her hometown. . .
along the shortest route
She first 1 finds out
the inter-city distances —
Kol Ben Guw Che Mum
Kol
Ben 1560
Guw 524 2082
Che 1356 290 1884
Mum 1654 846 1034 2088
Source : www.distancecalculator.net
. . . then
2 lists down
all the 4 ! ways
to plan her tour,
3 / 10
Learning ML
Partha Dey,
PhD
Ant Colony
Optimization
Genetic
Algorithm
GA operators
Flowcharts
R Codes
Acknowledge
Travelling Salesman Problem (TSP)
A salesperson has been given the assignment to visit
. Bengaluru,
. Guwahati,
. Chennai and
. Mumbai,
from Kolkata and come back to her hometown. . .
along the shortest route
She first 1 finds out
the inter-city distances —
Kol Ben Guw Che Mum
Kol
Ben 1560
Guw 524 2082
Che 1356 290 1884
Mum 1654 846 1034 2088
Source : www.distancecalculator.net
. . . then
2 lists down
all the 4 ! ways
to plan her tour,
and finally
3 picks the
shortest of them.
3 / 10
Learning ML
Partha Dey,
PhD
Ant Colony
Optimization
Genetic
Algorithm
GA operators
Flowcharts
R Codes
Acknowledge
Travelling Ants to solve the TSP
Now, the nature-loving salesperson
has a few servants whom she
asks to do the trial tours for her.
4 / 10
Learning ML
Partha Dey,
PhD
Ant Colony
Optimization
Genetic
Algorithm
GA operators
Flowcharts
R Codes
Acknowledge
Travelling Ants to solve the TSP
Now, the nature-loving salesperson
has a few servants whom she
asks to do the trial tours for her.
As per order, 4 ants instantly
start from Kolkata towards
the four different cities.
4 / 10
Learning ML
Partha Dey,
PhD
Ant Colony
Optimization
Genetic
Algorithm
GA operators
Flowcharts
R Codes
Acknowledge
Travelling Ants to solve the TSP
Now, the nature-loving salesperson
has a few servants whom she
asks to do the trial tours for her.
As per order, 4 ants instantly
start from Kolkata towards
the four different cities.
BOM,
4 / 10
Learning ML
Partha Dey,
PhD
Ant Colony
Optimization
Genetic
Algorithm
GA operators
Flowcharts
R Codes
Acknowledge
Travelling Ants to solve the TSP
Now, the nature-loving salesperson
has a few servants whom she
asks to do the trial tours for her.
As per order, 4 ants instantly
start from Kolkata towards
the four different cities.
BOM, BLR,
4 / 10
Learning ML
Partha Dey,
PhD
Ant Colony
Optimization
Genetic
Algorithm
GA operators
Flowcharts
R Codes
Acknowledge
Travelling Ants to solve the TSP
Now, the nature-loving salesperson
has a few servants whom she
asks to do the trial tours for her.
As per order, 4 ants instantly
start from Kolkata towards
the four different cities.
BOM, BLR, MAA,
4 / 10
Learning ML
Partha Dey,
PhD
Ant Colony
Optimization
Genetic
Algorithm
GA operators
Flowcharts
R Codes
Acknowledge
Travelling Ants to solve the TSP
Now, the nature-loving salesperson
has a few servants whom she
asks to do the trial tours for her.
As per order, 4 ants instantly
start from Kolkata towards
the four different cities.
BOM, BLR, MAA, GAU
4 / 10
Learning ML
Partha Dey,
PhD
Ant Colony
Optimization
Genetic
Algorithm
GA operators
Flowcharts
R Codes
Acknowledge
Travelling Ants to solve the TSP
Now, the nature-loving salesperson
has a few servants whom she
asks to do the trial tours for her.
As per order, 4 ants instantly
start from Kolkata towards
the four different cities.
Each ant completes a tour
and is Rewarded ∝ 1
tour distance
4 / 10
Learning ML
Partha Dey,
PhD
Ant Colony
Optimization
Genetic
Algorithm
GA operators
Flowcharts
R Codes
Acknowledge
Travelling Ants to solve the TSP
Now, the nature-loving salesperson
has a few servants whom she
asks to do the trial tours for her.
As per order, 4 ants instantly
start from Kolkata towards
the four different cities.
Each ant completes a tour
and is Rewarded ∝ 1
tour distance
They continue this quite a few
number of times, each time
depositing some pheromone
proportional to its reward.
4 / 10
Learning ML
Partha Dey,
PhD
Ant Colony
Optimization
Genetic
Algorithm
GA operators
Flowcharts
R Codes
Acknowledge
Travelling Ants to solve the TSP
Now, the nature-loving salesperson
has a few servants whom she
asks to do the trial tours for her.
As per order, 4 ants instantly
start from Kolkata towards
the four different cities.
Each ant completes a tour
and is Rewarded ∝ 1
tour distance
They continue this quite a few
number of times, each time
depositing some pheromone
proportional to its reward.
The next ants follow
stronger pheromone
trail. . .
4 / 10
Learning ML
Partha Dey,
PhD
Ant Colony
Optimization
Genetic
Algorithm
GA operators
Flowcharts
R Codes
Acknowledge
Travelling Ants to solve the TSP
Now, the nature-loving salesperson
has a few servants whom she
asks to do the trial tours for her.
As per order, 4 ants instantly
start from Kolkata towards
the four different cities.
Each ant completes a tour
and is Rewarded ∝ 1
tour distance
They continue this quite a few
number of times, each time
depositing some pheromone
proportional to its reward.
The next ants follow
stronger pheromone
trail. . . . . .
weaker
untraversed
trails . . . . . .
4 / 10
Learning ML
Partha Dey,
PhD
Ant Colony
Optimization
Genetic
Algorithm
GA operators
Flowcharts
R Codes
Acknowledge
Travelling Ants to solve the TSP
Now, the nature-loving salesperson
has a few servants whom she
asks to do the trial tours for her.
As per order, 4 ants instantly
start from Kolkata towards
the four different cities.
Each ant completes a tour
and is Rewarded ∝ 1
tour distance
They continue this quite a few
number of times, each time
depositing some pheromone
proportional to its reward.
The next ants follow
stronger pheromone
trail. . . . . .
weaker
untraversed
trails . . . . . .
evaporate fast
4 / 10
Learning ML
Partha Dey,
PhD
Ant Colony
Optimization
Genetic
Algorithm
GA operators
Flowcharts
R Codes
Acknowledge
Travelling Ants to solve the TSP
Now, the nature-loving salesperson
has a few servants whom she
asks to do the trial tours for her.
As per order, 4 ants instantly
start from Kolkata towards
the four different cities.
Each ant completes a tour
and is Rewarded ∝ 1
tour distance
They continue this quite a few
number of times, each time
depositing some pheromone
proportional to its reward.
The next ants follow
stronger pheromone
trail. . . . . .
showing
the way to
an optimized
path. . .
4 / 10
Learning ML
Partha Dey,
PhD
Ant Colony
Optimization
Genetic
Algorithm
GA operators
Flowcharts
R Codes
Acknowledge
Travelling Ants to solve the TSP
Now, the nature-loving salesperson
has a few servants whom she
asks to do the trial tours for her.
As per order, 4 ants instantly
start from Kolkata towards
the four different cities.
Each ant completes a tour
and is Rewarded ∝ 1
tour distance
They continue this quite a few
number of times, each time
depositing some pheromone
proportional to its reward.
The next ants follow
stronger pheromone
trail. . . . . .
showing
the way to
an optimized
path. . . for our
actual tranveller
to follow
4 / 10
Learning ML
Partha Dey,
PhD
Ant Colony
Optimization
Genetic
Algorithm
GA operators
Flowcharts
R Codes
Acknowledge
Travelling Ants to solve the TSP
Now, the nature-loving salesperson
has a few servants whom she
asks to do the trial tours for her.
As per order, 4 ants instantly
start from Kolkata towards
the four different cities.
Each ant completes a tour
and is Rewarded ∝ 1
tour distance
They continue this quite a few
number of times, each time
depositing some pheromone
proportional to its reward.
The next ants follow
stronger pheromone
trail. . . . . .
showing
the way to
an optimized
path. . . for our
actual tranveller
to follow, without
doing sort(4 ! sums)
4 / 10
Learning ML
Partha Dey,
PhD
Ant Colony
Optimization
Genetic
Algorithm
GA operators
Flowcharts
R Codes
Acknowledge
Another Optimization Problem
A can needs to be manufactured which is :
 cylindrical in shape
 should hold at least 300 ml liquid
We will want to know the size of the can
which will require the minimum material.
Let the dimensions be denoted as (r, h)
5 / 10
Learning ML
Partha Dey,
PhD
Ant Colony
Optimization
Genetic
Algorithm
GA operators
Flowcharts
R Codes
Acknowledge
Another Optimization Problem
A can needs to be manufactured which is :
 cylindrical in shape
 should hold at least 300 ml liquid
We will want to know the size of the can
which will require the minimum material.
Let the dimensions be denoted as (r, h)
(3, 11)
5 / 10
Learning ML
Partha Dey,
PhD
Ant Colony
Optimization
Genetic
Algorithm
GA operators
Flowcharts
R Codes
Acknowledge
Another Optimization Problem
A can needs to be manufactured which is :
 cylindrical in shape
 should hold at least 300 ml liquid
We will want to know the size of the can
which will require the minimum material.
Let the dimensions be denoted as (r, h)
(4, 6)
5 / 10
Learning ML
Partha Dey,
PhD
Ant Colony
Optimization
Genetic
Algorithm
GA operators
Flowcharts
R Codes
Acknowledge
Another Optimization Problem
A can needs to be manufactured which is :
 cylindrical in shape
 should hold at least 300 ml liquid
We will want to know the size of the can
which will require the minimum material.
Let the dimensions be denoted as (r, h)
(3.6, 7.5)
5 / 10
Learning ML
Partha Dey,
PhD
Ant Colony
Optimization
Genetic
Algorithm
GA operators
Flowcharts
R Codes
Acknowledge
Another Optimization Problem
A can needs to be manufactured which is :
 cylindrical in shape
 should hold at least 300 ml liquid
We will want to know the size of the can
which will require the minimum material.
Let the dimensions be denoted as (r, h)
(3.6, 7.5)
Hence, we minimize A = 2πrh + 2πr2
subject to V = πr2
h ≥ 300
5 / 10
Learning ML
Partha Dey,
PhD
Ant Colony
Optimization
Genetic
Algorithm
GA operators
Flowcharts
R Codes
Acknowledge
Another Optimization Problem
A can needs to be manufactured which is :
 cylindrical in shape
 should hold at least 300 ml liquid
We will want to know the size of the can
which will require the minimum material.
Let the dimensions be denoted as (r, h)
(3.6, 7.5)
Hence, we minimize A = 2πrh + 2πr2
subject to V = πr2
h ≥ 300
We ‘encode’ the two
dimensions (r and h)
in the form of a gene
5 / 10
Learning ML
Partha Dey,
PhD
Ant Colony
Optimization
Genetic
Algorithm
GA operators
Flowcharts
R Codes
Acknowledge
Another Optimization Problem
A can needs to be manufactured which is :
 cylindrical in shape
 should hold at least 300 ml liquid
We will want to know the size of the can
which will require the minimum material.
Let the dimensions be denoted as (r, h)
(3.6, 7.5)
Hence, we minimize A = 2πrh + 2πr2
subject to V = πr2
h ≥ 300
We ‘encode’ the two
dimensions (r and h)
in the form of a gene
1 0 0 1 | 1 0 1 0
# Hackers : Any principle for encoding ?
5 / 10
Learning ML
Partha Dey,
PhD
Ant Colony
Optimization
Genetic
Algorithm
GA operators
Flowcharts
R Codes
Acknowledge
Another Optimization Problem (solved with GA)
Let’s take a possible range of values of r and h :
r (coded) | h (coded)
2.5 7→ 0 0 0 0 | 5.0 7→ 0 0 0 0
2.6 7→ 0 0 0 1 | 5.5 7→ 0 0 0 1
... 7→ ... ... | ... 7→ ... ...
4.0 7→ 1 1 1 1 | 12.5 7→ 1 1 1 1
So, any can dimension, say (3.6, 7.5) could be encoded as :
6 / 10
Learning ML
Partha Dey,
PhD
Ant Colony
Optimization
Genetic
Algorithm
GA operators
Flowcharts
R Codes
Acknowledge
Another Optimization Problem (solved with GA)
Let’s take a possible range of values of r and h :
r (coded) | h (coded)
2.5 7→ 0 0 0 0 | 5.0 7→ 0 0 0 0
2.6 7→ 0 0 0 1 | 5.5 7→ 0 0 0 1
... 7→ ... ... | ... 7→ ... ...
4.0 7→ 1 1 1 1 | 12.5 7→ 1 1 1 1
So, any can dimension, say (3.6, 7.5) could be encoded as :
1 0 1 1 | 0 1 0 1
6 / 10
Learning ML
Partha Dey,
PhD
Ant Colony
Optimization
Genetic
Algorithm
GA operators
Flowcharts
R Codes
Acknowledge
Another Optimization Problem (solved with GA)
Let’s take a possible range of values of r and h :
r (coded) | h (coded)
2.5 7→ 0 0 0 0 | 5.0 7→ 0 0 0 0
2.6 7→ 0 0 0 1 | 5.5 7→ 0 0 0 1
... 7→ ... ... | ... 7→ ... ...
4.0 7→ 1 1 1 1 | 12.5 7→ 1 1 1 1
or, say (4, 6) would be encoded as :
1 1 1 1 | 0 0 1 0
6 / 10
Learning ML
Partha Dey,
PhD
Ant Colony
Optimization
Genetic
Algorithm
GA operators
Flowcharts
R Codes
Acknowledge
The Genetic Operators
Let’s take these two encoded strings, viz. :
1 0 1 1 0 1 1 0
1 1 1 1 0 0 1 0
7 / 10
Learning ML
Partha Dey,
PhD
Ant Colony
Optimization
Genetic
Algorithm
GA operators
Flowcharts
R Codes
Acknowledge
The Genetic Operators
Let’s take these two encoded strings, viz. :
1 0 1 1 0 1 1 0
×
1 1 1 1 0 0 1 0
We choose a crossover point,
7 / 10
Learning ML
Partha Dey,
PhD
Ant Colony
Optimization
Genetic
Algorithm
GA operators
Flowcharts
R Codes
Acknowledge
The Genetic Operators
Let’s take these two encoded strings, viz. :
1 0 1 1 0 1 1 0
×
1 1 1 1 0 0 1 0
We choose a crossover point,
across which we interchange
genetic material among parents.
7 / 10
Learning ML
Partha Dey,
PhD
Ant Colony
Optimization
Genetic
Algorithm
GA operators
Flowcharts
R Codes
Acknowledge
The Genetic Operators
Let’s take these two encoded strings, viz. :
1 0 1 1 0 1 1 0
×
1 1 1 1 0 0 1 0
1 0 1 1 0 0 1 0
1 1 1 1 0 1 1 0
We choose a crossover point,
across which we interchange
genetic material among parents.
7 / 10
Learning ML
Partha Dey,
PhD
Ant Colony
Optimization
Genetic
Algorithm
GA operators
Flowcharts
R Codes
Acknowledge
The Genetic Operators
Let’s take these two encoded strings, viz. :
1 0 1 1 0 1 1 0
×
1 1 1 1 0 0 1 0
1 0 1 1 0 0 1 0
1 1 1 1 0 1 1 0
We choose a crossover point,
across which we interchange
genetic material among parents.
→ (3.6, 6)
→ (4, 7.5)
7 / 10
Learning ML
Partha Dey,
PhD
Ant Colony
Optimization
Genetic
Algorithm
GA operators
Flowcharts
R Codes
Acknowledge
The Genetic Operators
Let’s take these two encoded strings, viz. :
1 0 1 1 0 1 1 0
×
1 1 1 1 0 0 1 0
1 0 1 1 0 0 1 0
1 1 1 1 0 1 1 0
We choose a crossover point,
across which we interchange
genetic material among parents.
Thus new solutions are born
inheriting characteristics
from both parents.
7 / 10
Learning ML
Partha Dey,
PhD
Ant Colony
Optimization
Genetic
Algorithm
GA operators
Flowcharts
R Codes
Acknowledge
The Genetic Operators
Let’s take these two encoded strings, viz. :
1 0 1 1 0 1 1 0
×
1 1 1 1 0 0 1 0
1 0 1 1 0 0 1 0
1 1 1 1 0 1 1 0
We choose a crossover point,
across which we interchange
genetic material among parents.
Thus new solutions are born
inheriting characteristics
from both parents.
7 / 10
Learning ML
Partha Dey,
PhD
Ant Colony
Optimization
Genetic
Algorithm
GA operators
Flowcharts
R Codes
Acknowledge
The Genetic Operators
Let’s take these two encoded strings, viz. :
1 0 1 1 0 1 1 0
×
1 1 1 1 0 0 1 0
1 0 1 1 0 0 1 0
1 1 1 1 0 1 1 0
1 1 1 1 0 1 1 0
We choose a crossover point,
across which we interchange
genetic material among parents.
Thus new solutions are born
inheriting characteristics
from both parents.
Sometimes,
7 / 10
Learning ML
Partha Dey,
PhD
Ant Colony
Optimization
Genetic
Algorithm
GA operators
Flowcharts
R Codes
Acknowledge
The Genetic Operators
Let’s take these two encoded strings, viz. :
1 0 1 1 0 1 1 0
×
1 1 1 1 0 0 1 0
1 0 1 1 0 0 1 0
1 1 1 1 0 1 1 0
1 1 1 1 0 1 1 0
We choose a crossover point,
across which we interchange
genetic material among parents.
Thus new solutions are born
inheriting characteristics
from both parents.
Sometimes, a random bit is toggled
7 / 10
Learning ML
Partha Dey,
PhD
Ant Colony
Optimization
Genetic
Algorithm
GA operators
Flowcharts
R Codes
Acknowledge
The Genetic Operators
Let’s take these two encoded strings, viz. :
1 0 1 1 0 1 1 0
×
1 1 1 1 0 0 1 0
1 0 1 1 0 0 1 0
1 1 1 1 0 1 1 0
1 1 1 1 0 0 1 0
We choose a crossover point,
across which we interchange
genetic material among parents.
Thus new solutions are born
inheriting characteristics
from both parents.
Sometimes, a random bit is toggled
7 / 10
Learning ML
Partha Dey,
PhD
Ant Colony
Optimization
Genetic
Algorithm
GA operators
Flowcharts
R Codes
Acknowledge
The Genetic Operators
Let’s take these two encoded strings, viz. :
1 0 1 1 0 1 1 0
×
1 1 1 1 0 0 1 0
1 0 1 1 0 0 1 0
1 1 1 1 0 1 1 0
1 1 1 1 0 0 1 0
We choose a crossover point,
across which we interchange
genetic material among parents.
Thus new solutions are born
inheriting characteristics
from both parents.
Sometimes, a random bit is toggled
(to avoid stagnation of solutions)
7 / 10
Learning ML
Partha Dey,
PhD
Ant Colony
Optimization
Genetic
Algorithm
GA operators
Flowcharts
R Codes
Acknowledge
The Genetic Operators
Let’s take these two encoded strings, viz. :
1 0 1 1 0 1 1 0
×
1 1 1 1 0 0 1 0
1 0 1 1 0 0 1 0
1 1 1 1 0 1 1 0
1 1 1 1 0 0 1 0
We choose a crossover point,
across which we interchange
genetic material among parents.
Thus new solutions are born
inheriting characteristics
from both parents.
Sometimes, a random bit is toggled
(to avoid stagnation of solutions)
These operators are called Crossover and Mutation.
They mimic the natural evolution phenomena.
7 / 10
Learning ML
Partha Dey,
PhD
Ant Colony
Optimization
Genetic
Algorithm
GA operators
Flowcharts
R Codes
Acknowledge
The Genetic Operators
Let’s take these two encoded strings, viz. :
1 0 1 1 0 1 1 0
×
1 1 1 1 0 0 1 0
1 0 1 1 0 0 1 0
1 1 1 1 0 1 1 0
1 1 1 1 0 0 1 0
We choose a crossover point,
across which we interchange
genetic material among parents.
Thus new solutions are born
inheriting characteristics
from both parents.
Sometimes, a random bit is toggled
(to avoid stagnation of solutions)
In each iteration (or generation), better performing solutions
are selected with higher probability. So offsprings improve.
7 / 10
Learning ML
Partha Dey,
PhD
Ant Colony
Optimization
Genetic
Algorithm
GA operators
Flowcharts
R Codes
Acknowledge
The algorithm for ACO
8 / 10
Learning ML
Partha Dey,
PhD
Ant Colony
Optimization
Genetic
Algorithm
GA operators
Flowcharts
R Codes
Acknowledge
The algorithm for GA
8 / 10
Learning ML
Partha Dey,
PhD
Ant Colony
Optimization
Genetic
Algorithm
GA operators
Flowcharts
R Codes
Acknowledge
The R code for GA
CAN - ga(type = real-valued,
fitness = function(can.dim) GA.obj(can.dim),
lower = c(2.5, 5), upper = c(4, 12.5),
popSize = 20, maxiter = 10)
GA.obj - function(rh)
{ p - 3.1416; r - rh[1]; h - rh[2]
V - p*r*r*h; A - 2*p*r*h + 2*(p*r*r)
if (r  ... | r  ...) return(-100)
if (h  ... | h  ...) return(-200)
if (V  300) return(-300)
return(1000 - A)
}
9 / 10
Learning ML
Partha Dey,
PhD
Ant Colony
Optimization
Genetic
Algorithm
GA operators
Flowcharts
R Codes
Acknowledge
Without whom this course would be impossible
Acknowledgements
10 / 10
Learning ML
Partha Dey,
PhD
Ant Colony
Optimization
Genetic
Algorithm
GA operators
Flowcharts
R Codes
Acknowledge
Without whom this course would be impossible
Acknowledgements
 Prof. J. Banerjee
10 / 10
Learning ML
Partha Dey,
PhD
Ant Colony
Optimization
Genetic
Algorithm
GA operators
Flowcharts
R Codes
Acknowledge
Without whom this course would be impossible
Acknowledgements
 Prof. J. Banerjee
 Prof. D. Bhattacharya
10 / 10
Learning ML
Partha Dey,
PhD
Ant Colony
Optimization
Genetic
Algorithm
GA operators
Flowcharts
R Codes
Acknowledge
Without whom this course would be impossible
Acknowledgements
 Prof. J. Banerjee
 Prof. D. Bhattacharya
 Prof. A. Sil
10 / 10
Learning ML
Partha Dey,
PhD
Ant Colony
Optimization
Genetic
Algorithm
GA operators
Flowcharts
R Codes
Acknowledge
Without whom this course would be impossible
Acknowledgements
 Prof. J. Banerjee
 Prof. D. Bhattacharya
 Prof. A. Sil
 Prof. D. K. Maity
10 / 10
Learning ML
Partha Dey,
PhD
Ant Colony
Optimization
Genetic
Algorithm
GA operators
Flowcharts
R Codes
Acknowledge
Without whom this course would be impossible
Acknowledgements
 Prof. J. Banerjee
 Prof. D. Bhattacharya
 Prof. A. Sil
 Prof. D. K. Maity
 Prof. A. K. Rana
10 / 10
Learning ML
Partha Dey,
PhD
Ant Colony
Optimization
Genetic
Algorithm
GA operators
Flowcharts
R Codes
Acknowledge
Without whom this course would be impossible
Acknowledgements
 Prof. J. Banerjee
 Prof. D. Bhattacharya
 Prof. A. Sil
 Prof. D. K. Maity
 Prof. A. K. Rana
 Prof. Ashoke Banerjee
10 / 10
Learning ML
Partha Dey,
PhD
Ant Colony
Optimization
Genetic
Algorithm
GA operators
Flowcharts
R Codes
Acknowledge
Without whom this course would be impossible
Acknowledgements
 Prof. J. Banerjee
 Prof. D. Bhattacharya
 Prof. A. Sil
 Prof. D. K. Maity
 Prof. A. K. Rana
 Prof. Ashoke Banerjee
 Prof. Shubhabrata Dutta
10 / 10
Learning ML
Partha Dey,
PhD
Ant Colony
Optimization
Genetic
Algorithm
GA operators
Flowcharts
R Codes
Acknowledge
Without whom this course would be impossible
Acknowledgements
 Prof. J. Banerjee
 Prof. D. Bhattacharya
 Prof. A. Sil
 Prof. D. K. Maity
 Prof. A. K. Rana
 Prof. Ashoke Banerjee
 Prof. Shubhabrata Dutta
 Prof. Kalyanmoy Deb and Prof. Marco Dorigo
10 / 10
Learning ML
Partha Dey,
PhD
Ant Colony
Optimization
Genetic
Algorithm
GA operators
Flowcharts
R Codes
Acknowledge
Without whom this course would be impossible
Acknowledgements
 Prof. J. Banerjee
 Prof. D. Bhattacharya
 Prof. A. Sil
 Prof. D. K. Maity
 Prof. A. K. Rana
 Prof. Ashoke Banerjee
 Prof. Shubhabrata Dutta
 Prof. Kalyanmoy Deb and Prof. Marco Dorigo
 All of you with your tried-and-tested patience
10 / 10

Machine Learning Lecture 5 (Genetic Algorithm)

  • 1.
    Learning ML Partha Dey, PhD AntColony Optimization Genetic Algorithm GA operators Flowcharts R Codes Acknowledge Learning Machine Learning :: Session 3 Partha Dey, PhD Dept. of Mechanical Engineering Academy of Technology 18th November 2018 1 / 10
  • 2.
    Learning ML Partha Dey, PhD AntColony Optimization Genetic Algorithm GA operators Flowcharts R Codes Acknowledge Overview 1 Ant Colony Optimization 2 Genetic Algorithm Genetic Operators 3 The ACO/GA flowchart 4 The ACO/GA code 5 Acknowledgements 2 / 10
  • 3.
    Learning ML Partha Dey, PhD AntColony Optimization Genetic Algorithm GA operators Flowcharts R Codes Acknowledge Travelling Salesman Problem (TSP) A salesperson has been given the assignment to visit . Bengaluru, . Guwahati, . Chennai and . Mumbai, from Kolkata and come back to her hometown. . . along the shortest route 3 / 10
  • 4.
    Learning ML Partha Dey, PhD AntColony Optimization Genetic Algorithm GA operators Flowcharts R Codes Acknowledge Travelling Salesman Problem (TSP) A salesperson has been given the assignment to visit . Bengaluru, . Guwahati, . Chennai and . Mumbai, from Kolkata and come back to her hometown. . . along the shortest route 3 / 10
  • 5.
    Learning ML Partha Dey, PhD AntColony Optimization Genetic Algorithm GA operators Flowcharts R Codes Acknowledge Travelling Salesman Problem (TSP) A salesperson has been given the assignment to visit . Bengaluru, . Guwahati, . Chennai and . Mumbai, from Kolkata and come back to her hometown. . . along the shortest route 3 / 10
  • 6.
    Learning ML Partha Dey, PhD AntColony Optimization Genetic Algorithm GA operators Flowcharts R Codes Acknowledge Travelling Salesman Problem (TSP) A salesperson has been given the assignment to visit . Bengaluru, . Guwahati, . Chennai and . Mumbai, from Kolkata and come back to her hometown. . . along the shortest route 3 / 10
  • 7.
    Learning ML Partha Dey, PhD AntColony Optimization Genetic Algorithm GA operators Flowcharts R Codes Acknowledge Travelling Salesman Problem (TSP) A salesperson has been given the assignment to visit . Bengaluru, . Guwahati, . Chennai and . Mumbai, from Kolkata and come back to her hometown. . . along the shortest route She first 1 finds out the inter-city distances — 3 / 10
  • 8.
    Learning ML Partha Dey, PhD AntColony Optimization Genetic Algorithm GA operators Flowcharts R Codes Acknowledge Travelling Salesman Problem (TSP) A salesperson has been given the assignment to visit . Bengaluru, . Guwahati, . Chennai and . Mumbai, from Kolkata and come back to her hometown. . . along the shortest route She first 1 finds out the inter-city distances — Kol Ben Guw Che Mum Kol Ben 1560 Guw 524 2082 Che 1356 290 1884 Mum 1654 846 1034 2088 Source : www.distancecalculator.net 3 / 10
  • 9.
    Learning ML Partha Dey, PhD AntColony Optimization Genetic Algorithm GA operators Flowcharts R Codes Acknowledge Travelling Salesman Problem (TSP) A salesperson has been given the assignment to visit . Bengaluru, . Guwahati, . Chennai and . Mumbai, from Kolkata and come back to her hometown. . . along the shortest route She first 1 finds out the inter-city distances — Kol Ben Guw Che Mum Kol Ben 1560 Guw 524 2082 Che 1356 290 1884 Mum 1654 846 1034 2088 Source : www.distancecalculator.net . . . then 2 lists down all the 4 ! ways to plan her tour, 3 / 10
  • 10.
    Learning ML Partha Dey, PhD AntColony Optimization Genetic Algorithm GA operators Flowcharts R Codes Acknowledge Travelling Salesman Problem (TSP) A salesperson has been given the assignment to visit . Bengaluru, . Guwahati, . Chennai and . Mumbai, from Kolkata and come back to her hometown. . . along the shortest route She first 1 finds out the inter-city distances — Kol Ben Guw Che Mum Kol Ben 1560 Guw 524 2082 Che 1356 290 1884 Mum 1654 846 1034 2088 Source : www.distancecalculator.net . . . then 2 lists down all the 4 ! ways to plan her tour, and finally 3 picks the shortest of them. 3 / 10
  • 11.
    Learning ML Partha Dey, PhD AntColony Optimization Genetic Algorithm GA operators Flowcharts R Codes Acknowledge Travelling Ants to solve the TSP Now, the nature-loving salesperson has a few servants whom she asks to do the trial tours for her. 4 / 10
  • 12.
    Learning ML Partha Dey, PhD AntColony Optimization Genetic Algorithm GA operators Flowcharts R Codes Acknowledge Travelling Ants to solve the TSP Now, the nature-loving salesperson has a few servants whom she asks to do the trial tours for her. As per order, 4 ants instantly start from Kolkata towards the four different cities. 4 / 10
  • 13.
    Learning ML Partha Dey, PhD AntColony Optimization Genetic Algorithm GA operators Flowcharts R Codes Acknowledge Travelling Ants to solve the TSP Now, the nature-loving salesperson has a few servants whom she asks to do the trial tours for her. As per order, 4 ants instantly start from Kolkata towards the four different cities. BOM, 4 / 10
  • 14.
    Learning ML Partha Dey, PhD AntColony Optimization Genetic Algorithm GA operators Flowcharts R Codes Acknowledge Travelling Ants to solve the TSP Now, the nature-loving salesperson has a few servants whom she asks to do the trial tours for her. As per order, 4 ants instantly start from Kolkata towards the four different cities. BOM, BLR, 4 / 10
  • 15.
    Learning ML Partha Dey, PhD AntColony Optimization Genetic Algorithm GA operators Flowcharts R Codes Acknowledge Travelling Ants to solve the TSP Now, the nature-loving salesperson has a few servants whom she asks to do the trial tours for her. As per order, 4 ants instantly start from Kolkata towards the four different cities. BOM, BLR, MAA, 4 / 10
  • 16.
    Learning ML Partha Dey, PhD AntColony Optimization Genetic Algorithm GA operators Flowcharts R Codes Acknowledge Travelling Ants to solve the TSP Now, the nature-loving salesperson has a few servants whom she asks to do the trial tours for her. As per order, 4 ants instantly start from Kolkata towards the four different cities. BOM, BLR, MAA, GAU 4 / 10
  • 17.
    Learning ML Partha Dey, PhD AntColony Optimization Genetic Algorithm GA operators Flowcharts R Codes Acknowledge Travelling Ants to solve the TSP Now, the nature-loving salesperson has a few servants whom she asks to do the trial tours for her. As per order, 4 ants instantly start from Kolkata towards the four different cities. Each ant completes a tour and is Rewarded ∝ 1 tour distance 4 / 10
  • 18.
    Learning ML Partha Dey, PhD AntColony Optimization Genetic Algorithm GA operators Flowcharts R Codes Acknowledge Travelling Ants to solve the TSP Now, the nature-loving salesperson has a few servants whom she asks to do the trial tours for her. As per order, 4 ants instantly start from Kolkata towards the four different cities. Each ant completes a tour and is Rewarded ∝ 1 tour distance They continue this quite a few number of times, each time depositing some pheromone proportional to its reward. 4 / 10
  • 19.
    Learning ML Partha Dey, PhD AntColony Optimization Genetic Algorithm GA operators Flowcharts R Codes Acknowledge Travelling Ants to solve the TSP Now, the nature-loving salesperson has a few servants whom she asks to do the trial tours for her. As per order, 4 ants instantly start from Kolkata towards the four different cities. Each ant completes a tour and is Rewarded ∝ 1 tour distance They continue this quite a few number of times, each time depositing some pheromone proportional to its reward. The next ants follow stronger pheromone trail. . . 4 / 10
  • 20.
    Learning ML Partha Dey, PhD AntColony Optimization Genetic Algorithm GA operators Flowcharts R Codes Acknowledge Travelling Ants to solve the TSP Now, the nature-loving salesperson has a few servants whom she asks to do the trial tours for her. As per order, 4 ants instantly start from Kolkata towards the four different cities. Each ant completes a tour and is Rewarded ∝ 1 tour distance They continue this quite a few number of times, each time depositing some pheromone proportional to its reward. The next ants follow stronger pheromone trail. . . . . . weaker untraversed trails . . . . . . 4 / 10
  • 21.
    Learning ML Partha Dey, PhD AntColony Optimization Genetic Algorithm GA operators Flowcharts R Codes Acknowledge Travelling Ants to solve the TSP Now, the nature-loving salesperson has a few servants whom she asks to do the trial tours for her. As per order, 4 ants instantly start from Kolkata towards the four different cities. Each ant completes a tour and is Rewarded ∝ 1 tour distance They continue this quite a few number of times, each time depositing some pheromone proportional to its reward. The next ants follow stronger pheromone trail. . . . . . weaker untraversed trails . . . . . . evaporate fast 4 / 10
  • 22.
    Learning ML Partha Dey, PhD AntColony Optimization Genetic Algorithm GA operators Flowcharts R Codes Acknowledge Travelling Ants to solve the TSP Now, the nature-loving salesperson has a few servants whom she asks to do the trial tours for her. As per order, 4 ants instantly start from Kolkata towards the four different cities. Each ant completes a tour and is Rewarded ∝ 1 tour distance They continue this quite a few number of times, each time depositing some pheromone proportional to its reward. The next ants follow stronger pheromone trail. . . . . . showing the way to an optimized path. . . 4 / 10
  • 23.
    Learning ML Partha Dey, PhD AntColony Optimization Genetic Algorithm GA operators Flowcharts R Codes Acknowledge Travelling Ants to solve the TSP Now, the nature-loving salesperson has a few servants whom she asks to do the trial tours for her. As per order, 4 ants instantly start from Kolkata towards the four different cities. Each ant completes a tour and is Rewarded ∝ 1 tour distance They continue this quite a few number of times, each time depositing some pheromone proportional to its reward. The next ants follow stronger pheromone trail. . . . . . showing the way to an optimized path. . . for our actual tranveller to follow 4 / 10
  • 24.
    Learning ML Partha Dey, PhD AntColony Optimization Genetic Algorithm GA operators Flowcharts R Codes Acknowledge Travelling Ants to solve the TSP Now, the nature-loving salesperson has a few servants whom she asks to do the trial tours for her. As per order, 4 ants instantly start from Kolkata towards the four different cities. Each ant completes a tour and is Rewarded ∝ 1 tour distance They continue this quite a few number of times, each time depositing some pheromone proportional to its reward. The next ants follow stronger pheromone trail. . . . . . showing the way to an optimized path. . . for our actual tranveller to follow, without doing sort(4 ! sums) 4 / 10
  • 25.
    Learning ML Partha Dey, PhD AntColony Optimization Genetic Algorithm GA operators Flowcharts R Codes Acknowledge Another Optimization Problem A can needs to be manufactured which is : cylindrical in shape should hold at least 300 ml liquid We will want to know the size of the can which will require the minimum material. Let the dimensions be denoted as (r, h) 5 / 10
  • 26.
    Learning ML Partha Dey, PhD AntColony Optimization Genetic Algorithm GA operators Flowcharts R Codes Acknowledge Another Optimization Problem A can needs to be manufactured which is : cylindrical in shape should hold at least 300 ml liquid We will want to know the size of the can which will require the minimum material. Let the dimensions be denoted as (r, h) (3, 11) 5 / 10
  • 27.
    Learning ML Partha Dey, PhD AntColony Optimization Genetic Algorithm GA operators Flowcharts R Codes Acknowledge Another Optimization Problem A can needs to be manufactured which is : cylindrical in shape should hold at least 300 ml liquid We will want to know the size of the can which will require the minimum material. Let the dimensions be denoted as (r, h) (4, 6) 5 / 10
  • 28.
    Learning ML Partha Dey, PhD AntColony Optimization Genetic Algorithm GA operators Flowcharts R Codes Acknowledge Another Optimization Problem A can needs to be manufactured which is : cylindrical in shape should hold at least 300 ml liquid We will want to know the size of the can which will require the minimum material. Let the dimensions be denoted as (r, h) (3.6, 7.5) 5 / 10
  • 29.
    Learning ML Partha Dey, PhD AntColony Optimization Genetic Algorithm GA operators Flowcharts R Codes Acknowledge Another Optimization Problem A can needs to be manufactured which is : cylindrical in shape should hold at least 300 ml liquid We will want to know the size of the can which will require the minimum material. Let the dimensions be denoted as (r, h) (3.6, 7.5) Hence, we minimize A = 2πrh + 2πr2 subject to V = πr2 h ≥ 300 5 / 10
  • 30.
    Learning ML Partha Dey, PhD AntColony Optimization Genetic Algorithm GA operators Flowcharts R Codes Acknowledge Another Optimization Problem A can needs to be manufactured which is : cylindrical in shape should hold at least 300 ml liquid We will want to know the size of the can which will require the minimum material. Let the dimensions be denoted as (r, h) (3.6, 7.5) Hence, we minimize A = 2πrh + 2πr2 subject to V = πr2 h ≥ 300 We ‘encode’ the two dimensions (r and h) in the form of a gene 5 / 10
  • 31.
    Learning ML Partha Dey, PhD AntColony Optimization Genetic Algorithm GA operators Flowcharts R Codes Acknowledge Another Optimization Problem A can needs to be manufactured which is : cylindrical in shape should hold at least 300 ml liquid We will want to know the size of the can which will require the minimum material. Let the dimensions be denoted as (r, h) (3.6, 7.5) Hence, we minimize A = 2πrh + 2πr2 subject to V = πr2 h ≥ 300 We ‘encode’ the two dimensions (r and h) in the form of a gene 1 0 0 1 | 1 0 1 0 # Hackers : Any principle for encoding ? 5 / 10
  • 32.
    Learning ML Partha Dey, PhD AntColony Optimization Genetic Algorithm GA operators Flowcharts R Codes Acknowledge Another Optimization Problem (solved with GA) Let’s take a possible range of values of r and h : r (coded) | h (coded) 2.5 7→ 0 0 0 0 | 5.0 7→ 0 0 0 0 2.6 7→ 0 0 0 1 | 5.5 7→ 0 0 0 1 ... 7→ ... ... | ... 7→ ... ... 4.0 7→ 1 1 1 1 | 12.5 7→ 1 1 1 1 So, any can dimension, say (3.6, 7.5) could be encoded as : 6 / 10
  • 33.
    Learning ML Partha Dey, PhD AntColony Optimization Genetic Algorithm GA operators Flowcharts R Codes Acknowledge Another Optimization Problem (solved with GA) Let’s take a possible range of values of r and h : r (coded) | h (coded) 2.5 7→ 0 0 0 0 | 5.0 7→ 0 0 0 0 2.6 7→ 0 0 0 1 | 5.5 7→ 0 0 0 1 ... 7→ ... ... | ... 7→ ... ... 4.0 7→ 1 1 1 1 | 12.5 7→ 1 1 1 1 So, any can dimension, say (3.6, 7.5) could be encoded as : 1 0 1 1 | 0 1 0 1 6 / 10
  • 34.
    Learning ML Partha Dey, PhD AntColony Optimization Genetic Algorithm GA operators Flowcharts R Codes Acknowledge Another Optimization Problem (solved with GA) Let’s take a possible range of values of r and h : r (coded) | h (coded) 2.5 7→ 0 0 0 0 | 5.0 7→ 0 0 0 0 2.6 7→ 0 0 0 1 | 5.5 7→ 0 0 0 1 ... 7→ ... ... | ... 7→ ... ... 4.0 7→ 1 1 1 1 | 12.5 7→ 1 1 1 1 or, say (4, 6) would be encoded as : 1 1 1 1 | 0 0 1 0 6 / 10
  • 35.
    Learning ML Partha Dey, PhD AntColony Optimization Genetic Algorithm GA operators Flowcharts R Codes Acknowledge The Genetic Operators Let’s take these two encoded strings, viz. : 1 0 1 1 0 1 1 0 1 1 1 1 0 0 1 0 7 / 10
  • 36.
    Learning ML Partha Dey, PhD AntColony Optimization Genetic Algorithm GA operators Flowcharts R Codes Acknowledge The Genetic Operators Let’s take these two encoded strings, viz. : 1 0 1 1 0 1 1 0 × 1 1 1 1 0 0 1 0 We choose a crossover point, 7 / 10
  • 37.
    Learning ML Partha Dey, PhD AntColony Optimization Genetic Algorithm GA operators Flowcharts R Codes Acknowledge The Genetic Operators Let’s take these two encoded strings, viz. : 1 0 1 1 0 1 1 0 × 1 1 1 1 0 0 1 0 We choose a crossover point, across which we interchange genetic material among parents. 7 / 10
  • 38.
    Learning ML Partha Dey, PhD AntColony Optimization Genetic Algorithm GA operators Flowcharts R Codes Acknowledge The Genetic Operators Let’s take these two encoded strings, viz. : 1 0 1 1 0 1 1 0 × 1 1 1 1 0 0 1 0 1 0 1 1 0 0 1 0 1 1 1 1 0 1 1 0 We choose a crossover point, across which we interchange genetic material among parents. 7 / 10
  • 39.
    Learning ML Partha Dey, PhD AntColony Optimization Genetic Algorithm GA operators Flowcharts R Codes Acknowledge The Genetic Operators Let’s take these two encoded strings, viz. : 1 0 1 1 0 1 1 0 × 1 1 1 1 0 0 1 0 1 0 1 1 0 0 1 0 1 1 1 1 0 1 1 0 We choose a crossover point, across which we interchange genetic material among parents. → (3.6, 6) → (4, 7.5) 7 / 10
  • 40.
    Learning ML Partha Dey, PhD AntColony Optimization Genetic Algorithm GA operators Flowcharts R Codes Acknowledge The Genetic Operators Let’s take these two encoded strings, viz. : 1 0 1 1 0 1 1 0 × 1 1 1 1 0 0 1 0 1 0 1 1 0 0 1 0 1 1 1 1 0 1 1 0 We choose a crossover point, across which we interchange genetic material among parents. Thus new solutions are born inheriting characteristics from both parents. 7 / 10
  • 41.
    Learning ML Partha Dey, PhD AntColony Optimization Genetic Algorithm GA operators Flowcharts R Codes Acknowledge The Genetic Operators Let’s take these two encoded strings, viz. : 1 0 1 1 0 1 1 0 × 1 1 1 1 0 0 1 0 1 0 1 1 0 0 1 0 1 1 1 1 0 1 1 0 We choose a crossover point, across which we interchange genetic material among parents. Thus new solutions are born inheriting characteristics from both parents. 7 / 10
  • 42.
    Learning ML Partha Dey, PhD AntColony Optimization Genetic Algorithm GA operators Flowcharts R Codes Acknowledge The Genetic Operators Let’s take these two encoded strings, viz. : 1 0 1 1 0 1 1 0 × 1 1 1 1 0 0 1 0 1 0 1 1 0 0 1 0 1 1 1 1 0 1 1 0 1 1 1 1 0 1 1 0 We choose a crossover point, across which we interchange genetic material among parents. Thus new solutions are born inheriting characteristics from both parents. Sometimes, 7 / 10
  • 43.
    Learning ML Partha Dey, PhD AntColony Optimization Genetic Algorithm GA operators Flowcharts R Codes Acknowledge The Genetic Operators Let’s take these two encoded strings, viz. : 1 0 1 1 0 1 1 0 × 1 1 1 1 0 0 1 0 1 0 1 1 0 0 1 0 1 1 1 1 0 1 1 0 1 1 1 1 0 1 1 0 We choose a crossover point, across which we interchange genetic material among parents. Thus new solutions are born inheriting characteristics from both parents. Sometimes, a random bit is toggled 7 / 10
  • 44.
    Learning ML Partha Dey, PhD AntColony Optimization Genetic Algorithm GA operators Flowcharts R Codes Acknowledge The Genetic Operators Let’s take these two encoded strings, viz. : 1 0 1 1 0 1 1 0 × 1 1 1 1 0 0 1 0 1 0 1 1 0 0 1 0 1 1 1 1 0 1 1 0 1 1 1 1 0 0 1 0 We choose a crossover point, across which we interchange genetic material among parents. Thus new solutions are born inheriting characteristics from both parents. Sometimes, a random bit is toggled 7 / 10
  • 45.
    Learning ML Partha Dey, PhD AntColony Optimization Genetic Algorithm GA operators Flowcharts R Codes Acknowledge The Genetic Operators Let’s take these two encoded strings, viz. : 1 0 1 1 0 1 1 0 × 1 1 1 1 0 0 1 0 1 0 1 1 0 0 1 0 1 1 1 1 0 1 1 0 1 1 1 1 0 0 1 0 We choose a crossover point, across which we interchange genetic material among parents. Thus new solutions are born inheriting characteristics from both parents. Sometimes, a random bit is toggled (to avoid stagnation of solutions) 7 / 10
  • 46.
    Learning ML Partha Dey, PhD AntColony Optimization Genetic Algorithm GA operators Flowcharts R Codes Acknowledge The Genetic Operators Let’s take these two encoded strings, viz. : 1 0 1 1 0 1 1 0 × 1 1 1 1 0 0 1 0 1 0 1 1 0 0 1 0 1 1 1 1 0 1 1 0 1 1 1 1 0 0 1 0 We choose a crossover point, across which we interchange genetic material among parents. Thus new solutions are born inheriting characteristics from both parents. Sometimes, a random bit is toggled (to avoid stagnation of solutions) These operators are called Crossover and Mutation. They mimic the natural evolution phenomena. 7 / 10
  • 47.
    Learning ML Partha Dey, PhD AntColony Optimization Genetic Algorithm GA operators Flowcharts R Codes Acknowledge The Genetic Operators Let’s take these two encoded strings, viz. : 1 0 1 1 0 1 1 0 × 1 1 1 1 0 0 1 0 1 0 1 1 0 0 1 0 1 1 1 1 0 1 1 0 1 1 1 1 0 0 1 0 We choose a crossover point, across which we interchange genetic material among parents. Thus new solutions are born inheriting characteristics from both parents. Sometimes, a random bit is toggled (to avoid stagnation of solutions) In each iteration (or generation), better performing solutions are selected with higher probability. So offsprings improve. 7 / 10
  • 48.
    Learning ML Partha Dey, PhD AntColony Optimization Genetic Algorithm GA operators Flowcharts R Codes Acknowledge The algorithm for ACO 8 / 10
  • 49.
    Learning ML Partha Dey, PhD AntColony Optimization Genetic Algorithm GA operators Flowcharts R Codes Acknowledge The algorithm for GA 8 / 10
  • 50.
    Learning ML Partha Dey, PhD AntColony Optimization Genetic Algorithm GA operators Flowcharts R Codes Acknowledge The R code for GA CAN - ga(type = real-valued, fitness = function(can.dim) GA.obj(can.dim), lower = c(2.5, 5), upper = c(4, 12.5), popSize = 20, maxiter = 10) GA.obj - function(rh) { p - 3.1416; r - rh[1]; h - rh[2] V - p*r*r*h; A - 2*p*r*h + 2*(p*r*r) if (r ... | r ...) return(-100) if (h ... | h ...) return(-200) if (V 300) return(-300) return(1000 - A) } 9 / 10
  • 51.
    Learning ML Partha Dey, PhD AntColony Optimization Genetic Algorithm GA operators Flowcharts R Codes Acknowledge Without whom this course would be impossible Acknowledgements 10 / 10
  • 52.
    Learning ML Partha Dey, PhD AntColony Optimization Genetic Algorithm GA operators Flowcharts R Codes Acknowledge Without whom this course would be impossible Acknowledgements Prof. J. Banerjee 10 / 10
  • 53.
    Learning ML Partha Dey, PhD AntColony Optimization Genetic Algorithm GA operators Flowcharts R Codes Acknowledge Without whom this course would be impossible Acknowledgements Prof. J. Banerjee Prof. D. Bhattacharya 10 / 10
  • 54.
    Learning ML Partha Dey, PhD AntColony Optimization Genetic Algorithm GA operators Flowcharts R Codes Acknowledge Without whom this course would be impossible Acknowledgements Prof. J. Banerjee Prof. D. Bhattacharya Prof. A. Sil 10 / 10
  • 55.
    Learning ML Partha Dey, PhD AntColony Optimization Genetic Algorithm GA operators Flowcharts R Codes Acknowledge Without whom this course would be impossible Acknowledgements Prof. J. Banerjee Prof. D. Bhattacharya Prof. A. Sil Prof. D. K. Maity 10 / 10
  • 56.
    Learning ML Partha Dey, PhD AntColony Optimization Genetic Algorithm GA operators Flowcharts R Codes Acknowledge Without whom this course would be impossible Acknowledgements Prof. J. Banerjee Prof. D. Bhattacharya Prof. A. Sil Prof. D. K. Maity Prof. A. K. Rana 10 / 10
  • 57.
    Learning ML Partha Dey, PhD AntColony Optimization Genetic Algorithm GA operators Flowcharts R Codes Acknowledge Without whom this course would be impossible Acknowledgements Prof. J. Banerjee Prof. D. Bhattacharya Prof. A. Sil Prof. D. K. Maity Prof. A. K. Rana Prof. Ashoke Banerjee 10 / 10
  • 58.
    Learning ML Partha Dey, PhD AntColony Optimization Genetic Algorithm GA operators Flowcharts R Codes Acknowledge Without whom this course would be impossible Acknowledgements Prof. J. Banerjee Prof. D. Bhattacharya Prof. A. Sil Prof. D. K. Maity Prof. A. K. Rana Prof. Ashoke Banerjee Prof. Shubhabrata Dutta 10 / 10
  • 59.
    Learning ML Partha Dey, PhD AntColony Optimization Genetic Algorithm GA operators Flowcharts R Codes Acknowledge Without whom this course would be impossible Acknowledgements Prof. J. Banerjee Prof. D. Bhattacharya Prof. A. Sil Prof. D. K. Maity Prof. A. K. Rana Prof. Ashoke Banerjee Prof. Shubhabrata Dutta Prof. Kalyanmoy Deb and Prof. Marco Dorigo 10 / 10
  • 60.
    Learning ML Partha Dey, PhD AntColony Optimization Genetic Algorithm GA operators Flowcharts R Codes Acknowledge Without whom this course would be impossible Acknowledgements Prof. J. Banerjee Prof. D. Bhattacharya Prof. A. Sil Prof. D. K. Maity Prof. A. K. Rana Prof. Ashoke Banerjee Prof. Shubhabrata Dutta Prof. Kalyanmoy Deb and Prof. Marco Dorigo All of you with your tried-and-tested patience 10 / 10