Skip to content

Rethink setting of random number seeds in particle filters

The Matlab random number generator is mt19937ar on clients and Threefry on workers (https://de.mathworks.com/help/parallel-computing/control-random-number-streams-on-workers.html). That means the algorithm and, therefore, seed within a parfor loop may be different than before. I experience crashes in hssmc with order>1 where non_linear_dsge_likelihood is called within parfor. It uses a combination of

[s1,s2] = get_dynare_random_generator_state();
LIK = feval(options_.particle.algorithm, ReducedForm, Y, start, options_.particle, options_.threads, options_, M_);
set_dynare_random_generator_state(s1,s2);

to reset the seed. But the second line may call filters like sequential_importance_particle_filter that have the line

options_=set_dynare_seed_local_options(options_,'default');

which will not just change the seed but also the algorithm. That crashes Matlab in line three because s1 of the old algorithm does not conform to the new one.

Put differently, we have a bug in set_dynare_seed_local_options as default is not uniquely defined.