model setup: random events

Anything that doesn't fit elsewhere.
Post Reply
SaiNitin
Posts: 6
Joined: Sun May 05, 2019 10:41 am

model setup: random events

Post by SaiNitin » Thu Jul 18, 2019 3:34 am

I have observed that just the addition of NetCon objects with null source (without delivering events) affects the voltage values at different time points when plotted. Please help me understand why this could be happening?

I tried this on two biophysics-simplified model (variation to my original model). In variation 1, I have 179 NetCon objects present and events are delivered to all of them at different time points. In variation 2, I have 5016 NetCon objects present but events are delivered to the same 179 NetCon objects from earlier case. Just the presence of these extra NetCon objects seems to be affecting the voltage vs time plot.

ted
Site Admin
Posts: 5632
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: Creating NetCon with null source in NEURON+Python

Post by ted » Thu Jul 18, 2019 10:31 am

The possibilities are either
1. there is a mismatch between what is in your computer and what is in your head, so that there is some additional difference between the computational implementations of your variation 1 and 2 models
or
2. you have run into a bug in NEURON

Did you happen to implement your model in such a way that the total number of NetCons is scalable, e.g. controlled by assigning a value to a symbolic constant, or is it hard wired into the code as the magic number 179? If it's scalable, have you tried comparing the results of simulations that involve
1 vs. 2 NetCons
2 vs. 3 NetCons
10 vs. 11 NetCons
?

SaiNitin
Posts: 6
Joined: Sun May 05, 2019 10:41 am

Re: Creating NetCon with null source in NEURON+Python

Post by SaiNitin » Mon Jul 22, 2019 8:11 am

Yes, the total number of NetCons are scalable. I tried the simulations again with 10 out of 11 NetCons active and only 10 NetCons present and active. There is still some minor difference emerging in the voltage plot.

There is a slight difference in the way these two cases are coded and this could be creating a difference. I have indicated by #=> the lines that are different in the two codes. Please note that the same 10 NetCons are activated at multiple time points in the same way in both cases.
I have also tried having 11 NetCons active using both types of code and it is still creating a minor difference. I just want to understand why.

Note: By active, I mean that they have at least 1 event delivery.

Case 1: (10 of 11 NetCon active)

Code: Select all

def run(bSyn):
    global UniformRand,NormRand
    UniformRand = h.Random(sd)
    NormRand = h.Random(sd)
    for p in range(10):
    	Events(Dnf,p,'GABA')
        Events(Upf,p,'GABA')
        
def Events(x,y,a,z):
    start = UniformRand.uniform(0, 1000/x)
    Event = start + NormRand.normal(0, 1e6/(16*x*x))
    b=(StateNo*SI*x)/1000
    for j in range(1,4+int(b)):
        if(Event>=0):
            c=int(Event/SI) 
            if (abs((int(c/2)==(c/2))-(x==Upf))):
                if(a=='GABA'):
#=>          		 ns[y].event(Event)
        Event = start + 1000*j/x + NormRand.repick()
        
fih = h.FInitializeHandler((run,1))
h.cvode_active(True)

#=>
for i in range(11):
	ns.append(h.NetCon(None,cell.gaba[i],10,1,1))
#=>
Case 2: (all 10 present are active)

Code: Select all

def run(bSyn):
    global UniformRand,NormRand
    UniformRand = h.Random(sd)
    NormRand = h.Random(sd)
    for p in range(10):
    	Events(Dnf,p,'GABA')
        Events(Upf,p,'GABA')
def Events(x,y,a,z):
    start = UniformRand.uniform(0, 1000/x)
    Event = start + NormRand.normal(0, 1e6/(16*x*x))
    b=(StateNo*SI*x)/1000
    for j in range(1,4+int(b)):
        if(Event>=0):
            c=int(Event/SI) 
            if (abs((int(c/2)==(c/2))-(x==Upf))):
                if(a=='GABA'):
#=>			ns.append(h.NetCon(None,cell.gaba[y],10,0,1))
#=>                  	ns[-1].event(Event)
        Event = start + 1000*j/x + NormRand.repick()
fih = h.FInitializeHandler((run,1))
h.cvode_active(True)

ted
Site Admin
Posts: 5632
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: model setup: random events

Post by ted » Mon Jul 22, 2019 12:29 pm

First a comment: the code examples are loaded with "magic numbers"--unnamed numerical constants, that is, constants whose values are embedded explicitly in the program. See this article in Wikipedia https://en.wikipedia.org/wiki/Magic_num ... ramming%29

Now for the source of the problem you encountered. The code creates a single "random number generator" (actually a pseudorandom numerical sequence generator--see the Wikipedia article https://en.wikipedia.org/wiki/Pseudoran ... _generator). If there is only one sequence generator, then every time the program needs a new "random" value, it will pick from the same sequence. If the program contains a statement S that needs a random value, the value used in S will depend on how many values have already been picked from the sequence. If something changes the number of values that are picked before S is executed, the random value used in S will change.

To verify that this is happening in your own code, print out and compare the event times for each NetCon. This will be easier if you make the numbers of NetCons and events small, e.g. 3 and 5, respectively.

To prevent such side-effects, use the Random123 generator, which "uses a 34bit counter, up to 3 32 bit identifiers, and a 32 bit global index and is most suitable for managing separate independent, reproducible, restartable streams"

You will want to read the relevant entries in the Programmer's Reference documentation of the Random class.

SaiNitin
Posts: 6
Joined: Sun May 05, 2019 10:41 am

Re: model setup: random events

Post by SaiNitin » Thu Jul 25, 2019 12:48 am

The way the random number generator is implemented in both cases is the same and they also have the same seed.

I have tried several combinations by varying the number of NetCon objects and Event delivery times including the one you suggested. The input timings also match. When there is a single type of point process involved, the plots match. However, I seem to be still getting minor variations in voltage in some cases.

For example, I used 2, 4, 4 NetCon objects connected to GABA, AMPA and NMDA point processes. Even when I activate all NetCons at randomized times, in both cases there are minor voltage differences (<0.25 mV, but this is becoming significant when I use many more NetCons) between the two cases. The only difference in the two cases were in the code for event delivery as shown in previous post.
Note: AMPA and NMDA processes have the same input timings. Not sure if that helps, just for information.

It's not clear to me what exactly you mean by magic numbers. If you are referring to Dnf,Upf,sd etc then they are constant numbers and are not being changed anywhere else in the program.

Also, I want both Uniform and Gaussian distributed random number generators in my model, how can Random123 generator fit in here..can it be used for both types of distribution?

Thank you for being patient with regards to all these queries. Please tell me if you need more information regarding the model.

ted
Site Admin
Posts: 5632
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: model setup: random events

Post by ted » Thu Jul 25, 2019 3:44 pm

I seem to be still getting minor variations in voltage in some cases.
Looks like I'll have to be able to reproduce this in order to figure out what's going on. Can you zip up the necessary code and email it to ted dot carnevale at yale dot edu? and also include instructions for how to reproduce what you're seeing?
It's not clear to me what exactly you mean by magic numbers
Here's one
for p in range(10):
Here's another
for j in range(1,4+int(b)):

SaiNitin
Posts: 6
Joined: Sun May 05, 2019 10:41 am

Re: model setup: random events

Post by SaiNitin » Mon Jul 29, 2019 12:28 pm

I have sent the email. Thank you. Looking forward to the resolution of this issue.

Post Reply