Random NetCon

Anything that doesn't fit elsewhere.
Post Reply
pfortier

Random NetCon

Post by pfortier »

To send random signals to NetCon I can successfuly use NetStim:

Code: Select all

create dend
objref rec
dend rec = new ExpSyn(0.5)
objref ns 
dend ns = new NetStim(.5)
ns.noise=.9
objref nc
dend nc=new NetCon(ns, rec, 0, 0, 1.0)
tstop=300
run()
Is it possible to use Random? The closest I get is:

Code: Select all

create dend
objref rec
dend rec = new ExpSyn(0.5)
objref rn 
rn = new Random(1000)
rn.normal(0,1) 
double ns[1]
rn.play(&ns[0])
objref nc
dend nc=new NetCon(&ns[0], rec, 0, 0, 1.0)
tstop=300
run()
This yields the following error:
/usr/bin/nrniv: NetCon pointer not associated with currently accessed section
Use section ... (&var(x)...) intead of ...(&section.var(x)...)
in rndpresynpattern.hoc near line 12
ted
Site Admin
Posts: 6384
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Post by ted »

This question raises several issues. Before delving into mechanical details like syntax and
how to attach a pseudorandom sequence generator to an event delivery queue, there is
the problem that the normal distribution has a finite probability of generating samples < 0.
Events with delivery times that are less than the current model time t are not allowed.
So either you have to abandon the normal distribution, or interpret samples in a way
that doesn't violate the injunction against "trying to deliver an event in the past."

As far as the mechanical details are concerned, the "best" answer depends "what you
are trying to do" i.e. the purpose that you have in mind.
pfortier

Post by pfortier »

I need and successfully used the first version of code with NetStim.

The second version of code using Random was attempted only as a learning exercise. It seemed possible to play a random number into a variable and have this variable act as a source to a NetCon.
ted
Site Admin
Posts: 6384
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Post by ted »

pfortier wrote:It seemed possible to play a random number into a variable and have this variable act as a source to a NetCon.
According to the documentation for the NetCon class, the source can be
1. a range variable
2. "a PointProcess with a NET_RECEIVE block which contains a call to net_event"
3. "a PointProcess which contains a "x" variable which is watched for threshold crossing, but this is obsolete since NET_RECEIVE blocks which explicitly call net_event are much more efficient since they avoid the overhead of threshold detection at every time step."
or
4. "a NULLObject. In this case events can only occur by calling event from hoc."

I thought you were trying to do something like (4), i.e. make your own sequence of event
times by sampling a random distribution. That's what most questions like this turn out to
be about.

If you want to do (1), just make a toy section and use the Random class to drive one of
its range variables. If your distribution can generate negative values, you'll probably want
to avoid driving diam or cm. I'm not sure that driving v will work--will the integrator
counteract the change you made with the Random variable? Try it and see what
happens; if it doesn't work, you might just insert pas, and then drive e_pas.
pfortier

Post by pfortier »

Does NetStim have a method to get the next value? Something like:

Code: Select all

objref ns
ns = new NetStim()
ns.noise=.9
for i=0,10 print ns.value()
The only way I know how to get the values is to run() a simulation:

Code: Select all

create dend
access dend
objref ns 
ns = new NetStim(.5)
objref vec, nc, nil
vec = new Vector()
nc = new NetCon(ns, nil)
nc.record(vec)
run()
for i=0,vec.size()-1 print vec.x[i]
ted
Site Admin
Posts: 6384
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Post by ted »

You can discover a lot by examining the source code for the NetStim class. If you are
using MSWin, read c:\nrn60\src\nrnoc\netstim.mod . If using Linux, you'll need to expand
the gzipped tar source code and look at nrn-6.0/src/nrnoc/netstim.mod . Note
FUNCTION erand(), which is callable from hoc. Repeatedly calling erand() will generate a
sequence of ISIs.

Code: Select all

objref foo
foo = new NetStim() // no need for a "host" section
foo.noise = 0.5
finitialize() // initialize pseudorandom sequence generator
for i=0,9 foo.erand() // print 10 ISIs
Post Reply