What is wrong with this code?

The basics of how to develop, test, and use models.
Post Reply
Elqui

What is wrong with this code?

Post by Elqui »

Hi there,

So I inherited this model from someone else and while trying to get things going I bumped into the following problem:

Whenever I try to run this piece of code more than once, either by calling it twice or by trying a second run, the computer hangs and the program gets non-responsive. Running it once causes no problems and the model runs correctly.

//Noise procedure

//INSERT MOD FILE FOR SINE WAVE


objref sinw, w, ramp

proc noise() {

forsec somatic {
w = new Random()
w.poisson(0.1)
sinw = new SinClamp(0.5)
sinw.del=0
sinw.dur=tstop
sinw.freq = 100
w.play(&sinw.pkamp)
}
}

Also, does anyone has a better noise proc? I really don't like how this one works really.

Thanks a lot!
Elqui

Re: What is wrong with this code?

Post by Elqui »

The person that gave me the code says that she's been having this problem now ever since she upgraded to 7.0

is it a bug? is there a work around? or I should just go with an earlier version?
ted
Site Admin
Posts: 5810
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: What is wrong with this code?

Post by ted »

Running it once causes no problems and the model runs correctly.
Depends on what one means by "runs correctly." At exit from the for loop, there will be just one instance of the Random class, and it will "play" into the pkamp parameter of the SinClamp object that is attached to the last section in "somatic". No other SinClamp object's pkamp parameter will be driven by an instance of the Random class. This might not be noticed if there is only one section in somatic, or if pkamp is GLOBAL (in which case every instance of SinClamp will have synchronous fluctuations of pkamp). Somehow none of these possibilities seems likely to be a desirable outcome. What was the code supposed to do?
Whenever I try to run this piece of code more than once, either by calling it twice or by trying a second run, the computer hangs and the program gets non-responsive.
Doesn't happen for me with a toy model that uses IClamp.
does anyone has a better noise proc? I really don't like how this one works
What's wrong with it? What would be "better"?
Elqui

Re: What is wrong with this code?

Post by Elqui »

First of all thanks for the response. Just going through your comments has been most helpful.

Sorry it took so long but as I said I inherited this. To answer your questions, pkamp is defined for the whole NEURON, in SinClamp, it is defined as a current step with a value of half a nano amp!!! and also somatic for the morphology I am using is just one compartment (an ellipse rotated on its major axis): soma[0].

The code is supposed to add some random noise to the trace so it would not be the same every repetition of the run, though the same seed is used every time the experiment is run anew to assure reliability. If I comment the code out the simulation runs ok, tho it is the same every time.

As for why I don't like the noise simulation is because it looks awful, from an experimental POV I would reject the trace by saying that there is some cable loose or the amplifier has the test pulse on while recording. I can't find how to attach (is it possible?) a few ms of the trace so you know how it looks. In any case here is SinClamp

NEURON {
POINT_PROCESS SinClamp
RANGE del, dur, pkamp, freq, phase, bias
ELECTRODE_CURRENT i
}

UNITS {
(nA) = (nanoamp)
}

PARAMETER {
del=0 (ms)
dur=200 (ms)
pkamp=0.5 (nA) :1
freq=1 (Hz)
phase=0 (rad)
bias=0 (nA)
PI=3.14159265358979323846
}

ASSIGNED {
i (nA)
}

BREAKPOINT {
if (t < del) {
i=0
}else{
if (t < del+dur) {
i = pkamp*sin(2*PI*freq*(t-del)/1000+phase)+bias
}else{
i = 0
}}}


Still, I would like to know why w = new random(), crashes my program, any suggestions as to how to proceed?


Thanks
Elqui

Re: What is wrong with this code?

Post by Elqui »

So the solution was to destroy the references (w, sinw) after they are called, or right before calling the noise() proc again. Go figure, I don't know how appropriate it is, but at least it works.
ted
Site Admin
Posts: 5810
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: What is wrong with this code?

Post by ted »

As for why I don't like the noise simulation is because it looks awful, from an experimental POV I would reject the trace by saying that there is some cable loose or the amplifier has the test pulse on while recording.
The SinClamp mechanism, when unmolested, generates a sinusoidal current. The original code, if the SectionList "somatic" contained more than one section, would create multiple instances of this mechanism, all but one of which would produce sinusoids with 1 nA peak-to-peak amplitude. Depending on the geometry and biophysical properties of your model cell, 1 nA could be a big current.

The final instance of the SinClamp mechanism would be driven by a sequence of pulses with magnitude 1, 2, . . . that occur at long, random intervals (i.e. most of the time, the driving function is 0). The current produced by this SinClamp would be a sequence of intervals of varying width during which there is no current, interrupted by brief pulses whose amplitude depends jointly on (1) the magnitude of the integer returned by the pseudorandom sequence generator, and (2) the timing of this integer relative to the phase of the sinusoid--in other words, occasional brief current spikes of varying polarity and amplitude. Seems very contrived, arbitrary, unrealistic. What kind of noise do you really want?
Elqui

Re: What is wrong with this code?

Post by Elqui »

I don't know, that is a good question. Ideally would be temperature and voltage dependent, i.e. random opening of the conductances plus whatever spontaneous synaptic activity is occurring. But I am betting that that is very computer intensive.

SinClamp however, I found out during the weekend, can be 'fixed' post-run. I just decimated the data and took the fourier transform and smoothed the odd frequency ( in the case of the code 100Hz) and things looked a whole lot better.

Also, I am using a reconstructed prefrontal ctx neuron.

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

Re: What is wrong with this code?

Post by ted »

Elqui wrote:SinClamp however, I found out during the weekend, can be 'fixed' post-run. I just decimated the data and took the fourier transform and smoothed the odd frequency ( in the case of the code 100Hz) and things looked a whole lot better.
OK, if you're happy with it and can justify whatever you did to an editor and a grant reviewer, that's fine with me.
Elqui

Re: What is wrong with this code?

Post by Elqui »

That's the thing, I can't really.... but it does look more like the real thing.
ted
Site Admin
Posts: 5810
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: What is wrong with this code?

Post by ted »

If I had a single compartment model that needed some "noise" I'd decide first if it is to be current noise or fluctuating conductance. If the latter, I'd use an ExpSyn and an Exp2Syn, each driven by its own NetStim with noise = 1, and specify values for the following parameters:
--ExpSyn e = 0 mV, tau ~ 2-3 ms (like an AMPAergic synapse)
--Exp2Syn e = 10-20 mV more negative than resting potential, tau1 ~ 2-5 ms and tau2 ~ 5-10 ms (like a GABA-A synapse)
--choose NetStim intervals and NetCon weights so that (1) the fluctuations of membrane potential look plausible to an experimentalist's eye and (2) the expected values of the currents delivered by these two synapses will cancel each other out if the cell is clamped at resting potential

A caveat for any attempt to emulate noise by injecting fluctuating current into a model cell with "active" membrane: because of the rectifying properties of voltage-gated channels, mean membrane potential is likely to deviate from rest even if the mean value of the applied current itself is 0.
Post Reply