NMath User's Guide

TOC | Previous | Next | Index

28.2 Annealing Schedules (.NET, C#, CSharp, VB, Visual Basic, F#)

In simulated annealing, the annealing schedule governs the choice of initial temperature, how many iterations are performed at each temperature, and how much the temperature is decremented at each step as cooling proceeds.

For example, the annealing schedule shown in Table 21 has four steps.

Table 21 – A sample annealing schedule

Step

Temperature

Iterations

1

100

20

2

75

20

3

50

20

4

0

20

In this case, the temperature decays linearly from 100 to 0, and the same number of iterations are performed at each step.

NOTE—Annealing schedules must end with a temperature of zero. Otherwise, they never converge on a minimum.

In NMath, AnnealingScheduleBase is the abstract base class for classes that define annealing schedules. Two concrete implementations are provided.

Linear Annealing Schedules

Class LinearAnnealingSchedule encapsulates the linear decay of a starting temperature to zero. Each step has a specified number of iterations. For example, this code creates the annealing schedule shown in Table 21:

Code Example – C# simulated annealing

int steps = 4;
int iterationsPerStep = 20
double startTemp = 100.0;

LinearAnnealingSchedule schedule = new LinearAnnealingSchedule( 
  steps, iterationsPerStep, startTemp );

Code Example – VB simulated annealing

Dim Steps = 4
Dim IterationsPerStep = 20
Dim StartTime As Double = 100.0

Dim Schedule As New LinearAnnealingSchedule(Steps, 
  IterationsPerStep, StartTemp)

You may optionally also provide a non-default error tolerance. At each annealing step, iteration stops if the estimated error is less than the tolerance, but typically this only occurs during the final step, when the temperature is zero.

Once constructed, a LinearAnnealingSchedule instance provides the following properties:

Steps gets the number of steps in the schedule.

Iterations gets and sets the number of iterations per step.

TotalIterations gets and sets the total number of iterations in this schedule. When set, the number of iterations per step is scaled appropriately.

StartingTemperature gets and sets the starting temperature.

Tolerance gets and sets the error tolerance used in computing minima estimates.

Custom Annealing Schedules

For more control over the temperature decay, you can use class CustomAnnealingSchedule. Instances of CustomAnnealingSchedule are constructed from an array containing the number of iterations for each step, and the temperature for each step.

For example:

Code Example – C# simulated annealing

var iterations = new int[] { 50, 30, 20, 20 };
var temps = new double[] { 75.3, 20.0, 10.5, 0.0 };

var schedule = 
  new CustomAnnealingSchedule( iterations, temps );

Code Example – VB simulated annealing

Dim Iterations() As Integer = {50, 30, 20, 20}
Dim Temps() As Double = {75.3, 20.0, 10.5, 0.0}

Dim Schedule As New CustomAnnealingSchedule(Iterations, Temps)

NOTE—An InvalidArgumentException is raised if the final temperature in a custom annealing schedule is not zero. Without a final temperature of zero, the system never settles into a minimum.

You may optionally also provide a non-default error tolerance. At each annealing step, iteration stops if the estimated error is less than the tolerance, but typically this only occurs during the final step, when the temperature is zero.

Once constructed, a CustomAnnealingSchedule instance provides the following properties:

Steps gets the number of steps in the schedule.

Iterations gets and sets the arrray of iterations for each step.

TotalIterations gets and sets the total number of iterations in this schedule. When set, the number of iterations per step is scaled appropriately.

Temperatures gets and sets the vector of temperatures for each step.

Tolerance gets and sets the error tolerance used in computing minima estimates.


Top

Top