Reproduce Your Results

Because the simulated annealing algorithm is stochastic—that is, it makes random choices—you get slightly different results each time you run it. The algorithm uses the default MATLAB® pseudorandom number stream. For more information about random number streams, see RandStream. Each time the algorithm calls the stream, its state changes. So the next time the algorithm calls the stream, it returns a different random number.

If you need to reproduce your results exactly, call simulannealbnd with the output argument. The output structure contains the current random number generator state in the output.rngstate field. Reset the state before running the function again.

For example, to reproduce the output of simulannealbnd applied to De Jong's fifth function, call simulannealbnd with the syntax

rng(10,'twister') % for reproducibility
[x,fval,exitflag,output] = simulannealbnd(@dejong5fcn,[0 0]);

Suppose the results are


x =
  -16.1292  -15.8214

fval =

The state of the random number generator, rngstate, is stored in output.rngstate. Reset the stream by entering

stream = RandStream.getGlobalStream;
stream.State = output.rngstate.State;

If you now run simulannealbnd a second time, you get the same results.


If you do not need to reproduce your results, it is better not to set the states of RandStream, so that you get the benefit of the randomness in these algorithms.

See Also

Related Topics