NetStim.interval variable

Moderator: wwlytton

Post Reply
patoorio
Posts: 81
Joined: Wed Jan 30, 2008 12:46 pm

NetStim.interval variable

Post by patoorio »

Hi,

I want to have a NetStim that delivers random pulses but with a variable mean interval. Specifically, I want to have sinusoid form with max=0 and min=20 (or anything resembling that).
I have tried by playing a sine vector on Net1.interval, i.e.

Code: Select all

sinvec.play(&Net1.interval,1,1) 
But it doesn't work; I get a segmentation violation. (sinevec is a vector previously loaded from a text file)
(BTW I also tried with sinvec.play(Net1.interval,1,1), without the & and it doesn't work either but without the error).

What is the proper way of doing what I want? I have thought of modifying the .mod file but I want to leave that as the last resource.

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

Re: NetStim.interval variable

Post by ted »

patoorio wrote:I want to have a NetStim that delivers random pulses but with a variable mean interval.
You need to find or create an algorithm that does what you want.

Consider a very simple problem: you have a simulation with fixed time step dt, and you want pulses that occur at an average interval of 2*dt. One way to do this is:
at every new time step:
pick a number from the uniform distribution over [0,1]
if the number is <=0.5, generate a pulse

To generalize, suppose you want an average interval of N*dt, where N>1. You could do this by:
at every new time step
pick a number from the uniform distribution over [0,1]
if the number is <=1/N, generate a pulse.

To generalize even further, suppose you want the average interval to vary with time. This means that N must be a function of time
N = f(t) where f is always >=1
So at every new time step,
pick a number from the uniform distribution over [0,1]
if the number is <= 1/f(t), generate a pulse.

This will generate pulses whose instantaneous average interval (discoverable by averaging results of an ensemble of simulations) is f(t)*dt
And it will have to be implemented with a mod file.
patoorio
Posts: 81
Joined: Wed Jan 30, 2008 12:46 pm

Re: NetStim.interval variable

Post by patoorio »

Thanks a lot for telling me to do what I didn't want to do ;)
But I mean it, because it turned out to be easier than I thought... until I got into trouble.

I have something like this:

Code: Select all

INITIAL {
	r_interval = exprand(1)
	last_event = 0
}	

BREAKPOINT {
    if (t>start && t<start+dur) {
        interval = (1000)*1/(minRate + (maxRate-minRate)*cos(2*3.14159*freq*(t-phase)/(1000))) 
        next_ev = last_event + invl(interval)
        if (t>=next_ev) {event()}
    }
}

FUNCTION invl(mean (ms)) (ms) {
		invl = (1. - noise)*mean + noise*mean*r_interval
}

PROCEDURE event() {
    net_event(t)
    last_event = t
    r_interval = exprand(1)
}
(for better readability I have deleted some lines that check that some things are greater than 0)
The idea is to keep the (exponentially distributed) random number r_interval unchanged until there is a new event; what changes from step to step is the mean of the distribution.
The error I get when trying to compile is that net_event (as well as net_send) has to be within the INITIAL or a NET_RECEIVE block. I cannot see how to accomplish that since I need interval to change every time, and every time check if last_event + invl(interval) is lower than t. In other words, I have to be able to generate (in any way) an event from within the BREAKPOINT block.
How can I do that?

Thanks!
patoorio
Posts: 81
Joined: Wed Jan 30, 2008 12:46 pm

Re: NetStim.interval variable

Post by patoorio »

I did some research and found that the WATCH command may be useful here.
Now I have this:

Code: Select all

INITIAL {
	if (noise < 0) {noise = 0}
	if (noise > 1) {noise = 1}
    if (minRate <=0) {minRate = 0.0001}
	r_interval = exprand(1)
	last_event = 0
	interval = (1000)*1/(minRate + (maxRate-minRate)*cos(2*3.14159*freq*(t-phase)/(1000)))
	next_ev = last_event + invl(interval)
    net_send(0,2)
}	

BREAKPOINT {
    if (t>start && t<start+dur) {
        interval = (1000)*1/(minRate + (maxRate-minRate)*cos(2*3.14159*freq*(t-phase)/(1000)))
        next_ev = last_event + invl(interval)
    }
}

NET_RECEIVE (w) {
    if (flag==1) {
        net_event(t)
        last_event = t
        r_interval = exprand(1)
        next_ev = last_event + invl(interval)
    }
    if (flag==2) {}
    WATCH (t>next_ev) 1 
}

FUNCTION invl(mean (ms)) (ms) {
	if (mean <= 0.) {
		mean = .01 (ms) 
	}
	if (noise == 0) {
		invl = mean
	}else{
		invl = (1. - noise)*mean + noise*mean*r_interval
	}
}
It compiles successfuly but just trying to initialize the model gives a segmentation violation error.

BTW, I'm using this mechanism in a very simple way:

Code: Select all

objref Net1,Con1,IF1

Net1 = new SinStim()
Net1.start = 0
Net1.noise = 0

IF1 = new IntFire1(0.5)
Con1 = new NetCon(Net1,IF1)
Con1.weight = 0.7
patoorio
Posts: 81
Joined: Wed Jan 30, 2008 12:46 pm

Re: NetStim.interval variable

Post by patoorio »

Well, I found the solution... and a possible bug?

It turns out that WATCH doesn't work in an ARTIFICIAL_CELL!! I just changed the process to a POINT_PROCESS, created a mock section to insert it and now it works like a charm!
Is this normal? BTW I haven't tried with the last alpha version, I'm working with NEURON 7.1

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

Re: NetStim.interval variable

Post by ted »

I wonder if that would work as an ARTIFICIAL_CELL with version 7.2. By the way, 7.2 has now (finally) been released officially.

I really don't like this algorithm for execution during a simulation--requires code execution at every fadvance() and forces fixed dt integration. It may be better to precalculate the spike times and save them to one or more files, then read them into one or more Vectors prior to calling run() and use VecStim to play the events into NetCons--for source code and an example of the use of VecStim see
nrn/share/nrn/examples/nrniv/netcon/vecevent*
(c:/nrnxx/examples/nrniv/netcon/vecevent* for MSWin users). This would allow the use of adaptive integration--even though the event times themselves were calculated in a way that forces them to lie at integer multiples of some sample rate.
patoorio
Posts: 81
Joined: Wed Jan 30, 2008 12:46 pm

Re: NetStim.interval variable

Post by patoorio »

ted wrote:I wonder if that would work as an ARTIFICIAL_CELL with version 7.2. By the way, 7.2 has now (finally) been released officially. .
No, it doesn't. And now there isn't any segmentation violation message, neuron just quits.
ted wrote:I really don't like this algorithm for execution during a simulation--requires code execution at every fadvance() and forces fixed dt integration. It may be better to precalculate the spike times and save them to one or more files, then read them into one or more Vectors prior to calling run() and use VecStim to play the events into NetCons--for source code and an example of the use of VecStim see
nrn/share/nrn/examples/nrniv/netcon/vecevent*
(c:/nrnxx/examples/nrniv/netcon/vecevent* for MSWin users). This would allow the use of adaptive integration--even though the event times themselves were calculated in a way that forces them to lie at integer multiples of some sample rate.
Sounds interesting. I will give it a try and see how much the simulation is sped up.
Thanks!
Post Reply