SpineML / SpineML_2_BRAHMS

Code generation scripts to run a SpineML neural model using BRAHMS on standard CPUs
http://spineml.github.io/simulators/BRAHMS/
4 stars 3 forks source link

RngData::seed should not be set to 0 #21

Closed sebjameswml closed 8 years ago

sebjameswml commented 8 years ago

In rng.h, there's an unsigned int seed, which is used in the SHR3 macro.

I don't know why, but on some hosts, having this seed set to 0 is problematic. Dave B found that on his home PC, the Poisson rng would generate about 40% too many spikes. Changing the seed to a number >0 solved this.

I also find that if I run the testnormal.cpp program (in SpineML_2_BRAHMS/include) with rngData.seed = 0; then I get a series of fat zeros.

So, seed = 0 is problematic and I'll force rngDatainit to set the seed to 1 instead.

SpineML commented 8 years ago

I think this RNG is mainly consists of shifts so if your seed is zero you will likely get 0 outputs throughout. Some of the other RNGs have an offset which is also applied to avoid this. You could look through the implementation for an offset variable and give it a nice prime number then your default seed of 0 would be fine.

P

On 8 September 2015 at 15:07, Seb James notifications@github.com wrote:

In rng.h, there's an unsigned int seed, which is used in the SHR3 macro.

I don't know why, but on some hosts, having this seed set to 0 is problematic. Dave B found that on his home PC, the Poisson rng would generate about 40% too many spikes. Changing the seed to a number >0 solved this.

I also find that if I run the testnormal.cpp program (in SpineML_2_BRAHMS/include) with rngData.seed = 0; then I get a series of fat zeros.

So, seed = 0 is problematic and I'll force rngDatainit to set the seed to 1 instead.

— Reply to this email directly or view it on GitHub https://github.com/SpineML/SpineML_2_BRAHMS/issues/21.

Dr Paul Richmond (Research Fellow) EPSRC Doctoral Prize Research Fellow Royal Academy of Engineering Student Development Fellowship Awardee

Computer Graphics Group UNIVERSITY OF SHEFFIELD The Department of Computer Science Regent Court, 211 Portobello Sheffield, S1 4DP, UK http://www.dcs.shef.ac.uk/~paul p.richmond@dcs.shef.ac.uk

sebjameswml commented 8 years ago

Thanks for that. Yes, that explains why testnormal.cpp outputs a string of 0s - I don't understand why Dave B was having his problem with the Poisson generator producing about 1.4 times the number of spikes expected.

In this code, I think the offset is RngData::jz, which is set to RngData::seed at the start of the SHR3 macro! I'll not change that, because at the moment, this rng produces identical streams of numbers to the rng in Brahms version 0.7.3.

SpineML commented 8 years ago

A simple explanation for the increase in spikes might be down to probabilistic connectivity. Consider

if rand() < 0.5 then connection

A more complicated explanation could come from any number of off emergent properties resulting from correlations in values which are described in the model with RNG to make them 'noisy'.

On 8 September 2015 at 15:30, Seb James notifications@github.com wrote:

Thanks for that. Yes, that explains why testnormal.cpp outputs a string of 0s - I don't understand why Dave B was having his problem with the Poisson generator producing about 1.4 times the number of spikes expected.

In this code, I think the offset is RngData::jz, which is set to RngData::seed at the start of the SHR3 macro! I'll not change that, because at the moment, this rng produces identical streams of numbers to the rng in Brahms version 0.7.3.

— Reply to this email directly or view it on GitHub https://github.com/SpineML/SpineML_2_BRAHMS/issues/21#issuecomment-138582397 .

Dr Paul Richmond (Research Fellow) EPSRC Doctoral Prize Research Fellow Royal Academy of Engineering Student Development Fellowship Awardee

Computer Graphics Group UNIVERSITY OF SHEFFIELD The Department of Computer Science Regent Court, 211 Portobello Sheffield, S1 4DP, UK http://www.dcs.shef.ac.uk/~paul p.richmond@dcs.shef.ac.uk

sebjameswml commented 8 years ago

Strange though - if you run the randomPoisson function with seed set to 0, then you get a single repeating number, rather than a slightly modified distribution.

I found I couldn't default the seed to 1, because some of the generated code in xsl/LL relies on testing the seed's value for being 0, so instead, I've changed a couple of the tools which failed to change the seed so that they DO change it to a non-zero number and added some more code comments about the importance of setting RngData::seed.

See commits 90c40b1cf2103b911ebeb8cb2faba7e16ea6b233 and 71e54c88853fe0d649d602e5504cdc37f5a23215

SpineML commented 8 years ago

The single repeating number will be because there is some normalisation applied to the output. Not sure about the XSLT though.

Comments are probably the best way but no doubt it will slip past someone and not be an obvious bug to pick-up at some stage down the line. Will have to keep in in mind for when someone is getting odd results.

P

On 8 September 2015 at 16:02, Seb James notifications@github.com wrote:

Strange though - if you run the randomPoisson function with seed set to 0, then you get a single repeating number, rather than a slightly modified distribution.

I found I couldn't default the seed to 1, because some of the generated code in xsl/LL relies on testing the seed's value for being 0, so instead, I've changed a couple of the tools which failed to change the seed so that they DO change it to a non-zero number and added some more code comments about the importance of setting RngData::seed.

— Reply to this email directly or view it on GitHub https://github.com/SpineML/SpineML_2_BRAHMS/issues/21#issuecomment-138593565 .

Dr Paul Richmond (Research Fellow) EPSRC Doctoral Prize Research Fellow Royal Academy of Engineering Student Development Fellowship Awardee

Computer Graphics Group UNIVERSITY OF SHEFFIELD The Department of Computer Science Regent Court, 211 Portobello Sheffield, S1 4DP, UK http://www.dcs.shef.ac.uk/~paul p.richmond@dcs.shef.ac.uk

ajc158 commented 8 years ago

IIRC the seed is set to 123 in the XSLT generated code - so that shouldn't be an issue. I test for 0 quite because it is a rubbish seed - if I get 0 I set the seed to a timeofday generated value, otherwise I use the seed... TLDR - the seed should always have been changed in the code before use Alex

On 8 September 2015 at 16:08, SpineML notifications@github.com wrote:

The single repeating number will be because there is some normalisation applied to the output. Not sure about the XSLT though.

Comments are probably the best way but no doubt it will slip past someone and not be an obvious bug to pick-up at some stage down the line. Will have to keep in in mind for when someone is getting odd results.

P

On 8 September 2015 at 16:02, Seb James notifications@github.com wrote:

Strange though - if you run the randomPoisson function with seed set to 0, then you get a single repeating number, rather than a slightly modified distribution.

I found I couldn't default the seed to 1, because some of the generated code in xsl/LL relies on testing the seed's value for being 0, so instead, I've changed a couple of the tools which failed to change the seed so that they DO change it to a non-zero number and added some more code comments about the importance of setting RngData::seed.

— Reply to this email directly or view it on GitHub < https://github.com/SpineML/SpineML_2_BRAHMS/issues/21#issuecomment-138593565

.

Dr Paul Richmond (Research Fellow) EPSRC Doctoral Prize Research Fellow Royal Academy of Engineering Student Development Fellowship Awardee

Computer Graphics Group UNIVERSITY OF SHEFFIELD The Department of Computer Science Regent Court, 211 Portobello Sheffield, S1 4DP, UK http://www.dcs.shef.ac.uk/~paul p.richmond@dcs.shef.ac.uk

— Reply to this email directly or view it on GitHub https://github.com/SpineML/SpineML_2_BRAHMS/issues/21#issuecomment-138595110 .

Alex Cope Research Associate Behavioural and Evolutionary Theory Lab Department of Computer Science, University of Sheffield www.alexcope.co.uk

ajc158 commented 8 years ago

In addition - PLEASE don't change the seed before use if it is 0 for this reason

On 8 September 2015 at 16:31, Alex Cope a.cope@sheffield.ac.uk wrote:

IIRC the seed is set to 123 in the XSLT generated code - so that shouldn't be an issue. I test for 0 quite because it is a rubbish seed - if I get 0 I set the seed to a timeofday generated value, otherwise I use the seed... TLDR - the seed should always have been changed in the code before use Alex

On 8 September 2015 at 16:08, SpineML notifications@github.com wrote:

The single repeating number will be because there is some normalisation applied to the output. Not sure about the XSLT though.

Comments are probably the best way but no doubt it will slip past someone and not be an obvious bug to pick-up at some stage down the line. Will have to keep in in mind for when someone is getting odd results.

P

On 8 September 2015 at 16:02, Seb James notifications@github.com wrote:

Strange though - if you run the randomPoisson function with seed set to 0, then you get a single repeating number, rather than a slightly modified distribution.

I found I couldn't default the seed to 1, because some of the generated code in xsl/LL relies on testing the seed's value for being 0, so instead, I've changed a couple of the tools which failed to change the seed so that they DO change it to a non-zero number and added some more code comments about the importance of setting RngData::seed.

— Reply to this email directly or view it on GitHub < https://github.com/SpineML/SpineML_2_BRAHMS/issues/21#issuecomment-138593565

.

Dr Paul Richmond (Research Fellow) EPSRC Doctoral Prize Research Fellow Royal Academy of Engineering Student Development Fellowship Awardee

Computer Graphics Group UNIVERSITY OF SHEFFIELD The Department of Computer Science Regent Court, 211 Portobello Sheffield, S1 4DP, UK http://www.dcs.shef.ac.uk/~paul p.richmond@dcs.shef.ac.uk

— Reply to this email directly or view it on GitHub https://github.com/SpineML/SpineML_2_BRAHMS/issues/21#issuecomment-138595110 .

Alex Cope Research Associate Behavioural and Evolutionary Theory Lab Department of Computer Science, University of Sheffield www.alexcope.co.uk

Alex Cope Research Associate Behavioural and Evolutionary Theory Lab Department of Computer Science, University of Sheffield www.alexcope.co.uk

sebjameswml commented 8 years ago

I think my last commits leave the code in the right state - seed is set to 0 inside rngDataInit(), but all client code sets the seed to a non-zero value. So, the upshot is that I changed code in a couple of the tools/ components but otherwise I made no functional changes in rng.h.

Except that I DID uncomment the uniformGCC() function as that seems to compile for me now.