## IF curve example

This example illustrates how to measure the I-F curve of a neuron. The program creates a small group of neurons and injects a noisy current I(t) = I_mean + I_std*W(t) where W(t) is a white noise process. The programm systematically drives the current through a series of values in the two-dimensional (I_mean, I_std) space and measures the firing rate of the neurons.

In this example, we measure the I-F curve of the adaptive exponential integrate and fire neuron (aeif_cond_exp), but any other neuron model that accepts current inputs is possible. The model and its parameters are supplied when the IF_curve object is created.

import numpy
import nest
import shelve

Here we define which model and the neuron parameters to use for measuring the transfer function.

model = 'aeif_cond_exp'
params = {'a': 4.0,
'b': 80.8,
'V_th': -50.4,
'Delta_T': 2.0,
'I_e': 0.0,
'C_m': 281.0,
'g_L': 30.0,
'V_reset': -70.6,
'tau_w': 144.0,
't_ref': 5.0,
'V_peak': -40.0,
'E_L': -70.6,
'E_ex': 0.,
'E_in': -70.}

class IF_curve():

This example illustrates how to measure the I-F curve of a neuron. The program creates a small group of neurons and injects a noisy current I(t)= I_mean + I_std*W(t) where W(t) is a white noise process. The programm systematically drives the current through a series of values in the two-dimensional (I_mean, I_std) space and measures the firing rate of the neurons.

    t_inter_trial = 200.  # Interval between two successive measurement trials
t_sim = 1000.         # Duration of a measurement trial
n_neurons = 100       # Number of neurons

def __init__(self, model, params=False):
self.model = model
self.params = params
self.build()
self.connect()

def build(self):

We reset NEST to delete information from previous simulations and adjust the number of threads.

        nest.ResetKernel()
nest.SetKernelStatus({'local_num_threads': self.n_threads})

We set the default parameters of the neuron model to those defined above and create neurons and devices.

        if self.params:
nest.SetDefaults(self.model, self.params)
self.neuron = nest.Create(self.model, self.n_neurons)
self.noise = nest.Create('noise_generator')
self.spike_detector = nest.Create('spike_detector')

def connect(self):

We connect the noisy current to the neurons and the neurons to the spike detectors.

        nest.Connect(self.noise, self.neuron, 'all_to_all')
nest.Connect(self.neuron, self.spike_detector, 'all_to_all')

def output_rate(self, mean, std):
self.build()
self.connect()

We adjust the parameters of the noise according to the current values.

        nest.SetStatus(self.noise, [{'mean': mean, 'std': std, 'start': 0.0,
'stop': 1000., 'origin': 0.}])

We simulate the network and calculate the rate.

        nest.Simulate(self.t_sim)
rate = nest.GetStatus(self.spike_detector, 'n_events') * 1000.0 \
/ (1. * self.n_neurons * self.t_sim)
return rate

def compute_transfer(self, i_mean=(400.0, 900.0, 50.0),
i_std=(0.0, 600.0, 50.0)):

We loop through all possible combinations of (I_mean, I_sigma) and measure the output rate of the neuron.

        self.i_range = numpy.arange(*i_mean)
self.std_range = numpy.arange(*i_std)
self.rate = numpy.zeros((self.i_range.size, self.std_range.size))
nest.set_verbosity('M_WARNING')
for n, i in enumerate(self.i_range):
print('I  =  {0}'.format(i))
for m, std in enumerate(self.std_range):
self.rate[n, m] = self.output_rate(i, std)

transfer = IF_curve(model, params)
transfer.compute_transfer()

After the simulation is finished we store the data into a file for later analysis.

dat = shelve.open(model + '_transfer.dat')
dat['I_mean'] = transfer.i_range
dat['I_std'] = transfer.std_range
dat['rate'] = transfer.rate
dat.close()
{"ft_lang_label":"__label__en","ft_lang_prob":0.55152637,"math_prob":0.9633194,"size":3670,"snap":"2023-14-2023-23","text_gpt3_token_len":957,"char_repetition_ratio":0.132024,"word_repetition_ratio":0.21604939,"special_character_ratio":0.2880109,"punctuation_ratio":0.2324967,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9974877,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2023-05-30T17:49:23Z\",\"WARC-Record-ID\":\"<urn:uuid:0566b923-90cf-453d-8dcf-82b7751c1fe4>\",\"Content-Length\":\"22309\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:fb5565b5-bcc6-4439-9b10-77d93cb8ebec>\",\"WARC-Concurrent-To\":\"<urn:uuid:fba418d9-f281-41fd-a1e2-cb660204178c>\",\"WARC-IP-Address\":\"5.199.143.70\",\"WARC-Target-URI\":\"https://www.nest-simulator.org/py_sample/if_curve/\",\"WARC-Payload-Digest\":\"sha1:U5ARWRV7NNIYEXVKBV6CULGXGD6FO4NY\",\"WARC-Block-Digest\":\"sha1:CHJI2TXWJAKNGOAEHUPBLZDCUSRI23PB\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2023/CC-MAIN-2023-23/CC-MAIN-2023-23_segments_1685224646076.50_warc_CC-MAIN-20230530163210-20230530193210-00336.warc.gz\"}"}