Simulated Annealing

Adam Gaweda
5 Feb 202317:45

Summary

TLDRThis video explores the limitations of hill climbing in optimization and introduces simulated annealing as a solution. The speaker explains how hill climbing struggles with local maxima and how simulated annealing overcomes this by sometimes allowing worse moves, mimicking the metallurgic process of heating and cooling metals. By controlling the randomness of these decisions, simulated annealing helps find better solutions over time, eventually narrowing down to the optimal one. The video delves into the math behind this method and demonstrates how it works with temperature decline and probability.

Takeaways

  • 🤔 Hill climbing struggles with local maxima, where it won't accept worse moves, potentially trapping it.
  • 🎲 Introducing controlled randomness allows for sometimes making worse moves to escape local maxima.
  • 🌱 Metaheuristics are inspired by natural processes and provide solutions beyond simple optimization algorithms.
  • 🔥 Simulated annealing is inspired by metallurgical processes, where heated metal gradually cools to a stable structure.
  • 🌡️ Simulated annealing involves accepting worse moves more frequently when the system (or temperature) is volatile or 'hot.'
  • 🔄 The algorithm computes the energy change (Delta E) to determine whether to accept a move based on its impact.
  • 📉 As temperature decreases, the probability of accepting worse moves decreases, guiding the system to a stable, optimized solution.
  • 🔢 The probability of accepting worse moves is based on an exponential function: e^(Delta E / temperature).
  • 🎯 The goal is to sometimes accept worse solutions early on to avoid getting stuck, gradually stabilizing at better solutions.
  • 📊 Simulated annealing is useful for escaping local maxima to potentially find a global maximum in optimization problems.

Q & A

  • What is the main limitation of hill climbing as described in the video?

    -The main limitation of hill climbing is that it can get stuck at a local maxima and won't consider moves that reduce the objective function, even if those moves could eventually lead to a better overall solution.

  • What is the solution proposed to overcome the limitation of hill climbing?

    -The proposed solution is to introduce randomness, allowing for the possibility of taking steps that reduce the objective function temporarily, which can help escape local maxima and potentially reach a better global solution.

  • What is simulated annealing, and how is it related to metallurgy?

    -Simulated annealing is an optimization technique inspired by the process of cooling metal in metallurgy. As the temperature of the metal decreases, the movement of molecules slows down and they settle into a more stable, crystalline structure. Similarly, simulated annealing allows for exploration (random moves) at high temperatures, and as the temperature decreases, the algorithm becomes more selective about improving moves.

  • How does simulated annealing handle 'bad moves' in optimization?

    -Simulated annealing allows for 'bad moves' (those that decrease the objective function) with a probability based on the difference in energy (Delta E) and the current temperature. At high temperatures, the probability of accepting a bad move is higher, but as the temperature decreases, this probability becomes smaller.

  • What is the role of temperature in simulated annealing?

    -Temperature controls the likelihood of accepting worse solutions. At higher temperatures, the algorithm is more likely to accept worse solutions to explore more of the solution space. As the temperature decreases, the algorithm becomes more conservative and favors only improving moves.

  • How is the probability of accepting a worse move calculated in simulated annealing?

    -The probability is calculated using the formula e^(Delta E / T), where Delta E is the change in energy (objective function value) and T is the current temperature. If Delta E is negative (indicating a worse move), the probability decreases as T decreases.

  • What happens to the probability of accepting a worse move as temperature decreases?

    -As temperature decreases, the probability of accepting a worse move also decreases. Eventually, when the temperature is very low, the probability becomes so small that the algorithm mostly rejects bad moves.

  • How is randomness introduced in the simulated annealing algorithm?

    -Randomness is introduced by selecting a random candidate move from the possible options at each step. This allows the algorithm to explore the solution space without always following the best or worst move.

  • What happens if the Delta E (energy difference) is positive in simulated annealing?

    -If Delta E is positive (indicating an improvement in the objective function), the move is always accepted, as it represents a step toward a better solution.

  • How does simulated annealing help in finding the global maxima?

    -Simulated annealing helps in finding the global maxima by allowing occasional moves to worse solutions, which helps escape local maxima. As the temperature decreases, the algorithm focuses on refining the solution to find a global or better local maxima.

Outlines

00:00

🧠 Introduction to Limitations of Hill Climbing and Random Control

The video begins by discussing a limitation of hill climbing optimization, specifically the problem of getting stuck in a local maximum. The concept of sometimes accepting moves that seem worse in the short term is introduced as a solution. This leads to the idea of meta-heuristics, a broader approach inspired by nature, which allows for controlled randomness. One such meta-heuristic, simulated annealing, is introduced as a technique that mimics the process of cooling in metallurgy to find better solutions in optimization problems.

05:00

📉 Delta E and Energy-Based Moves

This paragraph dives into the concept of calculating the change in energy (Delta E) when transitioning between states in simulated annealing. A positive Delta E represents a favorable move, while a negative Delta E may still be accepted in the early, volatile stages of optimization. The probability of accepting unfavorable moves is proportional to the energy difference and the current temperature of the system, allowing for exploration beyond local maxima.

10:02

🎲 Random Move Selection and Optimization

The process of randomly selecting potential moves in simulated annealing is explained here. Rather than always choosing the best or worst option, the algorithm picks a random candidate and evaluates its fitness. If the move improves the state, it is accepted. If not, the algorithm may still accept it depending on the calculated probability, which helps escape local maxima.

15:06

🔢 Probabilities and Temperature Decline in Simulated Annealing

This section explores how probabilities of accepting worse moves decrease as the temperature declines in simulated annealing. It shows how the probability of taking a suboptimal step starts high when the system is volatile (with high temperature) and gradually decreases as the temperature cools down. A Python code example demonstrates this decline in probability and how it affects decision-making in the optimization process.

Mindmap

Keywords

💡Hill Climbing

Hill climbing is an optimization algorithm where decisions are made to always move towards higher or more optimal values. In the context of the video, it refers to the strategy of taking steps that improve a solution, but this approach can get stuck in a 'local Maxima' where no better steps seem available. The video discusses its limitations and introduces alternatives like allowing worse moves to avoid this problem.

💡Local Maxima

A local Maxima is a point in an optimization problem where any small change in the solution results in a worse outcome, though better global solutions may exist elsewhere. The video highlights the challenge of getting stuck at a local Maxima using hill climbing and introduces methods like simulated annealing to escape these points by sometimes allowing worse moves temporarily.

💡Simulated Annealing

Simulated annealing is an optimization technique inspired by the process of heating and slowly cooling metal to remove defects. In the video, it is presented as an alternative to hill climbing, where controlled randomness allows the system to occasionally take worse steps to potentially reach better global solutions, similar to how metal's molecules rearrange as it cools.

💡Metaheuristics

Metaheuristics are high-level strategies used to guide and improve the performance of optimization algorithms. In the video, metaheuristics are introduced as a broader category of algorithms, including biologically inspired methods like simulated annealing, that are designed to explore solutions more creatively than basic approaches like hill climbing.

💡Biologically Inspired AI

Biologically inspired AI refers to algorithms and strategies derived from natural processes observed in biology. The video uses this term to describe a class of metaheuristic algorithms, such as simulated annealing, which mimics the physical process of cooling metals, in order to solve complex optimization problems in AI.

💡Objective Function

The objective function is the function that an optimization algorithm seeks to maximize or minimize. In the video, the speaker refers to it as 'F' or 'energy,' and explains that simulated annealing compares the change in the objective function between the current state and potential next states to determine whether to make a move.

💡Temperature

In simulated annealing, temperature refers to a control parameter that decreases over time, reducing the likelihood of accepting worse solutions as the algorithm progresses. The video explains that starting with a high temperature allows more exploration of worse solutions, while lowering the temperature gradually helps the algorithm focus on improving solutions.

💡Energy Difference (Delta E)

Delta E is the difference in the objective function value between the current state and the next state in an optimization problem. In the video, it is used to determine whether a move should be accepted, with moves that increase energy being always accepted, and moves that decrease energy being accepted based on a probability influenced by the temperature.

💡Crystallization

Crystallization refers to the process where molecules slow down and settle into stable positions as a material cools. In the video, this concept is used as an analogy for how simulated annealing works—the algorithm starts with high randomness (like hot metal) and gradually stabilizes by focusing on improving solutions as the temperature decreases.

💡Temperature Decline Schedule

The temperature decline schedule is the process by which the temperature is gradually reduced in a simulated annealing algorithm. The video discusses different ways to design this schedule, whether by using fixed percentages or step decreases, and how it impacts the probability of accepting worse solutions as the system cools.

Highlights

The limitation of hill climbing algorithms is they can get stuck in local maxima, where no potential moves improve the solution.

To resolve the local maxima issue, the introduction of randomness allows occasional moves to worse solutions, potentially leading to better maxima.

Meta-heuristics are strategies inspired by natural processes that provide alternative optimization methods.

Simulated annealing is introduced as a biologically inspired AI technique based on metallurgic processes.

In simulated annealing, molecules in hot metal move rapidly, similar to how solutions in optimization problems explore the search space when volatility is high.

As temperature decreases in simulated annealing, the exploration reduces, allowing solutions to settle into more stable states.

The optimization process in simulated annealing mimics crystallization, where molecules settle into a more fixed position as temperature cools.

Energy difference (Delta E) is a key factor in deciding whether a move is accepted in simulated annealing, even if it leads to a worse solution.

The probability of accepting a worse move is determined by the formula e^(Delta E / Temperature), meaning the worse the move and lower the temperature, the less likely it is to be accepted.

The algorithm starts with a high temperature, which allows for more exploration, and gradually decreases it over time.

Simulated annealing can help avoid local maxima by allowing occasional downward steps, potentially leading to a better overall solution.

The temperature decline schedule can vary, and different strategies can be applied to manage how quickly the temperature drops.

The probability of accepting worse moves decreases as the temperature decreases, and at very low temperatures, only better moves are accepted.

Simulated annealing uses random selection of moves from possible configurations rather than always picking the best option.

The randomness and controlled temperature decline in simulated annealing help explore different solution spaces, potentially leading to the global maxima.

Transcripts

play00:00

so in our last video we were talking

play00:02

about one of the sort of limitations of

play00:05

uh just working off of hill climbing

play00:07

that issue was specifically if I was at

play00:11

sort of a local Maxima uh I would never

play00:14

go to any potential move that was worse

play00:18

for me and so that's actually where we

play00:21

introduced that idea of maybe we want to

play00:23

attempt to control

play00:27

random and what I mean by that is again

play00:31

if we see that we have a better move if

play00:34

we're trying to maximize and we see

play00:36

something that makes our value go up we

play00:38

obviously take that step

play00:40

but again to sort of resolve this issue

play00:45

of no possible moves what we could do is

play00:49

we could utilize sometimes going down

play00:52

because sometimes going down right may

play00:56

lead us to some bottom but that may lead

play00:59

us to some new better uh Maxima that

play01:03

we've not yet discovered and it so sort

play01:06

of you know again goes the opposite way

play01:08

so when we're trying to minimize yes we

play01:10

want to always go down but sometimes we

play01:13

want to go up and that actually

play01:15

introduces us to what we call Meta

play01:18

heuristics or

play01:20

you often all see the term

play01:23

biologically

play01:26

inspired

play01:30

AI

play01:32

and the entire idea here is looking at

play01:35

something that we see out there in the

play01:37

world as sort of a natural occurrence

play01:39

and saying hey

play01:41

that might work

play01:43

and So Meta heuristics big fancy five

play01:46

dollar word it's just sort of this

play01:48

umbrella term to really kind of talk

play01:50

about all those things that we see out

play01:52

in nature and for at least this first

play01:55

video what I'm going to focus in on it

play01:57

is this idea of simulated annealing now

play01:59

we'll come and we'll explore some of

play02:02

these later on but again what we're just

play02:04

sort of doing is saying oh well maybe

play02:07

there are other heuristics that we could

play02:09

work off of so the best way to think

play02:11

about again that idea of simulated

play02:13

annealing that is another big fancy five

play02:16

dollar word where does it come from well

play02:18

specifically what we do is we think

play02:20

about it like it's metallurgic

play02:23

again if we're thinking about this we're

play02:25

we're a blacksmith we're in a forge you

play02:27

know we're heating up and banging the

play02:30

swords and what's happening as that

play02:34

whole process is going on if I were to

play02:36

draw sort of the edge of uh our blade

play02:40

for a moment

play02:42

right is all of the molecules and atoms

play02:46

that are going on as the blade is being

play02:50

heating up

play02:52

they're moving very radically very fast

play02:55

and so what's technically sort of going

play02:58

on there is this idea that you know we

play03:01

may be seeing some bad positions in

play03:04

those molecules but that's not just the

play03:07

only thing that happens when we start to

play03:09

work off of you know

play03:12

smithing what we do is then we take that

play03:16

we port

play03:19

that's the best bucket you'll see

play03:22

into a bucket of water what happens when

play03:26

we do that is that really hot metal gets

play03:29

quenched into that water and all of

play03:32

those molecules are going to

play03:35

slow

play03:37

down

play03:38

and what happens sort of in that process

play03:41

is we can think about it as very similar

play03:43

to sort of a crystallization process

play03:45

because the molecules have sort of moved

play03:48

all over the place and they crystallize

play03:51

because the temperature's gotten so low

play03:53

they're locked into place and that's

play03:56

actually going to allow us sort of to

play03:58

carry that thought with our optimization

play04:01

problem we can think about sort of this

play04:04

idea of sometimes going down when we had

play04:07

that's not how you start a v

play04:11

you can think about when we sometimes go

play04:13

down is because of just a very high

play04:16

temperature high volatility we're

play04:18

letting the molecules do their dance but

play04:21

then as temperature starts to decline we

play04:24

stop doing this sometimes and only work

play04:26

off of that good times

play04:29

so we allow those worst solutions to

play04:32

happen but we don't always do them so

play04:34

how do we start to kind of take a look

play04:36

at this well we're going to start to

play04:38

look at that objective function one more

play04:40

time we still work off of the idea of

play04:42

sort of that F but now we're going to

play04:44

call it energy

play04:46

big old fit that's not big old fancy e

play04:51

and so what we're looking at when we

play04:52

start to compare our state our state

play04:57

with a next possible state is that we're

play05:00

looking at this idea of the Delta e or

play05:03

change

play05:06

in e

play05:09

as you can sort of see here what we can

play05:11

do with that is just a very simple

play05:13

subtraction so taking whatever that next

play05:15

was going to be or what that next is

play05:18

going to be minus what we currently are

play05:20

and if that is a larger than zero number

play05:24

that's a good move that that distance is

play05:27

a positive move in the right direction

play05:29

and so from our perspective that's where

play05:32

we look at that always

play05:36

go up

play05:39

again probability of going up is one

play05:41

meaning yes we do it but more

play05:44

specifically again we're trying to look

play05:46

at when

play05:47

we're dealing with that sometimes going

play05:49

down and that's when we get a move that

play05:52

is not so good we take our next and then

play05:56

we subtract our current position and we

play05:58

still get a Delta e but what if that

play06:01

Delta e is negative

play06:05

well in that case again if we're

play06:07

thinking about it that's not a good step

play06:09

forward not a good step forward but we

play06:12

still want to accept it because we're

play06:14

working off of that idea that right now

play06:16

we're in a highly volatile situation and

play06:19

the step is okay how we do that is we

play06:23

determine

play06:26

the probability through e raised to the

play06:28

power of Delta energy over what our

play06:32

current temperature is at this given

play06:34

time step

play06:36

a lot of words a lot of stuff going on

play06:38

there right and so the big idea here is

play06:41

again what's happening is that uh this

play06:44

suddenly becomes proportional to the

play06:46

energy difference so as this

play06:50

energy difference occurs

play06:53

if it's a large distance oh it's not a

play06:56

good move and it's a really really bad

play06:57

move but if it's a super small you know

play07:00

difference that's not so bad and then

play07:02

secondly we've got the idea of t t he is

play07:05

working by going down right I want my T

play07:09

my T started at say for example 100 I

play07:12

want to gradually reach maybe one or

play07:15

zero well you can't divide by zero so

play07:17

gradually go down to one and when that's

play07:20

occurring this number

play07:24

is going to get much lower and we'll see

play07:26

sort of an example of that in just a bit

play07:28

but just to kind of help calm your minds

play07:31

a little bit all we need to do is if

play07:33

we're trying to minimize instead is all

play07:35

we have to do is flip which one is

play07:38

subtracted first or from the other one

play07:42

so to take a look at this there's a very

play07:44

simple pseudo code going on here the

play07:47

first part is again if we're thinking

play07:49

about sort of my prior video what we're

play07:52

doing is not a search tree right we're

play07:56

not doing this we're going through a

play07:59

loop well how often does that Loop run

play08:02

technically it can run an infinite

play08:05

number of times again

play08:06

could just keep on running and you know

play08:09

hopefully we eventually reach some point

play08:11

where we can stop it but again it can

play08:14

just run forever

play08:16

then specifically we look at that idea

play08:18

of T and T declining as lowercase T in

play08:22

this case goes down or in our case you

play08:26

know it's going from one to a million

play08:28

whatever whatever we're looking at is

play08:31

specifically we could design out our

play08:34

temperature decline schedule

play08:36

well what that means is again maybe we

play08:39

start with a very high temp

play08:44

but as you notice it's a very very quick

play08:47

drop off

play08:49

before leveling out and so T doesn't

play08:51

change

play08:54

doesn't

play08:58

change there that's a way we can write

play09:01

that

play09:02

that works that's one approach that we

play09:04

could do here's another approach that we

play09:07

could do the point being is what we're

play09:09

looking to do is just establish T is

play09:12

some value because again

play09:15

looking at that algorithm we have

play09:18

are our difference proportional to T so

play09:21

we wanted to gradually start to go down

play09:26

then what we're looking at is

play09:27

specifically you know oh well if T hits

play09:30

zero we could consider that good enough

play09:32

and you know we're done or you could

play09:35

strip this out entirely and just not

play09:37

ever have this

play09:39

be a part of the algorithm again you

play09:41

just constantly are moving through your

play09:43

search

play09:45

slowly declining T however you want

play09:47

maybe you wanted to go down by a

play09:49

percentage instead of a hard you know by

play09:51

one number

play09:53

either way works but specifically what

play09:56

we're looking at is when we had some

play09:59

configuration right we're going to look

play10:02

at all of the possible steps that that

play10:05

configuration could do so c 1 a c 1 b c

play10:12

1 c c 1 D these are all just possible

play10:17

steps that we could work off of and

play10:20

specific to simulated annealing in that

play10:22

idea of

play10:24

controlling

play10:27

random

play10:30

I just pick one I just doesn't matter

play10:33

I'm not looking for the best I'm not

play10:34

looking for the worst I'm just going to

play10:36

pick one of them I'm going to say for

play10:38

this case you know oh this time around I

play10:40

pick c1b that's it then what I do is I

play10:45

say well what is the Delta this is

play10:48

technically the Delta e of that

play10:50

candidate so that would be the c1b

play10:55

minus

play10:57

C1 whatever the evaluation the F score

play11:00

the fitness measure of C1 was check the

play11:03

difference once again if it's greater

play11:06

than zero again if we're trying to

play11:08

maximize

play11:09

immediately go to it we're done awesome

play11:11

right

play11:13

we're good but more specifically when

play11:16

we're dealing with when it's not not

play11:20

a good

play11:23

move

play11:26

we want to sometimes do it we need to

play11:29

sometimes do it again to potentially

play11:31

break out of local maximums and to do

play11:34

that again what we're looking at is this

play11:36

idea

play11:38

of some proportional distance again we

play11:41

want this to happen because again this

play11:43

is going to allow us to calculate that

play11:45

out we figure out what that probability

play11:47

is let's arbitrarily say that our P

play11:50

currently equals you know 65.

play11:54

right so there's a 65 chance we take

play11:57

that value because what that does is

play12:00

then if I show it again P being 65 I'm

play12:04

going to generate some random number

play12:09

some random number between 0 and 1.

play12:14

because all right well if that number is

play12:17

less than 65 so let's say I generated a

play12:21

0.25 well happen that happens to be a

play12:24

true statement that is less than 65

play12:27

therefore we can say okay well that is

play12:31

you going into that new move that works

play12:36

same kind of thing going on if it

play12:38

doesn't if it's uh 75

play12:41

oh this is not a true statement

play12:45

we don't make the step this time so

play12:48

again let's sort of play this out see

play12:50

what happens here

play12:52

so again we're working off of our simple

play12:54

example I've generated a fitness score

play12:57

of 106. I have all my potential

play13:00

candidates again red switching with

play13:02

orange red switching with green red

play13:04

switching with blue red switching with

play13:06

purple again just working off of those

play13:09

to make it easier for me

play13:11

but my point being is okay I can make

play13:13

one swap

play13:15

which one do I pick

play13:17

I pick one at random I pick arbitrarily

play13:20

one at random because again we're making

play13:24

the assessment of whether or not we do

play13:25

this again with sort of our our next

play13:28

approach

play13:29

if we're dealing with something that is

play13:31

better again let's say arbitrarily we

play13:33

want to maximize our value and we

play13:35

randomly picked uh you know this third

play13:38

option

play13:40

well again that's a better move so yes

play13:43

we obviously take that move but then you

play13:47

notice I have three other possibilities

play13:50

I have sort of a worse move here a worse

play13:53

move here and a worse move here if I

play13:56

picked any one of those again we have to

play13:59

say I might take that route and to do

play14:03

that again what we're looking at is this

play14:05

idea let's say if we picked this one

play14:08

well the Delta e for this is again 93

play14:13

minus 106

play14:15

which turns into a negative 13. negative

play14:18

13 means it's a bad move it's less than

play14:20

zero

play14:22

so we have to make a few more steps

play14:25

so again if we're looking at that

play14:27

pseudocode we generate out what is the

play14:29

probability that we go to that move and

play14:32

it's e to the negative 13 negative 13

play14:37

over t

play14:39

okay

play14:40

what's T to kind of take this into

play14:44

perspective here's just me you know

play14:46

cheating with a little python so let's

play14:48

arbitrarily say that t is 100 right and

play14:52

we're gonna just make it go down by one

play14:54

every single time so 4 I in range uh T

play14:59

to 1 with a step of negative one right

play15:05

that in mind again what I'm trying to do

play15:07

is calculate out the probability so the

play15:10

prob is going to equal math dot e you

play15:13

can see I I sort of cheated here and I

play15:15

already had that imported in math.e

play15:19

raised to the power of negative 13 over

play15:23

t

play15:25

or sorry it would be I in this case

play15:29

and so again that's going to be

play15:33

1998 97 96 Etc up to 1. and so I'm going

play15:38

to just print that out so here's that I

play15:41

here's the value and then what is the

play15:43

probability at that particular

play15:46

temperature level we take this we run it

play15:48

and what you can see here specifically

play15:51

is again when T is 100 right

play15:55

we have an 87 chance of making that step

play16:00

87.8 chance and then as T goes down

play16:05

87.7

play16:06

87.6 87.5 if I start to jump down to

play16:11

let's say 65 right that probability is

play16:16

now 87 or

play16:18

81.9 if I keep jumping down to say 35

play16:23

probability of making this step or

play16:25

selecting this 93 would be a 68.9 or you

play16:30

know 69 uh as we get down to a 10 you

play16:34

know where temperature is super low at

play16:36

this point our probability is starting

play16:37

to hit

play16:39

0.273 right we're starting to get lower

play16:42

and lower until as we reach ultimately

play16:45

to those zero values the probability

play16:48

becomes so low that we don't do it

play16:52

so again what this allows us to do is we

play16:54

make these types of selections because

play16:57

the hope is that after we made this hop

play17:01

there

play17:03

May

play17:05

be a chance

play17:09

at

play17:11

something

play17:15

better

play17:18

than

play17:20

106. and again that's the sole purpose

play17:23

because we're maybe getting out of that

play17:26

that that that little local Maxima that

play17:30

we're dealing with we may be able to

play17:31

move towards a better local Maxima or

play17:35

the the mythical Global Maxima that may

play17:38

be impossible for us to otherwise find

play17:40

out

play17:41

and that simulated annealing in a

play17:43

nutshell

Rate This

5.0 / 5 (0 votes)

Связанные теги
Simulated AnnealingMetaheuristicsOptimizationAI TechniquesHeuristicsLocal MaximaEnergy FunctionProbabilityAlgorithm DesignRandom Search
Вам нужно краткое изложение на английском?