Main Content

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, seeRandStream. 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, callsimulannealbndwith theoutput论点。的outputstructure contains the current random number generator state in theoutput.rngstate字段。重置逃跑前的状态g the function again.

For example, to reproduce the output ofsimulannealbndapplied to De Jong's fifth function, callsimulannealbndwith the syntax

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

Suppose the results are

x,fval x = -16.1292 -15.8214 fval = 6.9034

的state of the random number generator,rngstate, is stored inoutput.rngstate. Reset the stream by entering

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

If you now runsimulannealbnda second time, you get the same results.

Note

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

See Also

Related Topics