Random number seed for stochastic channels?

The basics of how to develop, test, and use models.
Post Reply
ppt
Posts: 5
Joined: Mon Dec 15, 2008 8:16 pm

Random number seed for stochastic channels?

Post by ppt »

Using the Channel Builder, I constructed a stochastic single channel simulator. How does one apply random number seeds to this simulation?
ted
Site Admin
Posts: 5810
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: Random number seed for stochastic channels?

Post by ted »

Good question. I thought the answer would be similar to how one deals with NMODL-specified point processes that use scop's pseudorandom generators, but found that, at least under 7.0, a ChannelBuilder-specified point process doesn't have a set_seed() method. It does have a public variable called rseed, which changes from run to run, but
KSChan[0].rseed = somevalue
returns the error message
Cannot assign to left hand side
hines
Site Admin
Posts: 1607
Joined: Wed May 18, 2005 3:32 pm

Re: Random number seed for stochastic channels?

Post by hines »

KSChan.rseed(i) is a function that sets the index (incremented per pick) for
calls analogous to
http://www.neuron.yale.edu/neuron/stati ... mcell_ran4
The current value of the index is returned (useful when no arg).
All the KSChan share the random index instance. The index is intitialized to 0.

Note that the KSChan instance sharing of random indices is a problem for reproducibility is
a parallel simulation and it might be a good idea to make it an instance variable. But then one
would have to initialize them so that the instance streams were statistically independent.
ted
Site Admin
Posts: 5810
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: Random number seed for stochastic channels?

Post by ted »

hines wrote:the KSChan instance sharing of random indices
Of course, this raised the question of whether NetStims draw from a common pseudorandom generator, and it turns out that they do. However, it is fairly straightforward to associate each NetStim with its own generator that is independent of any others--see
How to generate independent random spike streams
http://www.neuron.yale.edu/neuron/node/60
That example shows how to pair NetStims with instances of the Random class that use the MCellRan4 generator, but with only a few changes one can instead have them use the more recently added (and more powerful) Random123 generator http://www.neuron.yale.edu/neuron/stati ... .Random123

Revised 20150227 NTC
victoriadl
Posts: 1
Joined: Fri Feb 13, 2015 6:58 am

Re: Random number seed for stochastic channels?

Post by victoriadl »

Hello,

I am trying to do a similar thing as ppt, so making sure that every time I start the simulation again the code does not use the same seed (I'm looking at channel noise, but if the noise is the same every time there is not much to compare..). I tried to implement the suggested code, but I could not get it to work. Where in the code do I have to put KSChan.rseed(i) in the channel builder?
ted
Site Admin
Posts: 5810
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: Random number seed for stochastic channels?

Post by ted »

victoriadl wrote:Where in the code do I have to put KSChan.rseed(i) in the channel builder?
A program that sets up a model and then uses that model in a series of simulations should be organized in this order:

1. First should be model setup code--statements that specify the biophysical and anatomical properties that are represented in the model.

2. Instrumentation code is next--statements that specify things like
* what stimuli are applied to the model
* experimental manipulations such as extra- or intracellular changes of ionic concentrations or ligands or second messengers that are to occur in the course of the simulation
* which variables are to be displayed or captured to Vectors for later saving to file(s)

3. Finally comes simulation control code--which specifies things such as
* how the model is to be initialized
* what integration method to use
* what value of dt or error tolerance to use
* duration of the simulation (in "model time" not wall clock time)
* how many simulations are to be run
* if and how parameters are to be changed from one simulation to the next

Specification of seeds for random number generators that are called during a simulation is part of simulation control. If you merely wanted to run a series of identical simulations, you would ordinarily do that with this procedure

Code: Select all

// run $1 simulations
proc nrun() { local i
  if ($1>0) {
    for i=0,$1-1 run()
  }
}
But your model involves ChannelBuilder-specified stochastic channels, and those are governed by a random number generator that is controlled by a "highindex" value that increments automatically from one run to the next, unless you do something that overrides that, for example:

Code: Select all

// run $1 identical simulations, each using random seed specified by the second argument
proc nrun() { local i
  if ($1>0) {
    KSChan[0].rseed($2)
    for i=0,$1-1 run()
  }
}
A more useful example would be if you had a Vector called svec whose elements were the seeds you wanted to use. Then

Code: Select all

proc batrun() { local i
  for i=0,$o1.size()-1 {
    KSChan[0].rseed($o1.x[i])
    run()
  }
}
batrun(svec)
would run a series of simulations--one for each of the seed values in svec.
Post Reply