The simulated annealing algorithm explained with an analogy to a toy

Badri Adhikari
4 Feb 201711:15

Summary

TLDRThe video explains the simulated annealing algorithm, a method used to solve optimization problems by mimicking the controlled cooling process in metallurgy. It starts with a random configuration and gradually improves it, accepting both good and bad moves depending on a temperature variable that decreases over time. The algorithm is applied to complex problems like the traveling salesman and protein structure design. The video also contrasts simulated annealing with hill climbing and random walk methods, highlighting its balance between exploration and optimization.

Takeaways

  • ๐Ÿ”ง The simulated annealing algorithm is inspired by the annealing process in metallurgy, where controlled cooling strengthens metals.
  • ๐Ÿšถ Simulated annealing is widely used in solving optimization problems like the traveling salesman, circuit board design, robot path planning, and bioinformatics.
  • ๐Ÿ”„ The algorithm allows for accepting both good and bad moves initially, becoming more selective as it progresses, similar to how we play a water ring game.
  • ๐Ÿ“Š To apply simulated annealing, we need a way to define the 'energy' or 'fitness' of a solution, which is a measure of how good a configuration is.
  • ๐ŸŽฏ The goal is to avoid getting stuck in local minima or maxima and work toward the global optimum solution.
  • ๐Ÿ’ก The process involves computing the change in energy, represented by delta E, after altering the system's configuration.
  • ๐ŸŒก๏ธ Temperature (T) is a key factor in the algorithm. Initially, the temperature is high, allowing bad moves to be accepted with high probability, and it decreases gradually.
  • ๐Ÿ“ˆ As the temperature decreases, the algorithm becomes less likely to accept bad moves, focusing on refining the solution.
  • โš™๏ธ The algorithm repeats this process over several iterations (epochs) with different temperature values, trying to reach the global minimum or maximum.
  • ๐Ÿ” The parameters like Tmax, Tmin, and number of epochs depend on the specific problem being solved and can be adjusted based on trial and error.

Q & A

  • What is the origin of the term 'annealing' in the simulated annealing algorithm?

    -'Annealing' comes from metallurgy, where it refers to a process of slow and controlled cooling to make strong metallic objects. This concept is applied to the simulated annealing algorithm in computer science.

  • What types of problems can the simulated annealing algorithm be used to solve?

    -The simulated annealing algorithm is commonly applied to solve problems like the travelling salesman problem, designing printed circuit boards, robot path planning, and in bioinformatics to design 3D protein structures.

  • How does the water bubble ring toy help explain the simulated annealing algorithm?

    -The toy illustrates how one might start by pressing buttons vigorously (randomly exploring the solution space), then progressively become more careful and deliberate (moving towards an optimal solution). This mimics the way simulated annealing explores different configurations before narrowing down to a better solution.

  • How does the simulated annealing algorithm treat bad moves during the optimization process?

    -In the beginning, the algorithm allows bad moves to explore the solution space, but as it progresses (temperature decreases), the acceptance of bad moves becomes less likely, guiding the algorithm towards better solutions.

  • What is the role of energy in the simulated annealing algorithm?

    -Energy (E) measures how good a configuration is in optimization problems. The algorithm computes the energy change (ฮ”E) between configurations, and this value is used to decide whether to accept a new configuration.

  • What is a local maximum, and why is it important in the simulated annealing algorithm?

    -A local maximum is a point in the solution space where the configuration appears optimal but is not the best possible solution (global maximum). The simulated annealing algorithm must avoid getting stuck in local maxima by accepting occasional bad moves early in the process.

  • How does temperature influence the acceptance of bad moves in the simulated annealing algorithm?

    -At high temperatures, the probability of accepting bad moves is high, allowing exploration of the solution space. As temperature decreases, this probability lowers, leading the algorithm to focus on good moves and refine the solution.

  • What happens if the change in energy (ฮ”E) is very high during the optimization process?

    -If the change in energy (ฮ”E) is very high, the probability of accepting the move decreases, indicating a larger difference between the old and new configurations, and the algorithm is less likely to accept the move.

  • What is the difference between hill climbing and random walk algorithms compared to simulated annealing?

    -Hill climbing always accepts better moves, making it prone to getting stuck in local maxima. A random walk ignores the quality of moves, leading to endless exploration. Simulated annealing balances exploration and optimization by allowing bad moves initially but becoming selective as the solution progresses.

  • What are the key parameters in the simulated annealing algorithm, and how are they determined?

    -The key parameters are maximum temperature (Tmax), minimum temperature (Tmin), and the number of epochs (iterations). Tmax is usually set to a high value (e.g., 3000-5000), Tmin to a low value (e.g., 0-10), and the number of epochs typically ranges from 100 to 200. These parameters are problem-dependent and adjusted based on trial and error.

Outlines

00:00

๐Ÿ”ง Introduction to Simulated Annealing Algorithm

The speaker introduces the concept of simulated annealing, a technique inspired by the annealing process in metallurgy. They explain that annealing involves controlled cooling to create strong metallic objects and how this idea is applied in computer science to solve optimization problems like the traveling salesman, circuit board design, robot path planning, and protein structure modeling.

05:00

๐ŸŽฎ Water Bubble Rings Game as an Analogy

To explain simulated annealing, the speaker uses the water bubble rings game as a metaphor. Initially, players press buttons randomly, but as they get closer to hooking rings, they become more deliberate. This mirrors simulated annealing, where early moves can be random or 'bad,' but later moves become more calculated as the solution improves.

10:01

๐Ÿ“Š Configurations and Energy in Optimization

The speaker describes the importance of defining how 'good' a solution is in any problem tackled by simulated annealing. In the water bubble rings game, the fitness of a solution is determined by the number of rings hooked. Similarly, in optimization problems, the system's configuration is measured by its energy level, and changes in this energy (delta E) are used to evaluate moves.

๐Ÿ”„ Local vs Global Maximum and Deadlock

The concept of local maximum is explained through the example of getting stuck with many rings on one hook in the game, leading to a deadlock. This situation represents a local maximum where progress stalls. In optimization, it is crucial to distinguish between local and global maxima and minima to avoid deadlock and move towards the optimal solution.

๐Ÿ”ฅ Temperature and the Simulated Annealing Process

Simulated annealing involves gradually lowering the temperature, just like in metallurgy, to allow a system to settle into an optimal configuration. At high temperatures, bad moves are accepted more readily to explore solution space, but as the temperature decreases, the algorithm favors only good moves, refining the solution towards the global optimum.

๐Ÿ“ˆ Probability and Accepting Moves

The speaker discusses the probability of accepting moves in simulated annealing. At high temperatures, bad moves are accepted with higher probability, allowing for exploration. As the temperature drops, this probability decreases, limiting the acceptance of bad moves and ensuring the system gradually converges toward the best solution.

๐Ÿ”๏ธ Hill Climbing vs Random Walk

Two alternative algorithms are discussed: hill climbing, which only accepts good moves and is prone to getting stuck in local minima, and random walk, which explores the solution space indiscriminately and never converges to an optimal solution. Simulated annealing strikes a balance between these extremes by introducing temperature and probability factors.

๐Ÿ“‰ Configurable Parameters of Simulated Annealing

The speaker emphasizes that key parameters like maximum temperature, minimum temperature, and the number of epochs (iterations) depend on the problem being solved. These parameters need to be adjusted through experimentation to ensure the algorithm avoids local minima and moves toward the global optimum.

๐Ÿ”š Conclusion

The speaker wraps up by explaining how repeated runs of simulated annealing, adjusting the parameters, help determine whether the solution is heading toward a global minimum or stuck in a local minimum. They conclude by thanking the audience for their attention.

Mindmap

Keywords

๐Ÿ’กSimulated Annealing

Simulated annealing is an optimization algorithm inspired by the annealing process in metallurgy. It is used to find approximate solutions to complex problems by gradually reducing randomness (or 'temperature') in exploring possible solutions. In the video, it is described as a method to solve various computational problems, such as the traveling salesman problem, by accepting both good and bad moves initially and becoming more selective as the process progresses.

๐Ÿ’กAnnealing

Annealing is a process from metallurgy in which materials are heated and then cooled in a controlled manner to improve their properties. The video draws an analogy between this and the simulated annealing algorithm, where the system starts with high randomness (high temperature) and gradually becomes more focused on optimal solutions (cooling) as the temperature decreases.

๐Ÿ’กOptimization Problem

An optimization problem is a problem in which the goal is to find the best solution from a set of possible solutions. In the context of the video, problems like designing circuit boards or solving the traveling salesman problem are framed as optimization problems, where simulated annealing helps in finding the 'best' configuration or solution.

๐Ÿ’กEnergy Landscape

The energy landscape is a metaphor used to describe the set of all possible configurations of a system, with their associated energy levels. Peaks and valleys represent local maxima and minima, which are important in optimization. The goal of simulated annealing, as described in the video, is to find the global minimum (or maximum) without getting trapped in a local minimum.

๐Ÿ’กLocal Maximum/Minimum

A local maximum (or minimum) is a point in the energy landscape where a solution seems optimal compared to nearby solutions, but it may not be the best overall. In the video, this concept is illustrated by the water bubble game, where focusing too much on one hook can lead to a deadlock, analogous to getting stuck in a local maximum during optimization.

๐Ÿ’กGlobal Maximum/Minimum

The global maximum (or minimum) is the best possible solution in the entire energy landscape. The objective of optimization algorithms like simulated annealing is to find this global solution. In the video, it is mentioned as the desired outcome when maximizing the number of hooked rings in the water bubble game or when solving other optimization problems.

๐Ÿ’กTemperature

In simulated annealing, temperature is a controlling parameter that dictates how much randomness or exploration is allowed in the system. High temperatures allow for more exploration, including accepting bad moves, while low temperatures focus on refining the solution. The video uses this concept to explain how the algorithm balances between exploring new solutions and refining existing ones.

๐Ÿ’กEnergy (E)

Energy (E) represents the 'goodness' or fitness of a solution in an optimization problem. The goal of the simulated annealing algorithm is to minimize or maximize this energy depending on the problem. In the water bubble game example, energy is analogous to the number of rings hooked onto the pegs, with higher energy representing a better configuration.

๐Ÿ’กEpoch

An epoch refers to a cycle or iteration in which the simulated annealing algorithm processes solutions at a particular temperature level. The video explains that the algorithm typically runs through hundreds of epochs, gradually reducing the temperature with each one, allowing the system to converge toward a global solution.

๐Ÿ’กHill Climbing

Hill climbing is a simpler optimization algorithm where only moves that improve the solution are accepted, making it prone to getting stuck in local maxima or minima. The video contrasts hill climbing with simulated annealing, highlighting that the latter accepts bad moves early on, reducing the risk of being trapped in suboptimal solutions.

Highlights

Simulated annealing is inspired by the annealing process in metallurgy, which uses slow, controlled cooling to create strong metal objects.

The algorithm is widely applied in problems like the traveling salesman problem, printed circuit board design, robot path planning, and protein molecule structure design in bioinformatics.

The game analogy helps explain the concept of simulated annealing: at first, you play randomly and accept bad moves, but as you get closer to the solution, you become more deliberate and careful.

At the beginning of the algorithm, bad configurations are accepted, but as the solution progresses, only good moves are selected to reach the final goal.

To apply simulated annealing, you need a way to measure how good a configuration is. This is often described as the 'energy' or 'fitness' of the system.

Energy (E) of the system is computed for each configuration, and the change in energy (ฮ”E) is calculated when a new configuration is introduced.

In optimization problems, local maxima or local minima can occur, where a solution seems optimal but is not the global best.

Global maxima or minima represent the true optimal solution, while local optima can trap the system in suboptimal configurations.

The algorithm starts with a high temperature (Tmax) and gradually cools down to a low temperature (Tmin), simulating the annealing process in metallurgy.

At high temperatures, the probability of accepting bad moves is high, allowing exploration of the solution space. As the temperature lowers, the probability decreases, leading to more selective moves.

If a new configuration improves the system's energy (ฮ”E is positive), it is accepted. If it worsens the energy (ฮ”E is negative), it may still be accepted with a certain probability, depending on temperature.

The number of iterations (epochs) and temperature values (Tmax and Tmin) are parameters that need to be set based on the problem being solved.

Simulated annealing strikes a balance between two extremes: hill climbing, which only accepts better moves and is prone to getting stuck in local optima, and random walk, which explores without considering solution quality.

Hill climbing is a greedy algorithm that always goes toward better solutions but risks getting stuck in local minima.

Random walk, by contrast, explores the space without caring about the quality of moves, but it never converges to the best solution.

Transcripts

play00:00

Today I will explain the simulated

play00:03

annealing algorithm. The word annealing

play00:07

comes from metallurgy. In metallurgy, to make

play00:12

really strong metallic objects, people

play00:15

follow a slow and controlled cooling

play00:17

procedure known as annealing. The same can

play00:22

be applied to computer science algorithms

play00:23

The simulated annealing algorithm is widely

play00:28

applied to solve problems like

play00:29

travelling salesman problem, designing

play00:32

printed circuit boards, for planning of a

play00:36

path for a robot, and in bioinformatics

play00:40

to design three-dimensional structures

play00:44

of protein molecules. To better explain

play00:48

algorithm I have here with me

play00:50

our toy game known as water bubble rings.

play00:53

So this is a small water container that

play00:57

has these plastic rings inside and has

play00:59

some hooks as well.

play01:01

It also comes with these two buttons

play01:04

which can be pressed, so when we press

play01:07

the buttons, the rings move inside the water.

play01:09

Obviously the objective in this game is

play01:12

to get as many rings hooked as we can.

play01:15

So, how does someone play this game?

play01:20

If we were to play it how would we play it?

play01:22

Intuitively, we would first start by pressing the

play01:26

buttons vigorously and by checking to

play01:29

see if we can get all rings hooked or

play01:31

checking to see as many see if we can

play01:34

get as many rings hooked as we can

play01:36

without worrying about the solution so

play01:38

that's how we would start and once we

play01:41

have some rings hooked in the hooks, we will

play01:45

be more careful after that, we will be more

play01:47

deliberate and we'll play it more

play01:49

seriously, as we get closer to the final

play01:52

solution, we will be very careful very deliberate

play01:56

and out final moves will be extremely carefully planed

play01:59

so that's the intuition behind the simulated annealing algorithm

play02:01

At the beginning you don't care

play02:03

if you are

play02:05

actually moving towards the good solution and you

play02:07

accept bad moves as well, you accept

play02:09

bad configurations as well but as you

play02:11

progress towards the solution we become

play02:13

more careful and we try to get closer to

play02:16

the solution and by selecting only the good

play02:18

moves. So to formulate any problem in order

play02:22

to apply algorithms like simulated

play02:23

annealing every problem needs to have a

play02:26

way to define how good a given

play02:30

configuration is. So, for this particular

play02:32

game, for this particular toy, given a

play02:36

configuration of this toy, we can tell how

play02:39

good the solution is by checking the

play02:41

number of rings that are hooked, right?

play02:43

So every system or every problems that

play02:45

you're solving needs to have a way to

play02:47

describe the goodness or the fitness of

play02:51

the solution for the problem. In other

play02:53

words we need to, in optimization problems,

play02:55

also known as energy of the solution, in

play02:58

other words we need to have a mechanism

play02:59

to define the energy of the system. So if

play03:03

E is the energy of the system we represent

play03:07

the energy using E, and once we have

play03:12

a mechanism to compute E, you can also compute

play03:15

delta E or change in energy. So every time

play03:18

the system goes through a change of

play03:20

configuration, we can compute the

play03:21

change in energy.

play03:23

Now, talking about this game, when

play03:27

somebody's playing this game one

play03:28

can play it in a specific way

play03:30

so someone can focus in just one of the

play03:32

hooks and continue to play the game so

play03:35

that he or she can get as many rings as

play03:38

possible in one of the holes, forgetting

play03:40

about the remaining hooks. Now if we play

play03:42

like that, after a certain time, we will end

play03:46

up in a deadlock where we have a lot of

play03:48

rings hooked in one of the hooks but

play03:50

the other hooks are empty. At that point if you

play03:53

play vigorously you will you will

play03:56

remove lot of the rings which are already solved

play03:58

and you play it very slow it will take a

play04:00

really long time to get to the final solution. So,

play04:03

situations like that in optimization

play04:05

problems are known as a local maximum or

play04:08

local minimum, so you were to plot

play04:12

all possible configurations of a given

play04:16

system in X axis and in Y axis we were to compute

play04:21

the corresponding energy of all the

play04:23

configurations than energy landscape

play04:26

usually looks something like this so

play04:30

high values correspond to maximum energy in our

play04:33

case since we want maximum number of

play04:35

rings to be hooked

play04:37

it's a maximization problem and we want

play04:40

the maximum value of energy for our

play04:42

problem and places like these in the

play04:45

energy landscape which look like we have

play04:49

to look like

play04:50

hi value in energy but which actually

play04:53

take us to the deadlock are known as a

play04:55

local maximum or if you are trying to

play04:58

minimize the energy that these are also

play05:00

known as local minimum. And the actual energy

play05:05

that we want or the configuration that we want

play05:07

and the maximum energy is known as a

play05:09

global maximum, if we're trying to

play05:11

find the maximum. So this is something that we

play05:15

need to become vigilant about when applying

play05:18

algorithms like these to solve the problem is a

play05:21

to be careful and to check if we are

play05:23

actually being stuck in a local minima

play05:25

but we're actually getting closer to the

play05:28

the global maxima or global minimum. Now, once we have

play05:35

a way to define energy once and once we

play05:37

know about global minima an global maxima, we

play05:41

also need a way in which we can change

play05:42

the configuration of the system every

play05:44

time so in the water bubble rings game

play05:48

in this toy, we can change the

play05:50

configuration by placing the

play05:51

button, so it randomly alters the

play05:53

configuration of the system so that we

play05:55

get a new configuration. So every problem

play05:58

that we apply algorithm like this

play06:00

needs to have a mechanism to alter

play06:03

the configuration and so you see the

play06:04

current configuration, we need to have a

play06:06

mechanic to alter the current configuration

play06:08

to the next configures and and usually

play06:11

this is this is also known as making a move

play06:13

in the water bubble rings we

play06:16

make it just by pressing the button

play06:19

So, once we have the these definitions laid out

play06:21

now I would like to explain the

play06:23

simulated annealing algorithm

play06:25

So the idea is to start with the initial configuration

play06:28

or given random configuration

play06:29

Then, we use introduce a variable

play06:32

known as temperature. Just the way in

play06:34

case of annealing we start with initial

play06:37

high temperature and we slowly

play06:38

controlled cool the material, for the algorithm

play06:43

we start with a maximum temperature

play06:45

Tmax, and this is a monotonic

play06:47

decreasing function that slowly

play06:49

decreases to Tmin, or minimum temperature

play06:52

so whatever value of temperature we

play06:55

first compute the current energy of the

play06:57

system, for the current configuration C

play07:00

using E(C), then we change the

play07:04

configuration or alter the configuration

play07:05

a little bit using the technique for

play07:08

altering the configuration and then we

play07:10

get the new configuration and we compute

play07:12

the energy for this new configuration

play07:14

Once we have EC and EN, we can compute

play07:18

Delta E or change in energy and so

play07:21

now we have old configuration C or the

play07:24

current configuration C and see the new

play07:26

configuration N and we know that

play07:28

change in energy. Since we are working on

play07:30

a maximization problem if delta E is

play07:33

positive or the change in energy is a

play07:36

good one, or if it's a good move

play07:37

we accept the move. In other words we set

play07:40

the next configuration to the current

play07:42

configuration and we accept the move, and we

play07:44

repeat the process so so that we are

play07:46

getting closer to the we're getting a

play07:48

better solution, and move close to the

play07:50

final solution. At every step,

play07:53

if we see that change in energy is

play07:56

negative or in other words, if we are

play07:58

making a bad move then what do we do?

play08:02

In cases like these, we compute this

play08:03

probability, I will give the details of this,

play08:05

but we compute the probability of

play08:07

this and then if we see that the

play08:09

probability is very high then we accept

play08:13

the move even if it is a bad more and if

play08:16

the probability is low, then we have low

play08:18

probability to accept the bad move. So this

play08:22

probability depends on these two variables

play08:24

change energy delta E and the

play08:27

temperature factor T. When

play08:29

temperature is very high then the

play08:31

probability for accepting the bad move

play08:32

becomes very high, in other words, at high

play08:36

temperatures we are exploring the solution

play08:39

space or we are exploiting the

play08:41

configurations and we're accepting

play08:42

bad moves as well, and when the temperature

play08:45

is low this probability becomes very

play08:47

low and we have very low probability to

play08:49

accept bad moves. Say, for instance when

play08:52

temperature is very high, say 10,000 and

play08:55

change in energy is not very high, say 100 or 10

play09:00

then this whole thing computes to a

play09:02

a small negative number

play09:06

e to the power small negative number gives you

play09:08

something very close to one and a number

play09:11

that is close to one has a very high (correction)

play09:13

probability to become greater than a

play09:15

random number between 0 and 1, which means we get

play09:20

a very high probability, so when temperature

play09:22

is very high

play09:23

we have high probability to accept bad

play09:25

moves as well. Now, we also see that the change

play09:29

in energy, delta E also influences it, so if

play09:30

that change in energy is really high

play09:32

we are again have a low probability to

play09:34

accept the move and when the change in energy is

play09:36

small we have a high probability to accept the move.

play09:38

So this is how the whole algorithm works

play09:40

So, we repeat the process

play09:42

for certain number of times

play09:44

usually known as the number of epochs, usually 100 to 200 times

play09:47

and for every value of temperature

play09:49

we repeat the process and finally expecting

play09:52

the solution to converge towards the

play09:54

global minimum. So that's the idea behind

play09:56

the algorithm. Now on either extremes are 2 other algorithms

play10:00

known as hill climbing and

play10:02

random walk. So if we remove the

play10:07

probability factor or the temperature

play10:09

factor and always accept the good moves only

play10:11

then that's hill climbing

play10:13

or it's like a greedy algorithm which always go

play10:15

towards a better solution. Such, algorithms are

play10:18

prone to easily be stuck in local minima.

play10:21

On the other end is a random walk which

play10:24

means, we don't care about

play10:26

how good a move we are making every time but we

play10:29

just explore, continue to explore, the space

play10:31

Such algorithms never converge and

play10:34

will probably never give you the best

play10:36

optimal solution. Now the parameters Tmax

play10:41

Tmin, and number of epoch are dependent on

play10:43

the problem that we are solving, usually

play10:46

we start with high temperatures like a

play10:48

few thousands, let's say 3000 or 5000 and then

play10:50

the minimum temperature is set to a small value like 0 or 10

play10:53

or something like that. Number of epoch is usually

play10:56

a hundred, or 200 depending on the problem

play10:58

so these are the parameters that you can

play11:00

explore by applying the algorithm to

play11:03

problem that we have, and if you run it

play11:05

multiple times you will have an idea of whether

play11:07

you're being stuck in the local minima or

play11:10

you're heading towards the global minimum

play11:13

thank you

Rate This
โ˜…
โ˜…
โ˜…
โ˜…
โ˜…

5.0 / 5 (0 votes)

Related Tags
Simulated AnnealingOptimizationAlgorithmEnergy LandscapeLocal MinimaGlobal MaximumProblem SolvingTemperature VariableTraveling SalesmanHill Climbing