NetStim Event Times Same from Trial to Trial?

Anything that doesn't fit elsewhere.
Post Reply
Yaeger
Posts: 33
Joined: Mon Aug 19, 2013 4:36 pm

NetStim Event Times Same from Trial to Trial?

Post by Yaeger »

Hi, I am using NetStim to generate poisson-distributed event times to drive synapses. To my surprise, everytime I run the simulation the NetStim events seem to be occurring at the same time. I would have thought that the poisson-distributed event times would be generated probabilistically every time the simulation is run and thus would be different on a trial-to-trial basis. Is there a way to make the event times differ trial to trial?
ted
Site Admin
Posts: 6289
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: NetStim Event Times Same from Trial to Trial?

Post by ted »

Yaeger wrote:I would have thought that the poisson-distributed event times would be generated probabilistically every time the simulation is run and thus would be different on a trial-to-trial basis.
That would be a bug, not a feature (indeed, when it happens it is usually a symptom of an initialization error in a mod file). It would destroy your ability to write reproducible, debuggable code. Given input I, program P should always produce the same output O regardless of how many times P has been run.

What you need to do is change the "program's input" from one run to the next. The way to do that is by changing the seed(s) used by the random number generator(s). You want to do that in such a way that the pseudorandom sequences generated during one run are statistically independent of the sequences that are generated in the next run. Random123 is an excellent generator for this task--read about it in the Programmer's Reference
http://www.neuron.yale.edu/neuron/stati ... .Random123

For the sake of reproducibility, it is absolutely essential to keep track of the seeds that were (or are to be*) used in each run.

*--One common practice is to generate, in advance, a file that contains a list of seeds that will be used, before executing a sequence of "production runs" that draws on those seeds.
Yaeger
Posts: 33
Joined: Mon Aug 19, 2013 4:36 pm

Re: NetStim Event Times Same from Trial to Trial?

Post by Yaeger »

Hi Ted -

Thanks for the quick and helpful reply. Sorry it has taken me a bit to reply. Per your advice I have generated some code to create a vector of random numbers using Random123.

Code: Select all

objref r
r = new Random()
r.negexp(1)
r.Random123(1)

objref rvec
rvec = new Vector()

proc genran() { local i, seed
	for i = 1,$1 {
		myseed = r.repick
		rvec.append(myseed)
		}
}

genran(10)
Then I have a file that generates events at different frequencies and uses one of the random seeds contained in the vector rvec in the above code as the random seed for the NetStim i.e.:

Code: Select all

proc batrun() { local i, isi
	for i = 1,$1 {
		isi = 1000/(310 - i)
		useseed = rvec.x[0]
		ns.seed(useseed)
		ns.interval = isi
		ns.noise = 1		
		run()
}
}

What I am wondering (due to my ignorance of random number generators) is whether there is any interaction between the specific random seed used and the negative exponential distribution generated by "ns.noise = 1" at different NetStim interval values ? Is it appropriate to use the same random seed regardless of the NetStim interval size?
Yaeger
Posts: 33
Joined: Mon Aug 19, 2013 4:36 pm

Re: NetStim Event Times Same from Trial to Trial?

Post by Yaeger »

Now I am seeing that there is a problem with this code, although I am not sure where it is. For random seeds between zero and one, the NetStim generates the same interevent intervals.
ted
Site Admin
Posts: 6289
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: NetStim Event Times Same from Trial to Trial?

Post by ted »

Before carrying on further, it would be good to read the documentation on Randomness in NEURON models. See the link with that name on NEURON's Documentation page http://www.neuron.yale.edu/neuron/docs. Although the example provided uses MCellRan4, after you have worked through the code it shouldn't be too hard for you modify it so that it uses Random123. Then you'll be in a much better position to pick up with your own project.
Post Reply