optimization via search cpsc 315 – programming studio spring 2008 project 2, lecture 4 adapted...
TRANSCRIPT
![Page 1: Optimization via Search CPSC 315 – Programming Studio Spring 2008 Project 2, Lecture 4 Adapted from slides of Yoonsuck Choe](https://reader030.vdocument.in/reader030/viewer/2022013004/56649d985503460f94a821aa/html5/thumbnails/1.jpg)
Optimization via Search
CPSC 315 – Programming Studio
Spring 2008
Project 2, Lecture 4
Adapted from slides of Yoonsuck Choe
![Page 2: Optimization via Search CPSC 315 – Programming Studio Spring 2008 Project 2, Lecture 4 Adapted from slides of Yoonsuck Choe](https://reader030.vdocument.in/reader030/viewer/2022013004/56649d985503460f94a821aa/html5/thumbnails/2.jpg)
Improving Results and Optimization
Assume a state with many variables Assume some function that you want to
maximize/minimize the value of Searching entire space is too complicated
Can’t evaluate every possible combination of variables
Function might be difficult to evaluate analytically
![Page 3: Optimization via Search CPSC 315 – Programming Studio Spring 2008 Project 2, Lecture 4 Adapted from slides of Yoonsuck Choe](https://reader030.vdocument.in/reader030/viewer/2022013004/56649d985503460f94a821aa/html5/thumbnails/3.jpg)
Iterative improvement
Start with a complete valid state Gradually work to improve to better and
better states Sometimes, try to achieve an optimum, though
not always possible Sometimes states are discrete, sometimes
continuous
![Page 4: Optimization via Search CPSC 315 – Programming Studio Spring 2008 Project 2, Lecture 4 Adapted from slides of Yoonsuck Choe](https://reader030.vdocument.in/reader030/viewer/2022013004/56649d985503460f94a821aa/html5/thumbnails/4.jpg)
Simple Example
One dimension (typically use more):
x
functionvalue
![Page 5: Optimization via Search CPSC 315 – Programming Studio Spring 2008 Project 2, Lecture 4 Adapted from slides of Yoonsuck Choe](https://reader030.vdocument.in/reader030/viewer/2022013004/56649d985503460f94a821aa/html5/thumbnails/5.jpg)
Simple Example
Start at a valid state, try to maximize
x
functionvalue
![Page 6: Optimization via Search CPSC 315 – Programming Studio Spring 2008 Project 2, Lecture 4 Adapted from slides of Yoonsuck Choe](https://reader030.vdocument.in/reader030/viewer/2022013004/56649d985503460f94a821aa/html5/thumbnails/6.jpg)
Simple Example
Move to better state
x
functionvalue
![Page 7: Optimization via Search CPSC 315 – Programming Studio Spring 2008 Project 2, Lecture 4 Adapted from slides of Yoonsuck Choe](https://reader030.vdocument.in/reader030/viewer/2022013004/56649d985503460f94a821aa/html5/thumbnails/7.jpg)
Simple Example
Try to find maximum
x
functionvalue
![Page 8: Optimization via Search CPSC 315 – Programming Studio Spring 2008 Project 2, Lecture 4 Adapted from slides of Yoonsuck Choe](https://reader030.vdocument.in/reader030/viewer/2022013004/56649d985503460f94a821aa/html5/thumbnails/8.jpg)
Hill-Climbing
Choose Random Starting State
Repeat
From current state, generate n random
steps in random directions
Choose the one that gives the best new
value
While some new better state found
(i.e. exit if none of the n steps were better)
![Page 9: Optimization via Search CPSC 315 – Programming Studio Spring 2008 Project 2, Lecture 4 Adapted from slides of Yoonsuck Choe](https://reader030.vdocument.in/reader030/viewer/2022013004/56649d985503460f94a821aa/html5/thumbnails/9.jpg)
Simple Example
Random Starting Point
x
functionvalue
![Page 10: Optimization via Search CPSC 315 – Programming Studio Spring 2008 Project 2, Lecture 4 Adapted from slides of Yoonsuck Choe](https://reader030.vdocument.in/reader030/viewer/2022013004/56649d985503460f94a821aa/html5/thumbnails/10.jpg)
Simple Example
Three random steps
x
functionvalue
![Page 11: Optimization via Search CPSC 315 – Programming Studio Spring 2008 Project 2, Lecture 4 Adapted from slides of Yoonsuck Choe](https://reader030.vdocument.in/reader030/viewer/2022013004/56649d985503460f94a821aa/html5/thumbnails/11.jpg)
Simple Example
Choose Best One for new position
x
functionvalue
![Page 12: Optimization via Search CPSC 315 – Programming Studio Spring 2008 Project 2, Lecture 4 Adapted from slides of Yoonsuck Choe](https://reader030.vdocument.in/reader030/viewer/2022013004/56649d985503460f94a821aa/html5/thumbnails/12.jpg)
Simple Example
Repeat
x
functionvalue
![Page 13: Optimization via Search CPSC 315 – Programming Studio Spring 2008 Project 2, Lecture 4 Adapted from slides of Yoonsuck Choe](https://reader030.vdocument.in/reader030/viewer/2022013004/56649d985503460f94a821aa/html5/thumbnails/13.jpg)
Simple Example
Repeat
x
functionvalue
![Page 14: Optimization via Search CPSC 315 – Programming Studio Spring 2008 Project 2, Lecture 4 Adapted from slides of Yoonsuck Choe](https://reader030.vdocument.in/reader030/viewer/2022013004/56649d985503460f94a821aa/html5/thumbnails/14.jpg)
Simple Example
Repeat
x
functionvalue
![Page 15: Optimization via Search CPSC 315 – Programming Studio Spring 2008 Project 2, Lecture 4 Adapted from slides of Yoonsuck Choe](https://reader030.vdocument.in/reader030/viewer/2022013004/56649d985503460f94a821aa/html5/thumbnails/15.jpg)
Simple Example
Repeat
x
functionvalue
![Page 16: Optimization via Search CPSC 315 – Programming Studio Spring 2008 Project 2, Lecture 4 Adapted from slides of Yoonsuck Choe](https://reader030.vdocument.in/reader030/viewer/2022013004/56649d985503460f94a821aa/html5/thumbnails/16.jpg)
Simple Example
No Improvement, so stop.
x
functionvalue
![Page 17: Optimization via Search CPSC 315 – Programming Studio Spring 2008 Project 2, Lecture 4 Adapted from slides of Yoonsuck Choe](https://reader030.vdocument.in/reader030/viewer/2022013004/56649d985503460f94a821aa/html5/thumbnails/17.jpg)
Problems With Hill Climbing
Random Steps are Wasteful Addressed by other methods
Local maxima, plateaus, ridges Can try random restart locations Can keep the n best choices (this is also called “beam
search”)
Comparing to game trees: Basically looks at some number of available next moves
and chooses the one that looks the best at the moment Beam search: follow only the best-looking n moves
![Page 18: Optimization via Search CPSC 315 – Programming Studio Spring 2008 Project 2, Lecture 4 Adapted from slides of Yoonsuck Choe](https://reader030.vdocument.in/reader030/viewer/2022013004/56649d985503460f94a821aa/html5/thumbnails/18.jpg)
Gradient Descent (or Ascent)
Simple modification to Hill Climbing Generallly assumes a continuous state space
Idea is to take more intelligent steps Look at local gradient: the direction of largest
change Take step in that direction
Step size should be proportional to gradient Tends to yield much faster convergence to
maximum
![Page 19: Optimization via Search CPSC 315 – Programming Studio Spring 2008 Project 2, Lecture 4 Adapted from slides of Yoonsuck Choe](https://reader030.vdocument.in/reader030/viewer/2022013004/56649d985503460f94a821aa/html5/thumbnails/19.jpg)
Gradient Ascent
Random Starting Point
x
functionvalue
![Page 20: Optimization via Search CPSC 315 – Programming Studio Spring 2008 Project 2, Lecture 4 Adapted from slides of Yoonsuck Choe](https://reader030.vdocument.in/reader030/viewer/2022013004/56649d985503460f94a821aa/html5/thumbnails/20.jpg)
Gradient Ascent
Take step in direction of largest increase
(obvious in 1D, must be computed
in higher dimensions)
x
functionvalue
![Page 21: Optimization via Search CPSC 315 – Programming Studio Spring 2008 Project 2, Lecture 4 Adapted from slides of Yoonsuck Choe](https://reader030.vdocument.in/reader030/viewer/2022013004/56649d985503460f94a821aa/html5/thumbnails/21.jpg)
Gradient Ascent
Repeat
x
functionvalue
![Page 22: Optimization via Search CPSC 315 – Programming Studio Spring 2008 Project 2, Lecture 4 Adapted from slides of Yoonsuck Choe](https://reader030.vdocument.in/reader030/viewer/2022013004/56649d985503460f94a821aa/html5/thumbnails/22.jpg)
Gradient Ascent
Next step is actually lower, so stop
x
functionvalue
![Page 23: Optimization via Search CPSC 315 – Programming Studio Spring 2008 Project 2, Lecture 4 Adapted from slides of Yoonsuck Choe](https://reader030.vdocument.in/reader030/viewer/2022013004/56649d985503460f94a821aa/html5/thumbnails/23.jpg)
Gradient Ascent
Could reduce step size to “hone in”
x
functionvalue
![Page 24: Optimization via Search CPSC 315 – Programming Studio Spring 2008 Project 2, Lecture 4 Adapted from slides of Yoonsuck Choe](https://reader030.vdocument.in/reader030/viewer/2022013004/56649d985503460f94a821aa/html5/thumbnails/24.jpg)
Gradient Ascent
Converge to (local) maximum
x
functionvalue
![Page 25: Optimization via Search CPSC 315 – Programming Studio Spring 2008 Project 2, Lecture 4 Adapted from slides of Yoonsuck Choe](https://reader030.vdocument.in/reader030/viewer/2022013004/56649d985503460f94a821aa/html5/thumbnails/25.jpg)
Dealing with Local Minima
Can use various modifications of hill climbing and gradient descent Random starting positions – choose one Random steps when maximum reached Conjugate Gradient Descent/Ascent
Choose gradient direction – look for max in that direction
Then from that point go in a different direction
Simulated Annealing
![Page 26: Optimization via Search CPSC 315 – Programming Studio Spring 2008 Project 2, Lecture 4 Adapted from slides of Yoonsuck Choe](https://reader030.vdocument.in/reader030/viewer/2022013004/56649d985503460f94a821aa/html5/thumbnails/26.jpg)
Simulated Annealing
Annealing: heat up metal and let cool to make harder By heating, you give atoms freedom to move
around Cooling “hardens” the metal in a stronger state
Idea is like hill-climbing, but you can take steps down as well as up. The probability of allowing “down” steps goes
down with time
![Page 27: Optimization via Search CPSC 315 – Programming Studio Spring 2008 Project 2, Lecture 4 Adapted from slides of Yoonsuck Choe](https://reader030.vdocument.in/reader030/viewer/2022013004/56649d985503460f94a821aa/html5/thumbnails/27.jpg)
Simulated Annealing
Heuristic/goal/fitness function E (energy) Generate a move (randomly) and compute
E = Enew-Eold
If E <= 0, then accept the move If E > 0, accept the move with probability:
Set
T is “Temperature”
kT
E
eEP
)(
![Page 28: Optimization via Search CPSC 315 – Programming Studio Spring 2008 Project 2, Lecture 4 Adapted from slides of Yoonsuck Choe](https://reader030.vdocument.in/reader030/viewer/2022013004/56649d985503460f94a821aa/html5/thumbnails/28.jpg)
Simulated Annealing
Compare P(E) with a random number from 0 to 1. If it’s below, then accept
Temperature decreased over time When T is higher, downward moves are more
likely accepted T=0 means equivalent to hill climbing
When E is smaller, downward moves are more likely accepted
![Page 29: Optimization via Search CPSC 315 – Programming Studio Spring 2008 Project 2, Lecture 4 Adapted from slides of Yoonsuck Choe](https://reader030.vdocument.in/reader030/viewer/2022013004/56649d985503460f94a821aa/html5/thumbnails/29.jpg)
“Cooling Schedule”
Speed at which temperature is reduced has an effect
Too fast and the optima are not found Too slow and time is wasted
![Page 30: Optimization via Search CPSC 315 – Programming Studio Spring 2008 Project 2, Lecture 4 Adapted from slides of Yoonsuck Choe](https://reader030.vdocument.in/reader030/viewer/2022013004/56649d985503460f94a821aa/html5/thumbnails/30.jpg)
Simulated Annealing
Random Starting Point
x
functionvalue
T = Very High
![Page 31: Optimization via Search CPSC 315 – Programming Studio Spring 2008 Project 2, Lecture 4 Adapted from slides of Yoonsuck Choe](https://reader030.vdocument.in/reader030/viewer/2022013004/56649d985503460f94a821aa/html5/thumbnails/31.jpg)
Simulated Annealing
Random Step
x
functionvalue
T = Very High
![Page 32: Optimization via Search CPSC 315 – Programming Studio Spring 2008 Project 2, Lecture 4 Adapted from slides of Yoonsuck Choe](https://reader030.vdocument.in/reader030/viewer/2022013004/56649d985503460f94a821aa/html5/thumbnails/32.jpg)
Simulated Annealing
Even though E is lower, accept
x
functionvalue
T = Very High
![Page 33: Optimization via Search CPSC 315 – Programming Studio Spring 2008 Project 2, Lecture 4 Adapted from slides of Yoonsuck Choe](https://reader030.vdocument.in/reader030/viewer/2022013004/56649d985503460f94a821aa/html5/thumbnails/33.jpg)
Simulated Annealing
Next Step; accept since higher E
x
functionvalue
T = Very High
![Page 34: Optimization via Search CPSC 315 – Programming Studio Spring 2008 Project 2, Lecture 4 Adapted from slides of Yoonsuck Choe](https://reader030.vdocument.in/reader030/viewer/2022013004/56649d985503460f94a821aa/html5/thumbnails/34.jpg)
Simulated Annealing
Next Step; accept since higher E
x
functionvalue
T = Very High
![Page 35: Optimization via Search CPSC 315 – Programming Studio Spring 2008 Project 2, Lecture 4 Adapted from slides of Yoonsuck Choe](https://reader030.vdocument.in/reader030/viewer/2022013004/56649d985503460f94a821aa/html5/thumbnails/35.jpg)
Simulated Annealing
Next Step; accept even though lower
x
functionvalue
T = High
![Page 36: Optimization via Search CPSC 315 – Programming Studio Spring 2008 Project 2, Lecture 4 Adapted from slides of Yoonsuck Choe](https://reader030.vdocument.in/reader030/viewer/2022013004/56649d985503460f94a821aa/html5/thumbnails/36.jpg)
Simulated Annealing
Next Step; accept even though lower
x
functionvalue
T = High
![Page 37: Optimization via Search CPSC 315 – Programming Studio Spring 2008 Project 2, Lecture 4 Adapted from slides of Yoonsuck Choe](https://reader030.vdocument.in/reader030/viewer/2022013004/56649d985503460f94a821aa/html5/thumbnails/37.jpg)
Simulated Annealing
Next Step; accept since higher
x
functionvalue
T = Medium
![Page 38: Optimization via Search CPSC 315 – Programming Studio Spring 2008 Project 2, Lecture 4 Adapted from slides of Yoonsuck Choe](https://reader030.vdocument.in/reader030/viewer/2022013004/56649d985503460f94a821aa/html5/thumbnails/38.jpg)
Simulated Annealing
Next Step; lower, but reject (T is falling)
x
functionvalue
T = Medium
![Page 39: Optimization via Search CPSC 315 – Programming Studio Spring 2008 Project 2, Lecture 4 Adapted from slides of Yoonsuck Choe](https://reader030.vdocument.in/reader030/viewer/2022013004/56649d985503460f94a821aa/html5/thumbnails/39.jpg)
Simulated Annealing
Next Step; Accept since E is higher
x
functionvalue
T = Medium
![Page 40: Optimization via Search CPSC 315 – Programming Studio Spring 2008 Project 2, Lecture 4 Adapted from slides of Yoonsuck Choe](https://reader030.vdocument.in/reader030/viewer/2022013004/56649d985503460f94a821aa/html5/thumbnails/40.jpg)
Simulated Annealing
Next Step; Accept since E change small
x
functionvalue
T = Low
![Page 41: Optimization via Search CPSC 315 – Programming Studio Spring 2008 Project 2, Lecture 4 Adapted from slides of Yoonsuck Choe](https://reader030.vdocument.in/reader030/viewer/2022013004/56649d985503460f94a821aa/html5/thumbnails/41.jpg)
Simulated Annealing
Next Step; Accept since E larget
x
functionvalue
T = Low
![Page 42: Optimization via Search CPSC 315 – Programming Studio Spring 2008 Project 2, Lecture 4 Adapted from slides of Yoonsuck Choe](https://reader030.vdocument.in/reader030/viewer/2022013004/56649d985503460f94a821aa/html5/thumbnails/42.jpg)
Simulated Annealing
Next Step; Reject since E lower and T low
x
functionvalue
T = Low
![Page 43: Optimization via Search CPSC 315 – Programming Studio Spring 2008 Project 2, Lecture 4 Adapted from slides of Yoonsuck Choe](https://reader030.vdocument.in/reader030/viewer/2022013004/56649d985503460f94a821aa/html5/thumbnails/43.jpg)
Simulated Annealing
Eventually converge to Maximum
x
functionvalue
T = Low
![Page 44: Optimization via Search CPSC 315 – Programming Studio Spring 2008 Project 2, Lecture 4 Adapted from slides of Yoonsuck Choe](https://reader030.vdocument.in/reader030/viewer/2022013004/56649d985503460f94a821aa/html5/thumbnails/44.jpg)
Other Optimization Approach: Genetic Algorithms
State = “Chromosome” Genes are the variables
Optimization Function = “Fitness” Create “Generations” of solutions
A set of several valid solution
Most fit solutions carry on Generate next generation by:
Mutating genes of previous generation “Breeding” – Pick two (or more) “parents” and create
children by combining their genes