injecting continuous normally distributed noise in python

When Python is the interpreter, what is a good
design for the interface to the basic NEURON
concepts.

Moderator: hines

Post Reply
thiank
Posts: 1
Joined: Fri Aug 23, 2019 2:54 pm

injecting continuous normally distributed noise in python

Post 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
gladonias
Posts: 6
Joined: Thu Feb 28, 2019 5:24 am
Location: Waterford Institute of Technology

Re: injecting continuous normally distributed noise in python

Post by gladonias »

Have you checked NetStim.noise?
ted
Site Admin
Posts: 5793
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: injecting continuous normally distributed noise in python

Post 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.
Post Reply