Page 1 of 1

injecting continuous normally distributed noise in python

Posted: Sun Aug 25, 2019 10:57 pm
by thiank
Hi,

I've been trying to insert normally distributed noise onto my cells via IClamp, but the amp can only be set to one number/integer/float. I have a vector of say 1x1000 (1 per ms) that I want to set as the amp value. I guess one way would be to make a 1000 instances of the IClamp set at each time point, but that seems rather brutish.

Code: Select all

    def Insert_Noise(self, noise_mean, noise_std_dev): 
        
        noise_mean, noise_std_dev    = 1, 0.5
        self.noise_list                        = []
        
        for idx1 in range(self.N):

            t_list                             = np.arange(0,self.stop_time,h.dt)
            noise_current                      = np.random.normal(noise_mean, noise_std_dev, len(t_list))
            noise_current_vector               = h.Vector()
            noise_current_vector.from_python(noise_current)
            
            noise_input                        = h.IClamp(0.5, sec = self.cells[idx1].soma)
            noise_input.delay                  = 0
            noise_input.dur                    = 1e9
            #noise_input.amp                    = 0.1#noise_current_vector
            noise_current_vector.play(noise_input.amp, t_list, True)
            self.noise_list.append(noise_input)
I've looked through the previous post on this matter, where Ted posted the hoc code to do this (viewtopic.php?t=2986), but I'm looking to build my network using Python as the interpreter.

If there is another solution I would be happy to pursue it. I would also be happy with some guidance/pointers on where to look/how I could translate the hoc code into a python format. I have access to the NEURON book as well.

Thanks in advance!
Ian

Re: injecting continuous normally distributed noise in python

Posted: Mon Sep 14, 2020 7:23 am
by gladonias
Have you checked NetStim.noise?

Re: injecting continuous normally distributed noise in python

Posted: Mon Sep 14, 2020 3:10 pm
by ted
thiank wrote:I've been trying to insert normally distributed noise onto my cells via IClamp . . . I have a vector of say 1x1000 (1 per ms) that I want to set as the amp value.
Your code was heading in the right direction. Just a few changes and it will work. Here's a toy example (just a single cell) that might help you finish the job:

Code: Select all

from neuron import h,gui
import numpy as np

noise_mean, noise_std_dev = 1.0, 0.5

tvec = h.Vector(np.linspace(0.0, h.tstop, int(h.tstop/h.dt)))
noise_current = np.random.normal(noise_mean, noise_std_dev, len(tvec))
noise_current_vector = h.Vector()
noise_current_vector.from_python(noise_current)

soma = h.Section(name="soma")
stim = h.IClamp(soma(0.5))
stim.delay = 0.0
stim.dur = 1e9

noise_current_vector.play(stim._ref_amp, tvec, True)
Notice that I decided to use Vector.play with interpolation (read the documentation of Vector.play in the Programmer's Reference).
I've looked through the previous post on this matter, where Ted posted the hoc code to do this
The point of that earlier example was to demonstrate an NMODL-specified current source that generates a synthetic noise current. The NMODL-specified current source can be used with model cells that are built with either hoc or Python. It's a point process, so just download the zip file, expand it, copy the ingauss.mod file to your own directory, compile it with mknrndll or nrnivmodl, and use as if it were an IClamp with different parameters. Very little additional effort is needed to use it with Random123 as its pseudorandom sequence generator.