NMath User's Guide

TOC | Previous | Next | Index

28.3 Minimizing Functions by Simulated Annealing (.NET, C#, CSharp, VB, Visual Basic, F#)

Instances of AnnealingMinimizer are constructed from an annealing schedule (Section 28.2). For instance:

Code Example – C# simulated annealing

var schedule = new LinearAnnealingSchedule( 5, 25, 100.0 );;
var minimizer = new AnnealingMinimizer( schedule );

Code Example – VB simulated annealing

Dim Schedule As New LinearAnnealingSchedule(5, 25, 100.0)
Dim Minimizer As New AnnealingMinimizer(Schedule)

After construction, you can use the Schedule property to get and set the annealing schedule associated with an AnnealingMinimizer.

The RandomNumberGenerator property gets and sets the random number generator associated with this minimizer. The random number generator is used for making temperature-dependent, random steps in the search space as part of the annealing process. The random number generator is initially set at construction time to the value of static property DefaultRandomNumberGenerator, which defaults to an instance of RandGenUniform.

Class AnnealingMinimizer implements the IMultiVariableMinimizer interface, which provides a single Minimize() method that takes a MultiVariableFunction to minimize, and a starting point. For instance, if f is an encapsulated multivariable function (Chapter 25) of five variables, this code minimizes the function using the downhill simplex method, starting at (0.2,0.2,-.2,0.0,0.0):

Code Example – C# simulated annealing

var minimizer = new AnnealingMinimizer( schedule );
var start = new DoubleVector( 0.2, 0.2, -0.2, 0.0, 0.0 );
DoubleVector min = minimizer.Minimize( f, start );

Code Example – VB simulated annealing

Dim Minimizer As New AnnealingMinimizer(Schedule)
Dim Start As New DoubleVector(0.2, 0.2, -0.2, 0.0, 0.0)
Dim Min As DoubleVector = Minimizer.Minimize(F, Start)

After minimization, the following properties on AnnealingMinimizer can be useful for gathering more information about the minimum just computed:

Error gets the error associated with the mimimum just computed.

ToleranceMet returns a boolean value indicating whether the minimum just computed stopped because the error tolerance was reached. (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.)

For more information on the annealing process just completed, access the annealing history (Section 28.4).


Top

Top