In this tutorial, we will show how to set and reset the random number generator seed. This is important for generating reproducible results from simulations. For more information on random number generation in Matlab, see the MathWorks documentation.
VERTEX uses Matlab’s default random number generation functions for its random numbers. In serial mode this is quite simple: when initNetwork() is called, it will seed the random number generator using the value provided by the user in the SimulationSettings structure, or a default seed value if a user-defined seed is not given (the default seed is 123). If you have compiled the multiSynapse.cpp file to a mex file (see Tutorial 0) and are running the tutorials in serial mode, you should have been getting the same output graphs as given on the tutorial web pages.
To set the random seed to a different value at the start of your simulation, you simply specify the randomSeed field in your SimulationSettings structure:
SimulationSettings.randomSeed = 12345;
You may want to reset the random seed after the network has been generated: for example, if you want to perform multiple simulation runs using the same network but with different random inputs. To reset the random seed, you can call the resetRandomSeed() function:
If you do not specify a seed and just call resetRandomSeed(), then the random seed will be reset to VERTEX’s default seed (123). Note that if you call resetRandomSeed() but then call initNetwork(), then the network initialisation will automatically set the random seed again to the default value or the value specified in the SimulationSettings structure. If you want to generate a different network structure, you must control the random number seed by specifying different randomSeed value in your SimulationSettings structure.
VERTEX makes use of the Matlab Parallel Programming Toolbox’s parallel random number generation capabilities. These allow independent streams of random numbers to be generated by each lab, initialised by a single seed. This allows for reproducibility when running with the same number of labs, but unfortunately not when the number of labs changes. To emphasise this, the number of labs in use is automatically added to the default or user-provided random seed to emphasise that the number of labs in use will also affect the random number generation. This current limitation of VERTEX may be improved upon in future releases to allow truly reproducible random number generation independent of the number of labs used.
Setting the initial random seed, and the resetRandomSeed() function, work in the same way for both serial and parallel simulations.