NMath User's Guide

TOC | Previous | Next | Index

28.4 Annealing History (.NET, C#, CSharp, VB, Visual Basic, F#)

For annealing to successfully locate the global minimum of a function, an appropriate annealing schedule must be chosen, but unfortunately this is something of a trial-and-error process. An appropriate regime is entirely dependent on the characteristics of the function being minimized, which may not be well understood in advance.

To help you in this process, class AnnealingMinimizer can be configured to keep a history of the annealing process. There is a cost in memory and execution to record this information, so it is not enabled by default. To record the annealing history, set the KeepHistory property to true. Thus:

Code Example – C# simulated annealing

var minimizer = new AnnealingMinimizer( schedule );
minimizer.KeepHistory = true;

Code Example – VB simulated annealing

Dim Minimizer As New AnnealingMinimizer(Schedule)
Minimizer.KeepHistory = True

AnnealingMinimizer performs a minimization at each step in an annealing schedule. When history is turned on, the results of each step are recorded in an AnnealingHistory object. This data may be useful when adjusting the schedule for optimal performance. For example, this code prints out the complete history after a minimization:

Code Example – C# simulated annealing

DoubleVector min = minimizer.Minimize( f, startingPoint );
AnnealingHistory history = minimizer.AnnealingHistory;
Console.WriteLine( history );

Code Example – VB simulated annealing

Dim Min As DoubleVector = Minimizer.Minimize(F, StartingPoint)
Dim History As AnnealingHistory = Minimizer.AnnealingHistory
Console.WriteLine(History)

AnnealingHistory also provides a variety of properties for accessing specific information:

Function gets the function that was minimized.

MaximumIterations gets the number of maximum iterations at each step in the annealing history.

Iterations gets the number of iterations actually performed at each step in the annealing history.

Temperatures gets the temperatures at each step in the annealing history.

Simplexes gets the starting simplexes at each step in the annealing history.

MinimumPoints gets the minima computed at each step in the annealing history.

MinimumValues gets the function evaluated at the minima computed at each step in the annealing history.

Errors gets the errors at each step in the annealing history.

The inner class AnnealingHistory.Step encapsulates all of the data associated with a particular step in an AnnealingHistory. The AnnealingHistory.Steps property returns a IList of the steps in the annealing history:

Code Example – C# simulated annealing

AnnealingHistory history = minimizer.AnnealingHistory;
foreach( AnnealingHistory.Step step in history )
{
  Console.WriteLine( step );
}

Code Example – VB simulated annealing

Dim History As AnnealingHistory = Minimizer.AnnealingHistory



For Each AnnealingStep As AnnealingHistory.Step In History
  Console.WriteLine(AnnealingStep)
Next

The provided indexer can also be used to retrieve information about a particular step. For example, this code prints out a summary of the third step:

Code Example – C# simulated annealing

Console.WriteLine( history[3] );

Code Example – VB simulated annealing

Console.WriteLine(History(3))


Top

Top