1165
Comment:

3320

Deletions are marked like this.  Additions are marked like this. 
Line 17:  Line 17: 
=== set_dynare_seed(a,b) === * With two arguments, the first argument sets the random generator type and the second argument sets the seed * with one argument, if the argument is numeric, it sets the seed of the random generator of the default type (depends on Matlab version). If the single argument is not numeric, an error is triggered * The function sets options_.DynareRandomStreams.algo and options_.DynareRandomStreams.seed * In older versions, Matlab used two distinct random generators for uniformly distributed and for normally distributed variables. Dynare uses the same seed for both generators * Octave has only one type of random generator, Mersenne Twister, the same algorithm as the default in recent versions of Matlab === get_dynare_random_generator_state() === * this function returns two vectors describing the current state of the random generators (one for uniformly, one for normally distributed variables) * this function handles automatically the different versions of random generators available in Matlab * as noted, above, in recent Matlab versions, there is only one random generator and in that case the two vectors are identical. === set_dynare_random_generator_state(state_u,state_n) === * uses both arguments to set the state of the random generators. When using the current mechanism provided by recent versions of Matlab, both vectors must be identical. * this function handles automatically the different versions of random generators available in Matlab === Metropolis === * since August 29, 2012, the random generator is reseeded with a different seed before the computation of each Metropolis chain. * the current mechanism, using only the default random stream, will need to be revised if we use {{{parfor}}} to compute in parallel the various chains. * the state of the random generator is stored in {{{record.Seeds(j).Unifor}}} and {{{record.Seeds(j).Normal}}}, where {{{j}}} is the index of the Metropolis chain. Note that the field name {{{Seeds}}} is misleading because it stores the state vector and not the original seed. We keep it that way for backward compatibility. 
Fixing random seed
It is desirable that the default behavior of Dynare be fully deterministic: two runs of the same *.mod file on the same installation should provide the same results. Introduced in commit db54c2d76ec8ac6a42c0cbf99bc394f7644f2a85 (git master), there is a new matlab routine for setting the seed: set_dynare_seed.m. This routine is called in global_initialization.m, so that each instance of dynare is initialized with the same seed (and should give exactly the same results). This routine can also be called in a mod file, depending on the version of matlab the user can set the seed and (with ver('matlab')>=7.7) choose the algorithm used to generate uniform variates (see matlab documentation or the output of the command RandStream.list).
List of commands or functions that use a random generator
 stoch_simul (csolve simult_ + currently call to dynare_simul_ uses a fixed seed)
 estimation
 mode optimization
 Metropolis iterations
 subsampling for posterior statistics
 osr optimization
 steady (csolve)
 ramsey_policy (csolve + simult_)
 Markov switching
 Global Sensitivity Analysis
set_dynare_seed(a,b)
 With two arguments, the first argument sets the random generator type and the second argument sets the seed
 with one argument, if the argument is numeric, it sets the seed of the random generator of the default type (depends on Matlab version). If the single argument is not numeric, an error is triggered
The function sets options_.DynareRandomStreams.algo and options_.DynareRandomStreams.seed
 In older versions, Matlab used two distinct random generators for uniformly distributed and for normally distributed variables. Dynare uses the same seed for both generators
 Octave has only one type of random generator, Mersenne Twister, the same algorithm as the default in recent versions of Matlab
get_dynare_random_generator_state()
 this function returns two vectors describing the current state of the random generators (one for uniformly, one for normally distributed variables)
 this function handles automatically the different versions of random generators available in Matlab * as noted, above, in recent Matlab versions, there is only one random generator and in that case the two vectors are identical.
set_dynare_random_generator_state(state_u,state_n)
 uses both arguments to set the state of the random generators. When using the current mechanism provided by recent versions of Matlab, both vectors must be identical.
 this function handles automatically the different versions of random generators available in Matlab
Metropolis
 since August 29, 2012, the random generator is reseeded with a different seed before the computation of each Metropolis chain.
the current mechanism, using only the default random stream, will need to be revised if we use parfor to compute in parallel the various chains.
the state of the random generator is stored in record.Seeds(j).Unifor and record.Seeds(j).Normal, where j is the index of the Metropolis chain. Note that the field name Seeds is misleading because it stores the state vector and not the original seed. We keep it that way for backward compatibility.