SlideShare a Scribd company logo
1 of 131
Download to read offline
Nature-inspired algorithms
Lars Marius Garshol, lars.marius.garshol@schibsted.com
http://twitter.com/larsga
2017–09–14, Oslo
The problem
2
The problem
• You need to tune something
• a database
• a search engine
• a machine learning solution
• …
2
The problem
• You need to tune something
• a database
• a search engine
• a machine learning solution
• …
• Getting good results is important
• but there’s lots of values to tune
• the effects of tuning them are hard to predict
2
Database tuning
3Automatic database management system tuning through large-scale machine learning Aken et al. , SIGMOD’17
Find the best pair
4
Effects of MySQL tuning
Config settings
5
How to solve
6
How to solve
1. Formulate the problem clearly
6
How to solve
1. Formulate the problem clearly
2. Measure results properly
6
How to solve
1. Formulate the problem clearly
2. Measure results properly
3. Then
• try to understand the problem in depth, and/or
• let your computer find a good solution
6
Our kind of problem
7
Our kind of problem
• If
• all your knobs are numeric and
• you can measure how good a given set of settings is
7
Our kind of problem
• If
• all your knobs are numeric and
• you can measure how good a given set of settings is
• then
• basically you’re trying to find the highest point in a many-
dimensional space
7
Our kind of problem
• If
• all your knobs are numeric and
• you can measure how good a given set of settings is
• then
• basically you’re trying to find the highest point in a many-
dimensional space
• One dimension per knob + 1 dimension for
evaluation function
7
The hill-climbing problem
8
The hill-climbing problem
8
The hill-climbing problem
8
Explore vs
Exploit
A warning!
• Be very, very careful about the evaluation function
• Your algorithm will produce a good value for the
evaluation function
• If the function matches poorly with what you
actually need, you’re going to work hard to produce
something bad …
9
Genetic algorithm
10
Genetic algorithm
• The “original” nature-inspired algorithm (1960s)
• make n random solutions
• evaluate them, throw away the worst, duplicate the best
• add random newcomers
• make random changes, repeat
10
Genetic algorithm
• The “original” nature-inspired algorithm (1960s)
• make n random solutions
• evaluate them, throw away the worst, duplicate the best
• add random newcomers
• make random changes, repeat
10
Exploit
Genetic algorithm
• The “original” nature-inspired algorithm (1960s)
• make n random solutions
• evaluate them, throw away the worst, duplicate the best
• add random newcomers
• make random changes, repeat
10
Exploit
Explore
Genetic algorithm
• The “original” nature-inspired algorithm (1960s)
• make n random solutions
• evaluate them, throw away the worst, duplicate the best
• add random newcomers
• make random changes, repeat
• Weakness: can’t exploit structure of numeric problems
• no sense of hyperspace
10
Exploit
Explore
Genetic algorithm
• The “original” nature-inspired algorithm (1960s)
• make n random solutions
• evaluate them, throw away the worst, duplicate the best
• add random newcomers
• make random changes, repeat
• Weakness: can’t exploit structure of numeric problems
• no sense of hyperspace
• Strength: can solve non-numeric problems
• can even write code
10
Exploit
Explore
Particle-swarm
optimization (1995)
• A swarm of particles explore the search space
together
• move around semi-randomly
• communicate about what they’ve seen
• particles attracted toward high spots in the landscape
11
PSO, initialization
• Use 10 + int(2 * math.sqrt(dimensions))
particles
• Position each particle randomly
• Give each particle a random velocity
12
PSO, iteration
13
PSO, iteration
• For each particle, in each dimension, update the
velocity by adding
13
PSO, iteration
• For each particle, in each dimension, update the
velocity by adding
• old velocity * decay factor
13
PSO, iteration
• For each particle, in each dimension, update the
velocity by adding
• old velocity * decay factor
• random factor * (best position - current position)
13
PSO, iteration
• For each particle, in each dimension, update the
velocity by adding
• old velocity * decay factor
• random factor * (best position - current position)
• random factor * (best neighbour position - current position)
13
PSO, iteration
• For each particle, in each dimension, update the
velocity by adding
• old velocity * decay factor
• random factor * (best position - current position)
• random factor * (best neighbour position - current position)
• Velocity tends to decrease as
13
PSO, iteration
• For each particle, in each dimension, update the
velocity by adding
• old velocity * decay factor
• random factor * (best position - current position)
• random factor * (best neighbour position - current position)
• Velocity tends to decrease as
• current position goes toward best position and
13
PSO, iteration
• For each particle, in each dimension, update the
velocity by adding
• old velocity * decay factor
• random factor * (best position - current position)
• random factor * (best neighbour position - current position)
• Velocity tends to decrease as
• current position goes toward best position and
• best and best neighbour position converge
13
Code
def f1(x):
return 1 + math.sin(2 * np.pi * x)
def f2a(x):
return x ** 3 - 2 * x ** 2 + 1 * x - 1
def f(x):
return f1(x) + f2a(x)
swarm = pso.Swarm(
dimensions = [(0.0, 2.0)],
fitness = lambda x: f(x[0]),
particles = 5
)
for ix in range(20):
swarm.iterate()
print swarm.get_best_ever()
14
Implementation
class Particle:
def __init__(self, dimensions, fitness):
self._dimensions = dimensions
self._fitness = fitness
self._vel = [pick_velocity(min, max) for (min, max) in dimensions]
def iterate(self):
for ix in range(len(self._dimensions)):
self._vel[ix] = (
self._vel[ix] * w +
random.uniform(0, c) * (self._prev_best_pos[ix] - self._pos[ix]) +
random.uniform(0, c) * (self.neighbourhood_best(ix) - self._pos[ix])
)
self._pos[ix] += self._vel[ix]
self._constrain(ix)
self._update()
15
Failure
16
Failure
16
Failure
16
Failure
16
Failure
16
Failure
16
Failure
16
Failure
16
Failure
16
Stuck at local maximum
Failure
16
Stuck at local maximum
Failure
16
Stuck at local maximum
Failure
16
Stuck at local maximum
Success
17
Success
17
Success
17
Success
17
Success
17
Success
17
Success
17
Success
17
Success
17
Evaluation
18
1.14104381602
2.0
1.14104055169
1.14104347433
2.0
1.1410413438
2.0
2.0
1.14104338772
2.0
2.0
2.0
2.0
1.14091395333
2.0
2.0
2.0
2.0
2.0
1.54853512969
1.41797678323
1.95856547819
1.96104312889
1.97134000263
1.77291733994
1.89848029636
1.78709716124
1.87083300112
1.94696318783
1.92667787259
1.88582583083
1.99492413725
1.95307959097
1.84557417213
1.93746433855
1.88898766983
1.80740253329
1.99788027783
PSO
Average: 1.7 Average: 1.9
Random
Enough toy problems
Let’s try a real problem
Problem: Find the duplicates
20
ID SOURCE NAME ADDRESS1 ADDRESS2 ADDRESS3 CITY ZIP
9354686 1300001 Augustin
C. Sundts Gate
22-24 Bergen 5004 8007
9316306 1300006 AUGUSTIN C. SUNDSGATE 22 5004 BERGEN NORWAY BGO
9025453 1300010 Augustin Hotel C. Sundts gate 22 Bergen 5004
9151327 1300010 Basic Hotel Bergen Hakonsgaten 27 Bergen 5015
9150992 1300010 Basic Hotel Marken Kong Oscars gate 45 Bergen 5017
9048595 1300010 Basic Hotel Victoria Kong Oscars Gate 29 Bergen 5017
9151853 1300010 Bergen Bed & Breakfast Hennebysmauet 9 Bergen 5005
9316307 1300006 BERGEN TRAVEL VESTRE TORGGATE 7 5015 BERGEN NORWAY BGO
9062459 1300010 Bergen Travel Hotel Vestre Torggaten 7 Bergen 5015
9010488 1300001 Best Western Hordaheimen C. Sundtsgt. 18 5004
9316314 1300006 BEST WESTERN HORDAHEIMEN C. SUNDTSGATE 18 BERGEN NORWAY 5004 BERGEN BGO
9032340 1300010 Best Western Hotell Hordaheimen C. Sundtsgate 18 Bergen 5004
9362760 1300001 Clarion Admiral C. Sundts Gate 9 P.o.box 252 Bergen 5004 8007
9316308 1300006 CLARION ADMIRAL C. SUNDTS GATE 9 5804 BERGEN NORWAY BGO
9364882 1300001 Clarion Admiral (Fjord View) C. Sundts Gate 9 P.o.box 252 Bergen 5004 8007
9010491 1300001 Clarion Bergen Airport Flyplassveien 555 5869
9363104 1300001 Clarion Bergen Airport Flyplassveien 555 Po Box 24 Bergen No-5869
Configure manually
21
PROPERTY COMPARATOR LOW HIGH
Name LongestCommonSubstring 0.35 0.88
Address1 WeightedLevenshtein 0.25 0.65
Address2 Levenshtein 0.5 0.6
Email Exact 0.49 0.51
Phone Exact 0.45 0.65
Geopos Geoposition 0.25 0.6
Region Exact 0.0 0.5
Threshold: 0.74
Dedup with PSO
• A 27-dimension problem
• Really difficult to solve optimally
• Takes a long time to evaluate solutions
• No idea what the best possible solution actually is
22
PSO vs random
23
Green: PSO
Blue: random
Two PSO runs
24
100 PSO runs
25
Average of 100
26
PSO vs genetic
27
Firefly algorithm
28
Xin-She Yang, 2010
Firefly algorithm
• Fireflies are positioned randomly
28
Xin-She Yang, 2010
Firefly algorithm
• Fireflies are positioned randomly
• On each iteration, each firefly jumps toward every other
firefly based on how bright it looks
• that is, the brighter the other firefly appears, the further toward it
our firefly jumps
• it only jumps toward fireflies that are brighter than itself
28
Xin-She Yang, 2010
Firefly algorithm
• Fireflies are positioned randomly
• On each iteration, each firefly jumps toward every other
firefly based on how bright it looks
• that is, the brighter the other firefly appears, the further toward it
our firefly jumps
• it only jumps toward fireflies that are brighter than itself
• Each firefly shines brighter the better its fitness is
• but attractiveness falls off with square of the distance
28
Xin-She Yang, 2010
Firefly algorithm
• Fireflies are positioned randomly
• On each iteration, each firefly jumps toward every other
firefly based on how bright it looks
• that is, the brighter the other firefly appears, the further toward it
our firefly jumps
• it only jumps toward fireflies that are brighter than itself
• Each firefly shines brighter the better its fitness is
• but attractiveness falls off with square of the distance
• Add random jiggling
28
Xin-She Yang, 2010
How it works
• The best firefly always stands still, pulling the
others toward the best result
• Bad fireflies get pulled in all directions, but good
fireflies get pulled much less
• this is exploit vs explore
• Pull diminishes with distance, so the fireflies don’t
necessarily all explore the same best position
• in order to explore more local maxima
29
Firefly code
def iterate(self):
for firefly in self._swarm.get_particles():
if self._val < firefly._val:
dist = self.distance(firefly)
attract = firefly._val / (1 + gamma * (dist ** 2))
for ix in range(len(self._dimensions)):
jiggle = alpha * (random.uniform(0, 1) - 0.5)
diff = firefly._pos[ix] - self._pos[ix]
self._pos[ix] = self._pos[ix] + jiggle + (attract * diff)
self._constrain(ix)
30
Evaluation
31
Unit is: number of fitness evaluations
to find global maximum
(Lower is better)
Taken from Yang 2010
Firefly vs PSO
32
Cuckoo search
• Very similar to genetic algorithm
• take candidate, modify it
• if better than existing candidate, replace
• Every generation, discard some proportion of
candidates
• fill up with random new ones
• The difference is in how new results are produced
• using Lévy flights
33
Yang et al. 2010
Lévy flights
34
How it works
• Balance explore and exploit with Lévy flights
• usually jump short, sometimes jump long
• Never replace good candidates by bad
• but always throw away the n worst
35
Toy problem again
36
Toy problem again
36
Toy problem again
36
Starts exploring local maximum
Toy problem again
36
Starts exploring local maximum
Toy problem again
36
Starts exploring local maximum
Toy problem again
36
Starts exploring local maximum
Toy problem again
36
Starts exploring local maximum
Toy problem again
36
Starts exploring local maximum
Toy problem again
36
Starts exploring local maximum
Toy problem again
36
Starts exploring local maximum
Toy problem again
36
Starts exploring local maximum
Toy problem again
36
Rogue cuckoo strikes gold
Starts exploring local maximum
Toy problem again
36
Rogue cuckoo strikes gold
Starts exploring local maximum
Toy problem again
36
Rogue cuckoo strikes gold
Starts exploring local maximum
Toy problem again
36
Rogue cuckoo strikes gold
Starts exploring local maximum
Toy problem again
36
Rogue cuckoo strikes gold
Starts exploring local maximum
Toy problem again
36
Rogue cuckoo strikes gold
Evaluation
37
Comparison
38
My 2015 attempt
39
Morale
• These are stochastic algorithms
• one evaluation doesn’t tell you much about the algorithm
• even 10 evaluations isn’t enough
• Be careful here, or you can fool yourself!
40
It’s not that simple
• Which PSO?
• SPSO 2006, 2007, or 2011?
• What values to use for decay factor and randomization?
• What neighbourhood topology to use?
• Firefly has parameters alpha, beta, and gamma
• Cuckoo has alpha and scale
41
Firefly, different alphas
42
So … in order to tune our algorithm we need to
tune the algorithm that tunes our algorithm
Problems
• Doing one run of Cuckoo search takes ~30 minutes
• Need to do that ~40 times to get a decent estimate
• My laptop was already getting uncomfortably hot
• My wife was complaining about the fan noise
• What to do?
44
In the cloud
45
Master
Worker
node
Worker
node
Worker
node
Worker
node
Worker
node
Worker
node
Worker
node
Worker
node
Worker
node
Worker
node
/get-task
/answer
Master algorithm
• Run PSO on Cuckoo alpha & scale
• Fitness function
• sets the task handed out by /get-task
• hangs until 20 evaluations have come in via /answer
• returns average of evaluations
46
Sunday morning
47
Sunday morning
47
First values
I tried
Monday morning
48
First values
I tried
Tuesday morning
49
More algorithms
• Flower-pollination algorithm [Xin-She Yang 2013]
• Bat-inspired algorithm [Xin-She Yang, 2010]
• Ant colony algorithm [Marco Dorigo, 1992]
• Bee algorithm [Pham et al 2005]
• Fish school search [Filho et al 2007]
• Artificial bee colony algorithm [Karaboga et al 2005]
• …
50
Looks interesting,
hard to find algorithm
Paper too vague,
can’t implement
Complicated,
didn’t finish implementation
51
PROPERTY COMPARATOR LOW HIGH
Name LongestCommonSubstring 0.35 0.88
Address1 WeightedLevenshtein 0.25 0.65
Address2 Levenshtein 0.5 0.6
Email Exact 0.49 0.51
Phone Exact 0.45 0.65
Geopos Geoposition 0.25 0.6
Region Exact 0.0 0.5
Threshold: 0.74
But what about these?
The machine learning way
52
PROPERTY COMPARATOR LOW HIGH
Name c1 c1 0.35 0.88
Name c2 c2 0.25 0.65
Name c3 c3 0.5 0.6
Name c4 c4 0.49 0.51
… … 0.45 0.65
Address1 c1 c1 0.25 0.6
Address1 c2 c2 0.0 0.5
Address1 c3 c3 … …
Address1 c4 c4 … …
… … … …
Opens a door
• Means we can drop the probabilities, and just use the
numeric values coming out of the comparators
• Feed into one of
• random forests
• Support Vector Machine (SVM)
• logistic regression
• neural networks
• …
• Except that’s no longer optimization, but attacking the
problem directly, so let’s stick with our algorithms
53
General trick
• Quite common to “cheat” this way to use numeric-
only machine learning algorithms
• Turn boolean into [0, 1] parameter
• Turn enumeration into one boolean per value
• Looks odd, but in general it does work
• of course, now there isn’t much spatial structure any more
54
Tricky, tricky
55
Tricky, tricky
• Our problem now has 267 dimensions
• should allow us to tune for really detailed signals
55
Tricky, tricky
• Our problem now has 267 dimensions
• should allow us to tune for really detailed signals
• The curse of dimensionality
• everywhere is pretty much equally far away from
everywhere else
• hyperspace consists of all corners and no middle
• many of the dimensions contain no signal
55
How it went
56
Another test
57
Any number of dimensions, this is 2
Number of local minima is d!
Performance
58
Meta-tuning again
def fitness(pos):
(firefly.alpha, firefly.gamma) = pos
averages = crap.run_experiment(
firefly,
dimensions = [(0.0, math.pi)] * 16,
fitness = function.michaelwicz,
particles = 20,
problem = 'michaelwicz',
quiet = True
)
return crap.average(averages)
dimensions = [(0.0, 1.0), (0.0, 10.0)] # alpha, gamma
swarm = pso.Swarm(dimensions, fitness, 10)
crap.evaluate(swarm, 'meta-michaelwicz-firefly')
59
It’s better…
60
Rosenbrock
61
Griewangk
62
What to choose?
• PSO
• generally performs best
• dead easy to implement
• parameters available in the literature
• no need to scale to coordinate system used
• SPSO 2007
• values for w and c are given
• ring topology: each particle knows p-1, p, p+1
63
Simulated annealing
• Inspired by the behaviour of cooling metals
• guaranteed to eventually find maximum
• no guarantee that time taken will be reasonable
• To use, requires following parameters
• Candidate neighbour generation procedure
• Acceptance probability function
• Annealing schedule
• Initial temperature
• May work better than PSO and friends, but also requires a lot
more effort to set up
64
Choices, choices
• There are always more advanced methods
• sometimes they work much better, sometimes not
• PSO gives you a dead easy place to start
• whip it up in a few lines of code
• see how it works
• vastly better than random trial and error
• adapts nicely to all kinds of problems without tuning
65
Research papers
• Publishing standards are probably too lax
• Algorithm descriptions are weak
• far too little information about tuning parameters
• no code available
• Evaluation sections are weak
• only one evaluation metric
• no information about how PSO/GA were tuned
• no information about how proposed algorithm was tuned
• no cross-comparison with other algorithms
66
See for yourself
• https://github.com/larsga/py-snippets/tree/master/
machine-learning/pso
• links to all the papers
• code for crap, genetic, pso, firefly, cuckoo
• bonus: cuckoo2, server
• also has the test functions
• Total number of experiments: 24,008
• means evaluating fitness 2,400,800 times
67

More Related Content

What's hot

Particle swarm optimization
Particle swarm optimizationParticle swarm optimization
Particle swarm optimizationanurag singh
 
Particle Swarm Optimization
Particle Swarm OptimizationParticle Swarm Optimization
Particle Swarm OptimizationQasimRehman
 
Particle Swarm Optimization
Particle Swarm OptimizationParticle Swarm Optimization
Particle Swarm OptimizationStelios Petrakis
 
Particle swarm optimization
Particle swarm optimizationParticle swarm optimization
Particle swarm optimizationSuman Chatterjee
 
Particle swarm optimization
Particle swarm optimizationParticle swarm optimization
Particle swarm optimizationMahesh Tibrewal
 
Cuckoo search
Cuckoo searchCuckoo search
Cuckoo searchG Prachi
 
Cuckoo Search Algorithm - Beyazıt Kölemen
Cuckoo Search Algorithm - Beyazıt KölemenCuckoo Search Algorithm - Beyazıt Kölemen
Cuckoo Search Algorithm - Beyazıt KölemenBeyazıt Kölemen
 
Bat algorithm and applications
Bat algorithm and applicationsBat algorithm and applications
Bat algorithm and applicationsMd.Al-imran Roton
 
Whale optimizatio algorithm
Whale optimizatio algorithmWhale optimizatio algorithm
Whale optimizatio algorithmAhmed Fouad Ali
 
Metaheuristic Algorithms: A Critical Analysis
Metaheuristic Algorithms: A Critical AnalysisMetaheuristic Algorithms: A Critical Analysis
Metaheuristic Algorithms: A Critical AnalysisXin-She Yang
 
ABC Algorithm.
ABC Algorithm.ABC Algorithm.
ABC Algorithm.N Vinayak
 
Swarm intelligence
Swarm intelligenceSwarm intelligence
Swarm intelligenceEslam Hamed
 
MACHINE LEARNING - GENETIC ALGORITHM
MACHINE LEARNING - GENETIC ALGORITHMMACHINE LEARNING - GENETIC ALGORITHM
MACHINE LEARNING - GENETIC ALGORITHMPuneet Kulyana
 
Particle Swarm Optimization by Rajorshi Mukherjee
Particle Swarm Optimization by Rajorshi MukherjeeParticle Swarm Optimization by Rajorshi Mukherjee
Particle Swarm Optimization by Rajorshi MukherjeeRajorshi Mukherjee
 
Genetic Algorithms
Genetic AlgorithmsGenetic Algorithms
Genetic Algorithmsanas_elf
 

What's hot (20)

Particle swarm optimization
Particle swarm optimizationParticle swarm optimization
Particle swarm optimization
 
Particle Swarm Optimization
Particle Swarm OptimizationParticle Swarm Optimization
Particle Swarm Optimization
 
Particle Swarm Optimization
Particle Swarm OptimizationParticle Swarm Optimization
Particle Swarm Optimization
 
Particle swarm optimization
Particle swarm optimizationParticle swarm optimization
Particle swarm optimization
 
Particle swarm optimization
Particle swarm optimizationParticle swarm optimization
Particle swarm optimization
 
Firefly algorithm
Firefly algorithmFirefly algorithm
Firefly algorithm
 
Cuckoo search
Cuckoo searchCuckoo search
Cuckoo search
 
Cuckoo Search Algorithm - Beyazıt Kölemen
Cuckoo Search Algorithm - Beyazıt KölemenCuckoo Search Algorithm - Beyazıt Kölemen
Cuckoo Search Algorithm - Beyazıt Kölemen
 
Grey wolf optimizer
Grey wolf optimizerGrey wolf optimizer
Grey wolf optimizer
 
Cuckoo search algorithm
Cuckoo search algorithmCuckoo search algorithm
Cuckoo search algorithm
 
Bat algorithm and applications
Bat algorithm and applicationsBat algorithm and applications
Bat algorithm and applications
 
Whale optimizatio algorithm
Whale optimizatio algorithmWhale optimizatio algorithm
Whale optimizatio algorithm
 
Metaheuristic Algorithms: A Critical Analysis
Metaheuristic Algorithms: A Critical AnalysisMetaheuristic Algorithms: A Critical Analysis
Metaheuristic Algorithms: A Critical Analysis
 
ABC Algorithm.
ABC Algorithm.ABC Algorithm.
ABC Algorithm.
 
bat algorithm
bat algorithmbat algorithm
bat algorithm
 
Swarm intelligence
Swarm intelligenceSwarm intelligence
Swarm intelligence
 
Metaheuristics
MetaheuristicsMetaheuristics
Metaheuristics
 
MACHINE LEARNING - GENETIC ALGORITHM
MACHINE LEARNING - GENETIC ALGORITHMMACHINE LEARNING - GENETIC ALGORITHM
MACHINE LEARNING - GENETIC ALGORITHM
 
Particle Swarm Optimization by Rajorshi Mukherjee
Particle Swarm Optimization by Rajorshi MukherjeeParticle Swarm Optimization by Rajorshi Mukherjee
Particle Swarm Optimization by Rajorshi Mukherjee
 
Genetic Algorithms
Genetic AlgorithmsGenetic Algorithms
Genetic Algorithms
 

Similar to Nature-inspired algorithms

Evolutionary Algorithms: Perfecting the Art of "Good Enough"
Evolutionary Algorithms: Perfecting the Art of "Good Enough"Evolutionary Algorithms: Perfecting the Art of "Good Enough"
Evolutionary Algorithms: Perfecting the Art of "Good Enough"PyData
 
Machine Learning on Azure - AzureConf
Machine Learning on Azure - AzureConfMachine Learning on Azure - AzureConf
Machine Learning on Azure - AzureConfSeth Juarez
 
BeyondClassicalSearch.ppt
BeyondClassicalSearch.pptBeyondClassicalSearch.ppt
BeyondClassicalSearch.pptGauravWani20
 
BeyondClassicalSearch.ppt
BeyondClassicalSearch.pptBeyondClassicalSearch.ppt
BeyondClassicalSearch.pptjpradha86
 
Understanding Basics of Machine Learning
Understanding Basics of Machine LearningUnderstanding Basics of Machine Learning
Understanding Basics of Machine LearningPranav Ainavolu
 
Nearest Neighbor Customer Insight
Nearest Neighbor Customer InsightNearest Neighbor Customer Insight
Nearest Neighbor Customer InsightMapR Technologies
 
Demystifying deep reinforement learning
Demystifying deep reinforement learningDemystifying deep reinforement learning
Demystifying deep reinforement learning재연 윤
 
Evolutionary deep learning: computer vision.
Evolutionary deep learning: computer vision.Evolutionary deep learning: computer vision.
Evolutionary deep learning: computer vision.Olivier Teytaud
 
TEXT FEUTURE SELECTION USING PARTICLE SWARM OPTIMIZATION (PSO)
TEXT FEUTURE SELECTION  USING PARTICLE SWARM OPTIMIZATION (PSO)TEXT FEUTURE SELECTION  USING PARTICLE SWARM OPTIMIZATION (PSO)
TEXT FEUTURE SELECTION USING PARTICLE SWARM OPTIMIZATION (PSO)yahye abukar
 
Simulation-based optimization: Upper Confidence Tree and Direct Policy Search
Simulation-based optimization: Upper Confidence Tree and Direct Policy SearchSimulation-based optimization: Upper Confidence Tree and Direct Policy Search
Simulation-based optimization: Upper Confidence Tree and Direct Policy SearchOlivier Teytaud
 
Erik Bernhardsson, CTO, Better Mortgage
Erik Bernhardsson, CTO, Better MortgageErik Bernhardsson, CTO, Better Mortgage
Erik Bernhardsson, CTO, Better MortgageMLconf
 
Pso kota baru parahyangan 2017
Pso kota baru parahyangan 2017Pso kota baru parahyangan 2017
Pso kota baru parahyangan 2017Iwan Sofana
 
LINEAR PROGRAMMING
LINEAR PROGRAMMINGLINEAR PROGRAMMING
LINEAR PROGRAMMINGrashi9
 

Similar to Nature-inspired algorithms (20)

Evolutionary Algorithms: Perfecting the Art of "Good Enough"
Evolutionary Algorithms: Perfecting the Art of "Good Enough"Evolutionary Algorithms: Perfecting the Art of "Good Enough"
Evolutionary Algorithms: Perfecting the Art of "Good Enough"
 
Machine Learning on Azure - AzureConf
Machine Learning on Azure - AzureConfMachine Learning on Azure - AzureConf
Machine Learning on Azure - AzureConf
 
BeyondClassicalSearch.ppt
BeyondClassicalSearch.pptBeyondClassicalSearch.ppt
BeyondClassicalSearch.ppt
 
BeyondClassicalSearch.ppt
BeyondClassicalSearch.pptBeyondClassicalSearch.ppt
BeyondClassicalSearch.ppt
 
Understanding Basics of Machine Learning
Understanding Basics of Machine LearningUnderstanding Basics of Machine Learning
Understanding Basics of Machine Learning
 
Games
GamesGames
Games
 
Bic pso
Bic psoBic pso
Bic pso
 
Nearest Neighbor Customer Insight
Nearest Neighbor Customer InsightNearest Neighbor Customer Insight
Nearest Neighbor Customer Insight
 
Demystifying deep reinforement learning
Demystifying deep reinforement learningDemystifying deep reinforement learning
Demystifying deep reinforement learning
 
Evolutionary deep learning: computer vision.
Evolutionary deep learning: computer vision.Evolutionary deep learning: computer vision.
Evolutionary deep learning: computer vision.
 
Greedy algorithm
Greedy algorithmGreedy algorithm
Greedy algorithm
 
Genetic algorithm
Genetic algorithmGenetic algorithm
Genetic algorithm
 
TEXT FEUTURE SELECTION USING PARTICLE SWARM OPTIMIZATION (PSO)
TEXT FEUTURE SELECTION  USING PARTICLE SWARM OPTIMIZATION (PSO)TEXT FEUTURE SELECTION  USING PARTICLE SWARM OPTIMIZATION (PSO)
TEXT FEUTURE SELECTION USING PARTICLE SWARM OPTIMIZATION (PSO)
 
Simulation-based optimization: Upper Confidence Tree and Direct Policy Search
Simulation-based optimization: Upper Confidence Tree and Direct Policy SearchSimulation-based optimization: Upper Confidence Tree and Direct Policy Search
Simulation-based optimization: Upper Confidence Tree and Direct Policy Search
 
Erik Bernhardsson, CTO, Better Mortgage
Erik Bernhardsson, CTO, Better MortgageErik Bernhardsson, CTO, Better Mortgage
Erik Bernhardsson, CTO, Better Mortgage
 
Pso kota baru parahyangan 2017
Pso kota baru parahyangan 2017Pso kota baru parahyangan 2017
Pso kota baru parahyangan 2017
 
introduction pso.ppt
introduction pso.pptintroduction pso.ppt
introduction pso.ppt
 
Lec10 alignment
Lec10 alignmentLec10 alignment
Lec10 alignment
 
LINEAR PROGRAMMING
LINEAR PROGRAMMINGLINEAR PROGRAMMING
LINEAR PROGRAMMING
 
DeepLearning.pdf
DeepLearning.pdfDeepLearning.pdf
DeepLearning.pdf
 

More from Lars Marius Garshol

JSLT: JSON querying and transformation
JSLT: JSON querying and transformationJSLT: JSON querying and transformation
JSLT: JSON querying and transformationLars Marius Garshol
 
Data collection in AWS at Schibsted
Data collection in AWS at SchibstedData collection in AWS at Schibsted
Data collection in AWS at SchibstedLars Marius Garshol
 
NoSQL and Einstein's theory of relativity
NoSQL and Einstein's theory of relativityNoSQL and Einstein's theory of relativity
NoSQL and Einstein's theory of relativityLars Marius Garshol
 
Using the search engine as recommendation engine
Using the search engine as recommendation engineUsing the search engine as recommendation engine
Using the search engine as recommendation engineLars Marius Garshol
 
Linked Open Data for the Cultural Sector
Linked Open Data for the Cultural SectorLinked Open Data for the Cultural Sector
Linked Open Data for the Cultural SectorLars Marius Garshol
 
NoSQL databases, the CAP theorem, and the theory of relativity
NoSQL databases, the CAP theorem, and the theory of relativityNoSQL databases, the CAP theorem, and the theory of relativity
NoSQL databases, the CAP theorem, and the theory of relativityLars Marius Garshol
 
Introduction to Big Data/Machine Learning
Introduction to Big Data/Machine LearningIntroduction to Big Data/Machine Learning
Introduction to Big Data/Machine LearningLars Marius Garshol
 
Hafslund SESAM - Semantic integration in practice
Hafslund SESAM - Semantic integration in practiceHafslund SESAM - Semantic integration in practice
Hafslund SESAM - Semantic integration in practiceLars Marius Garshol
 
Experiments in genetic programming
Experiments in genetic programmingExperiments in genetic programming
Experiments in genetic programmingLars Marius Garshol
 

More from Lars Marius Garshol (20)

JSLT: JSON querying and transformation
JSLT: JSON querying and transformationJSLT: JSON querying and transformation
JSLT: JSON querying and transformation
 
Data collection in AWS at Schibsted
Data collection in AWS at SchibstedData collection in AWS at Schibsted
Data collection in AWS at Schibsted
 
Kveik - what is it?
Kveik - what is it?Kveik - what is it?
Kveik - what is it?
 
Collecting 600M events/day
Collecting 600M events/dayCollecting 600M events/day
Collecting 600M events/day
 
History of writing
History of writingHistory of writing
History of writing
 
NoSQL and Einstein's theory of relativity
NoSQL and Einstein's theory of relativityNoSQL and Einstein's theory of relativity
NoSQL and Einstein's theory of relativity
 
Norwegian farmhouse ale
Norwegian farmhouse aleNorwegian farmhouse ale
Norwegian farmhouse ale
 
Archive integration with RDF
Archive integration with RDFArchive integration with RDF
Archive integration with RDF
 
The Euro crisis in 10 minutes
The Euro crisis in 10 minutesThe Euro crisis in 10 minutes
The Euro crisis in 10 minutes
 
Using the search engine as recommendation engine
Using the search engine as recommendation engineUsing the search engine as recommendation engine
Using the search engine as recommendation engine
 
Linked Open Data for the Cultural Sector
Linked Open Data for the Cultural SectorLinked Open Data for the Cultural Sector
Linked Open Data for the Cultural Sector
 
NoSQL databases, the CAP theorem, and the theory of relativity
NoSQL databases, the CAP theorem, and the theory of relativityNoSQL databases, the CAP theorem, and the theory of relativity
NoSQL databases, the CAP theorem, and the theory of relativity
 
Bitcoin - digital gold
Bitcoin - digital goldBitcoin - digital gold
Bitcoin - digital gold
 
Introduction to Big Data/Machine Learning
Introduction to Big Data/Machine LearningIntroduction to Big Data/Machine Learning
Introduction to Big Data/Machine Learning
 
Hops - the green gold
Hops - the green goldHops - the green gold
Hops - the green gold
 
Big data 101
Big data 101Big data 101
Big data 101
 
Linked Open Data
Linked Open DataLinked Open Data
Linked Open Data
 
Hafslund SESAM - Semantic integration in practice
Hafslund SESAM - Semantic integration in practiceHafslund SESAM - Semantic integration in practice
Hafslund SESAM - Semantic integration in practice
 
Approximate string comparators
Approximate string comparatorsApproximate string comparators
Approximate string comparators
 
Experiments in genetic programming
Experiments in genetic programmingExperiments in genetic programming
Experiments in genetic programming
 

Recently uploaded

Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 

Recently uploaded (20)

Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 

Nature-inspired algorithms

  • 1. Nature-inspired algorithms Lars Marius Garshol, lars.marius.garshol@schibsted.com http://twitter.com/larsga 2017–09–14, Oslo
  • 3. The problem • You need to tune something • a database • a search engine • a machine learning solution • … 2
  • 4. The problem • You need to tune something • a database • a search engine • a machine learning solution • … • Getting good results is important • but there’s lots of values to tune • the effects of tuning them are hard to predict 2
  • 5. Database tuning 3Automatic database management system tuning through large-scale machine learning Aken et al. , SIGMOD’17
  • 6. Find the best pair 4 Effects of MySQL tuning
  • 9. How to solve 1. Formulate the problem clearly 6
  • 10. How to solve 1. Formulate the problem clearly 2. Measure results properly 6
  • 11. How to solve 1. Formulate the problem clearly 2. Measure results properly 3. Then • try to understand the problem in depth, and/or • let your computer find a good solution 6
  • 12. Our kind of problem 7
  • 13. Our kind of problem • If • all your knobs are numeric and • you can measure how good a given set of settings is 7
  • 14. Our kind of problem • If • all your knobs are numeric and • you can measure how good a given set of settings is • then • basically you’re trying to find the highest point in a many- dimensional space 7
  • 15. Our kind of problem • If • all your knobs are numeric and • you can measure how good a given set of settings is • then • basically you’re trying to find the highest point in a many- dimensional space • One dimension per knob + 1 dimension for evaluation function 7
  • 19. A warning! • Be very, very careful about the evaluation function • Your algorithm will produce a good value for the evaluation function • If the function matches poorly with what you actually need, you’re going to work hard to produce something bad … 9
  • 21. Genetic algorithm • The “original” nature-inspired algorithm (1960s) • make n random solutions • evaluate them, throw away the worst, duplicate the best • add random newcomers • make random changes, repeat 10
  • 22. Genetic algorithm • The “original” nature-inspired algorithm (1960s) • make n random solutions • evaluate them, throw away the worst, duplicate the best • add random newcomers • make random changes, repeat 10 Exploit
  • 23. Genetic algorithm • The “original” nature-inspired algorithm (1960s) • make n random solutions • evaluate them, throw away the worst, duplicate the best • add random newcomers • make random changes, repeat 10 Exploit Explore
  • 24. Genetic algorithm • The “original” nature-inspired algorithm (1960s) • make n random solutions • evaluate them, throw away the worst, duplicate the best • add random newcomers • make random changes, repeat • Weakness: can’t exploit structure of numeric problems • no sense of hyperspace 10 Exploit Explore
  • 25. Genetic algorithm • The “original” nature-inspired algorithm (1960s) • make n random solutions • evaluate them, throw away the worst, duplicate the best • add random newcomers • make random changes, repeat • Weakness: can’t exploit structure of numeric problems • no sense of hyperspace • Strength: can solve non-numeric problems • can even write code 10 Exploit Explore
  • 26. Particle-swarm optimization (1995) • A swarm of particles explore the search space together • move around semi-randomly • communicate about what they’ve seen • particles attracted toward high spots in the landscape 11
  • 27. PSO, initialization • Use 10 + int(2 * math.sqrt(dimensions)) particles • Position each particle randomly • Give each particle a random velocity 12
  • 29. PSO, iteration • For each particle, in each dimension, update the velocity by adding 13
  • 30. PSO, iteration • For each particle, in each dimension, update the velocity by adding • old velocity * decay factor 13
  • 31. PSO, iteration • For each particle, in each dimension, update the velocity by adding • old velocity * decay factor • random factor * (best position - current position) 13
  • 32. PSO, iteration • For each particle, in each dimension, update the velocity by adding • old velocity * decay factor • random factor * (best position - current position) • random factor * (best neighbour position - current position) 13
  • 33. PSO, iteration • For each particle, in each dimension, update the velocity by adding • old velocity * decay factor • random factor * (best position - current position) • random factor * (best neighbour position - current position) • Velocity tends to decrease as 13
  • 34. PSO, iteration • For each particle, in each dimension, update the velocity by adding • old velocity * decay factor • random factor * (best position - current position) • random factor * (best neighbour position - current position) • Velocity tends to decrease as • current position goes toward best position and 13
  • 35. PSO, iteration • For each particle, in each dimension, update the velocity by adding • old velocity * decay factor • random factor * (best position - current position) • random factor * (best neighbour position - current position) • Velocity tends to decrease as • current position goes toward best position and • best and best neighbour position converge 13
  • 36. Code def f1(x): return 1 + math.sin(2 * np.pi * x) def f2a(x): return x ** 3 - 2 * x ** 2 + 1 * x - 1 def f(x): return f1(x) + f2a(x) swarm = pso.Swarm( dimensions = [(0.0, 2.0)], fitness = lambda x: f(x[0]), particles = 5 ) for ix in range(20): swarm.iterate() print swarm.get_best_ever() 14
  • 37. Implementation class Particle: def __init__(self, dimensions, fitness): self._dimensions = dimensions self._fitness = fitness self._vel = [pick_velocity(min, max) for (min, max) in dimensions] def iterate(self): for ix in range(len(self._dimensions)): self._vel[ix] = ( self._vel[ix] * w + random.uniform(0, c) * (self._prev_best_pos[ix] - self._pos[ix]) + random.uniform(0, c) * (self.neighbourhood_best(ix) - self._pos[ix]) ) self._pos[ix] += self._vel[ix] self._constrain(ix) self._update() 15
  • 60. Enough toy problems Let’s try a real problem
  • 61. Problem: Find the duplicates 20 ID SOURCE NAME ADDRESS1 ADDRESS2 ADDRESS3 CITY ZIP 9354686 1300001 Augustin C. Sundts Gate 22-24 Bergen 5004 8007 9316306 1300006 AUGUSTIN C. SUNDSGATE 22 5004 BERGEN NORWAY BGO 9025453 1300010 Augustin Hotel C. Sundts gate 22 Bergen 5004 9151327 1300010 Basic Hotel Bergen Hakonsgaten 27 Bergen 5015 9150992 1300010 Basic Hotel Marken Kong Oscars gate 45 Bergen 5017 9048595 1300010 Basic Hotel Victoria Kong Oscars Gate 29 Bergen 5017 9151853 1300010 Bergen Bed & Breakfast Hennebysmauet 9 Bergen 5005 9316307 1300006 BERGEN TRAVEL VESTRE TORGGATE 7 5015 BERGEN NORWAY BGO 9062459 1300010 Bergen Travel Hotel Vestre Torggaten 7 Bergen 5015 9010488 1300001 Best Western Hordaheimen C. Sundtsgt. 18 5004 9316314 1300006 BEST WESTERN HORDAHEIMEN C. SUNDTSGATE 18 BERGEN NORWAY 5004 BERGEN BGO 9032340 1300010 Best Western Hotell Hordaheimen C. Sundtsgate 18 Bergen 5004 9362760 1300001 Clarion Admiral C. Sundts Gate 9 P.o.box 252 Bergen 5004 8007 9316308 1300006 CLARION ADMIRAL C. SUNDTS GATE 9 5804 BERGEN NORWAY BGO 9364882 1300001 Clarion Admiral (Fjord View) C. Sundts Gate 9 P.o.box 252 Bergen 5004 8007 9010491 1300001 Clarion Bergen Airport Flyplassveien 555 5869 9363104 1300001 Clarion Bergen Airport Flyplassveien 555 Po Box 24 Bergen No-5869
  • 62. Configure manually 21 PROPERTY COMPARATOR LOW HIGH Name LongestCommonSubstring 0.35 0.88 Address1 WeightedLevenshtein 0.25 0.65 Address2 Levenshtein 0.5 0.6 Email Exact 0.49 0.51 Phone Exact 0.45 0.65 Geopos Geoposition 0.25 0.6 Region Exact 0.0 0.5 Threshold: 0.74
  • 63. Dedup with PSO • A 27-dimension problem • Really difficult to solve optimally • Takes a long time to evaluate solutions • No idea what the best possible solution actually is 22
  • 64. PSO vs random 23 Green: PSO Blue: random
  • 70. Firefly algorithm • Fireflies are positioned randomly 28 Xin-She Yang, 2010
  • 71. Firefly algorithm • Fireflies are positioned randomly • On each iteration, each firefly jumps toward every other firefly based on how bright it looks • that is, the brighter the other firefly appears, the further toward it our firefly jumps • it only jumps toward fireflies that are brighter than itself 28 Xin-She Yang, 2010
  • 72. Firefly algorithm • Fireflies are positioned randomly • On each iteration, each firefly jumps toward every other firefly based on how bright it looks • that is, the brighter the other firefly appears, the further toward it our firefly jumps • it only jumps toward fireflies that are brighter than itself • Each firefly shines brighter the better its fitness is • but attractiveness falls off with square of the distance 28 Xin-She Yang, 2010
  • 73. Firefly algorithm • Fireflies are positioned randomly • On each iteration, each firefly jumps toward every other firefly based on how bright it looks • that is, the brighter the other firefly appears, the further toward it our firefly jumps • it only jumps toward fireflies that are brighter than itself • Each firefly shines brighter the better its fitness is • but attractiveness falls off with square of the distance • Add random jiggling 28 Xin-She Yang, 2010
  • 74. How it works • The best firefly always stands still, pulling the others toward the best result • Bad fireflies get pulled in all directions, but good fireflies get pulled much less • this is exploit vs explore • Pull diminishes with distance, so the fireflies don’t necessarily all explore the same best position • in order to explore more local maxima 29
  • 75. Firefly code def iterate(self): for firefly in self._swarm.get_particles(): if self._val < firefly._val: dist = self.distance(firefly) attract = firefly._val / (1 + gamma * (dist ** 2)) for ix in range(len(self._dimensions)): jiggle = alpha * (random.uniform(0, 1) - 0.5) diff = firefly._pos[ix] - self._pos[ix] self._pos[ix] = self._pos[ix] + jiggle + (attract * diff) self._constrain(ix) 30
  • 76. Evaluation 31 Unit is: number of fitness evaluations to find global maximum (Lower is better) Taken from Yang 2010
  • 78. Cuckoo search • Very similar to genetic algorithm • take candidate, modify it • if better than existing candidate, replace • Every generation, discard some proportion of candidates • fill up with random new ones • The difference is in how new results are produced • using Lévy flights 33 Yang et al. 2010
  • 80. How it works • Balance explore and exploit with Lévy flights • usually jump short, sometimes jump long • Never replace good candidates by bad • but always throw away the n worst 35
  • 84. Starts exploring local maximum Toy problem again 36
  • 85. Starts exploring local maximum Toy problem again 36
  • 86. Starts exploring local maximum Toy problem again 36
  • 87. Starts exploring local maximum Toy problem again 36
  • 88. Starts exploring local maximum Toy problem again 36
  • 89. Starts exploring local maximum Toy problem again 36
  • 90. Starts exploring local maximum Toy problem again 36
  • 91. Starts exploring local maximum Toy problem again 36
  • 92. Starts exploring local maximum Toy problem again 36 Rogue cuckoo strikes gold
  • 93. Starts exploring local maximum Toy problem again 36 Rogue cuckoo strikes gold
  • 94. Starts exploring local maximum Toy problem again 36 Rogue cuckoo strikes gold
  • 95. Starts exploring local maximum Toy problem again 36 Rogue cuckoo strikes gold
  • 96. Starts exploring local maximum Toy problem again 36 Rogue cuckoo strikes gold
  • 97. Starts exploring local maximum Toy problem again 36 Rogue cuckoo strikes gold
  • 101. Morale • These are stochastic algorithms • one evaluation doesn’t tell you much about the algorithm • even 10 evaluations isn’t enough • Be careful here, or you can fool yourself! 40
  • 102. It’s not that simple • Which PSO? • SPSO 2006, 2007, or 2011? • What values to use for decay factor and randomization? • What neighbourhood topology to use? • Firefly has parameters alpha, beta, and gamma • Cuckoo has alpha and scale 41
  • 104. So … in order to tune our algorithm we need to tune the algorithm that tunes our algorithm
  • 105. Problems • Doing one run of Cuckoo search takes ~30 minutes • Need to do that ~40 times to get a decent estimate • My laptop was already getting uncomfortably hot • My wife was complaining about the fan noise • What to do? 44
  • 107. Master algorithm • Run PSO on Cuckoo alpha & scale • Fitness function • sets the task handed out by /get-task • hangs until 20 evaluations have come in via /answer • returns average of evaluations 46
  • 112. More algorithms • Flower-pollination algorithm [Xin-She Yang 2013] • Bat-inspired algorithm [Xin-She Yang, 2010] • Ant colony algorithm [Marco Dorigo, 1992] • Bee algorithm [Pham et al 2005] • Fish school search [Filho et al 2007] • Artificial bee colony algorithm [Karaboga et al 2005] • … 50 Looks interesting, hard to find algorithm Paper too vague, can’t implement Complicated, didn’t finish implementation
  • 113. 51 PROPERTY COMPARATOR LOW HIGH Name LongestCommonSubstring 0.35 0.88 Address1 WeightedLevenshtein 0.25 0.65 Address2 Levenshtein 0.5 0.6 Email Exact 0.49 0.51 Phone Exact 0.45 0.65 Geopos Geoposition 0.25 0.6 Region Exact 0.0 0.5 Threshold: 0.74 But what about these?
  • 114. The machine learning way 52 PROPERTY COMPARATOR LOW HIGH Name c1 c1 0.35 0.88 Name c2 c2 0.25 0.65 Name c3 c3 0.5 0.6 Name c4 c4 0.49 0.51 … … 0.45 0.65 Address1 c1 c1 0.25 0.6 Address1 c2 c2 0.0 0.5 Address1 c3 c3 … … Address1 c4 c4 … … … … … …
  • 115. Opens a door • Means we can drop the probabilities, and just use the numeric values coming out of the comparators • Feed into one of • random forests • Support Vector Machine (SVM) • logistic regression • neural networks • … • Except that’s no longer optimization, but attacking the problem directly, so let’s stick with our algorithms 53
  • 116. General trick • Quite common to “cheat” this way to use numeric- only machine learning algorithms • Turn boolean into [0, 1] parameter • Turn enumeration into one boolean per value • Looks odd, but in general it does work • of course, now there isn’t much spatial structure any more 54
  • 118. Tricky, tricky • Our problem now has 267 dimensions • should allow us to tune for really detailed signals 55
  • 119. Tricky, tricky • Our problem now has 267 dimensions • should allow us to tune for really detailed signals • The curse of dimensionality • everywhere is pretty much equally far away from everywhere else • hyperspace consists of all corners and no middle • many of the dimensions contain no signal 55
  • 121. Another test 57 Any number of dimensions, this is 2 Number of local minima is d!
  • 123. Meta-tuning again def fitness(pos): (firefly.alpha, firefly.gamma) = pos averages = crap.run_experiment( firefly, dimensions = [(0.0, math.pi)] * 16, fitness = function.michaelwicz, particles = 20, problem = 'michaelwicz', quiet = True ) return crap.average(averages) dimensions = [(0.0, 1.0), (0.0, 10.0)] # alpha, gamma swarm = pso.Swarm(dimensions, fitness, 10) crap.evaluate(swarm, 'meta-michaelwicz-firefly') 59
  • 127. What to choose? • PSO • generally performs best • dead easy to implement • parameters available in the literature • no need to scale to coordinate system used • SPSO 2007 • values for w and c are given • ring topology: each particle knows p-1, p, p+1 63
  • 128. Simulated annealing • Inspired by the behaviour of cooling metals • guaranteed to eventually find maximum • no guarantee that time taken will be reasonable • To use, requires following parameters • Candidate neighbour generation procedure • Acceptance probability function • Annealing schedule • Initial temperature • May work better than PSO and friends, but also requires a lot more effort to set up 64
  • 129. Choices, choices • There are always more advanced methods • sometimes they work much better, sometimes not • PSO gives you a dead easy place to start • whip it up in a few lines of code • see how it works • vastly better than random trial and error • adapts nicely to all kinds of problems without tuning 65
  • 130. Research papers • Publishing standards are probably too lax • Algorithm descriptions are weak • far too little information about tuning parameters • no code available • Evaluation sections are weak • only one evaluation metric • no information about how PSO/GA were tuned • no information about how proposed algorithm was tuned • no cross-comparison with other algorithms 66
  • 131. See for yourself • https://github.com/larsga/py-snippets/tree/master/ machine-learning/pso • links to all the papers • code for crap, genetic, pso, firefly, cuckoo • bonus: cuckoo2, server • also has the test functions • Total number of experiments: 24,008 • means evaluating fitness 2,400,800 times 67