Ejemplo n.º 1
0
    def test_SetStatusVth_E_L(self):
        """SetStatus of reversal and threshold potential """

        m = "sample_neuron"

        cynest.ResetKernel()

        neuron1 = cynest.Create(m)
        neuron2 = cynest.Create(m)

        # must not depend on the order.
        new_EL = -90.
        new_Vth = -10.
        cynest.SetStatus(neuron1, {'E_L': new_EL})
        cynest.SetStatus(neuron2, {'V_th': new_Vth})

        cynest.SetStatus(neuron1, {'V_th': new_Vth})
        cynest.SetStatus(neuron2, {'E_L': new_EL})

        # next three lines for debugging
        vth1, vth2 = cynest.GetStatus(neuron1, 'V_th'), cynest.GetStatus(
            neuron2, 'V_th')
        if vth1 != vth2:
            print(m, vth1, vth2, cynest.GetStatus(neuron1, 'E_L'),
                  cynest.GetStatus(neuron2, 'E_L'))

        assert (cynest.GetStatus(neuron1,
                                 'V_th') == cynest.GetStatus(neuron2, 'V_th'))
Ejemplo n.º 2
0
def output_rate(guess):
    print "Inhibitory rate estimate: %5.2f Hz ->" % guess,
    rate = float(abs(n_in * guess))
    nest.SetStatus([noise[1]], "rate", rate)
    nest.SetStatus(spikedetector, "n_events", 0)
    nest.Simulate(t_sim)
    out = nest.GetStatus(spikedetector, "n_events")[0] * 1000.0 / t_sim
    print "Neuron rate: %6.2f Hz (goal: %4.2f Hz)" % (out, r_ex)
    return out
Ejemplo n.º 3
0
 def output_rate(self,mean, std):
     t=nest.GetKernelStatus('time')
     if t>100000: # prevent overflow of clock
         self.build()
         self.connect()
         t=0.0
     nest.Simulate(self.t_inter_trial)
     nest.SetStatus(self.spike, "n_events", 0)
     nest.SetStatus(self.noise,[{'mean':mean, 'std':std, 'start': 0.0, 'stop': 1000., 'origin':t}])
     nest.Simulate(self.t_sim)
     rate=nest.GetStatus(self.spike, "n_events")[0]*1000.0/(self.n_neurons*self.t_sim)
     return rate
Ejemplo n.º 4
0
    def test_ParamTypes(self):
        """Test of all parameter types"""

        cynest.ResetKernel()

        node = cynest.Create("sample_neuron")
        cynest.SetStatus(node, {"param1":2, "param2":6.5, "param3": True, "param4":"sd", "param5":'r',  \
        "param6":[1,2,3,4], "param7":{"c1":1, "c2":2}, "param8":{"e1":{"s1":1}}})

        cynest.Simulate(1)

        s = cynest.GetStatus(node)[0]

        self.assertEqual(s["param1"], 2)
        self.assertEqual(s["param2"], 6.5)
        self.assertEqual(s["param3"], True)
        self.assertEqual(s["param4"], "sd")
        self.assertEqual(s["param5"], 'r')
        self.assertEqual(s["param6"][0], 1)
        self.assertEqual(s["param6"][1], 2)
        self.assertEqual(s["param6"][2], 3)
        self.assertEqual(s["param6"][3], 4)
        self.assertEqual(s["param7"]["c1"], 1)
        self.assertEqual(s["param7"]["c2"], 2)
        self.assertEqual(s["param8"]["e1"]["s1"], 1)
Ejemplo n.º 5
0
    def build(self, neuronName, custom):
        """
        Create all nodes, used in the model.
        """
        if self.built == True: return
        self.calibrate()

        self.nodes = cynest.Create(neuronName, self.N_neurons)

        self.noise = cynest.Create("poisson_generator", 1,
                                   {"rate": self.p_rate})
        self.spikes = cynest.Create("spike_detector", 2,
                                    [{
                                        "label": "brunel-py-ex"
                                    }, {
                                        "label": "brunel-py-in"
                                    }])
        if custom == True:
            cynest.SetStatus(self.nodes, [{"optimized": True}])

        self.nodes_E = self.nodes[:self.N_E]
        self.nodes_I = self.nodes[self.N_E:]
        self.spikes_E = self.spikes[:1]
        self.spikes_I = self.spikes[1:]
        self.built = True
Ejemplo n.º 6
0
def build_network(dt):

    nest.ResetKernel()
    nest.SetKernelStatus({"local_num_threads": 1, "resolution": dt})

    neuron = nest.Create('iaf_neuron')
    nest.SetStatus(neuron, "I_e", 376.0)

    vm = nest.Create('voltmeter')
    nest.SetStatus(vm, "withtime", True)

    sd = nest.Create('spike_detector')

    nest.Connect(vm, neuron)
    nest.Connect(neuron, sd)

    return vm, sd
Ejemplo n.º 7
0
 def build(self):
     nest.ResetKernel()
     nest.SetKernelStatus({'local_num_threads': self.n_threads})
     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=nest.Create('spike_detector')
     nest.SetStatus(self.spike,[{'to_memory':True, 'to_file':False}])
Ejemplo n.º 8
0
    def test_SetStatusParam(self):
        """SetStatus with parameter"""

        m = "sample_neuron"

        cynest.ResetKernel()
        n = cynest.Create(m)
        cynest.SetStatus(n, 'V_m', 3.)
        self.assertEqual(cynest.GetStatus(n, 'V_m')[0], 3.)
Ejemplo n.º 9
0
    def test_SetStatusList(self):
        """SetStatus with list"""

        m = "sample_neuron"

        cynest.ResetKernel()
        n = cynest.Create(m)
        cynest.SetStatus(n, [{'V_m': 2.}])
        self.assertEqual(cynest.GetStatus(n, 'V_m')[0], 2.)
Ejemplo n.º 10
0
    def test_SetStatus(self):
        """SetStatus with dict"""

        m = "sample_neuron"

        cynest.ResetKernel()
        n = cynest.Create(m)
        cynest.SetStatus(n, {'V_m': 1.})
        self.assertEqual(cynest.GetStatus(n, 'V_m')[0], 1.)
Ejemplo n.º 11
0
    def test_Function(self):
        """Test of function object"""

        cynest.ResetKernel()

        node = cynest.Create("sample_neuron")

        try:
            cynest.SetStatus(node, {"param2": testFct})

        except:
            info = sys.exc_info()[1]
Ejemplo n.º 12
0
    def test_Instance(self):
        """Test of instance object"""

        cynest.ResetKernel()

        t = testClass()

        node = cynest.Create("sample_neuron")

        try:
            cynest.SetStatus(node, {"param2": t})

        except:
            info = sys.exc_info()[1]
Ejemplo n.º 13
0
    def test_FindConnections(self):
        """FindConnections"""

        nest.ResetKernel()

        a = nest.Create("iaf_neuron", 3)
        nest.DivergentConnect(a, a)
        c1 = nest.FindConnections(a)
        c2 = nest.FindConnections(a, synapse_type="static_synapse")
        self.assertEqual(c1, c2)

        d1 = [{"weight": w} for w in [2.0, 3.0, 4.0]]

        c3 = nest.FindConnections(a, a)
        nest.SetStatus(c3, d1)
        s1 = nest.GetStatus(c3, "weight")
        self.assertEqual(s1, [w["weight"] for w in d1])
# To be consistent with the other parameters in the equations, b must be
# converted to pA (pico Ampere).

import cynest as nest
import cynest.voltage_trace
import pylab

nest.ResetKernel()

res = 0.1
nest.SetKernelStatus({"resolution": res})
neuron = nest.Create("aeif_cond_exp")
nest.SetStatus(neuron, {
    "V_peak": 20.,
    "E_L": -60.0,
    "a": 80.0,
    "b": 80.5,
    "tau_w": 720.0
})
dc = nest.Create("dc_generator")

nest.SetStatus(dc, [{"amplitude": -800.0, "start": 0.0, "stop": 400.0}])

nest.ConvergentConnect(dc, neuron)

voltmeter = nest.Create("voltmeter")
nest.SetStatus(voltmeter, {"withgid": True, "withtime": True, 'interval': 0.1})

nest.Connect(voltmeter, neuron)

nest.Simulate(1000.0)
Ejemplo n.º 15
0
# Third, the nodes are created using Create(). We store the returned
# handles in variables for later reference.

neuron = nest.Create("iaf_neuron")
noise = nest.Create("poisson_generator", 2)
voltmeter = nest.Create("voltmeter")
spikedetector = nest.Create("spike_detector")

# Fourth, the excitatory Poisson generator (noise[0]) and the
# voltmeter are configured using SetStatus, which expects a list of
# node handles and a list of parameter dictionaries. The rate of the
# inhibitory Poisson generator is set later. Note that we need not set
# parameters for the neuron and the spike detector, since they have
# satisfactory defaults.

nest.SetStatus(noise, [{"rate": n_ex * r_ex}, {"rate": n_in * r_in}])
nest.SetStatus(voltmeter, {
    "interval": 10.0,
    "withgid": True,
    "withtime": True
})

# Fifth, the neuron is connected to the spike detector and the
# voltmeter, as are the two Poisson generators to the neuron. The
# command Connect() has different variants. Plain Connect() just takes
# the handles of pre- and post-synaptic nodes and uses the default
# values for weight and delay. ConvergentConnect() takes four
# arguments: A list of pre-synaptic nodes, a list of post-synaptic
# nodes, and lists of weights and delays. Note that the connection
# direction for the voltmeter is reversed compared to the spike
# detector, because it observes the neuron instead of receiving events
Ejemplo n.º 16
0
nest.SetDefaults("dc_generator", {
    "amplitude": I0,
    "start": TIstart,
    "stop": TIend
})

# create dc_generator:
dc_gen = nest.Create("dc_generator")

# set properties of voltmeter:
volts = nest.Create("voltmeter")

# create voltmeter:
nest.SetStatus([volts], [{
    "label": "voltmeter",
    "withtime": True,
    "withgid": True,
    "interval": 1.
}])

# connect dc_generator to neuron 1:
nest.Connect(dc_gen, [neurons[0]])

# connect voltmeter to neuron 2:
nest.Connect(volts, [neurons[1]])

# set synapse parameters:
syn_param = {
    "tau_psc": Tau_psc,
    "tau_rec": Tau_rec,
    "tau_fac": Tau_fac,
    "U": U,
Ejemplo n.º 17
0
# Brette and Gerstner (2005) J. Neurophysiology.
# This script reproduces figure 2.C of the paper.
# Note that Brette&Gerstner give the value for b in nA.
# To be consistent with the other parameters in the equations, b must be
# converted to pA (pico Ampere).

import cynest as nest
import cynest.voltage_trace
import pylab

nest.ResetKernel()

res = 0.1
nest.SetKernelStatus({"resolution": res})
neuron = nest.Create("aeif_cond_alpha")
nest.SetStatus(neuron, {"a": 4.0, "b": 80.5})
dc = nest.Create("dc_generator", 2)

nest.SetStatus(dc, [{
    "amplitude": 500.0,
    "start": 0.0,
    "stop": 200.0
}, {
    "amplitude": 800.0,
    "start": 500.0,
    "stop": 1000.0
}])

nest.ConvergentConnect(dc, neuron)

voltmeter = nest.Create("voltmeter")
Ejemplo n.º 18
0
#! /usr/bin/env python

import cynest as nest
import cynest.voltage_trace

nest.ResetKernel()

neuron = nest.Create("iaf_neuron")

noise = nest.Create("poisson_generator", 2)
nest.SetStatus(noise, [{"rate": 80000.0}, {"rate": 20000.0}])

sine = nest.Create("ac_generator")
nest.SetStatus(sine, [{"amplitude": 100.0, "frequency": 2.0}])

voltmeter = nest.Create("voltmeter")
nest.SetStatus(voltmeter, {"withgid": True, "withtime": True})

nest.ConvergentConnect(noise, neuron, [1.0, -1.0], 1.0)
nest.Connect(voltmeter, neuron)
nest.Connect(sine, neuron)

nest.Simulate(1000.0)

nest.voltage_trace.from_device(voltmeter)
nest.voltage_trace.show()
Ejemplo n.º 19
0
#! /usr/bin/env python

import cynest as nest
import cynest.voltage_trace

nest.ResetKernel()

neuron = nest.Create("iaf_neuron")

noise = nest.Create("poisson_generator", 2)
nest.SetStatus(noise, [{"rate": 80000.0}, {"rate": 15000.0}])

voltmeter = nest.Create("voltmeter")
nest.SetStatus(voltmeter, {"withgid": True, "withtime": True})

nest.ConvergentConnect(noise, neuron, [1.2, -1.0], 1.0)
nest.Connect(voltmeter, neuron)

nest.Simulate(1000.0)

nest.voltage_trace.from_device(voltmeter)
nest.voltage_trace.show()
Ejemplo n.º 20
0
#! layer, since they will differ from layer to layer. We will add them
#! below by updating the ``'elements'`` dictionary entry for each
#! population.

#! Retina
#! ------
layerProps.update({'elements': 'RetinaNode'})
retina = topo.CreateLayer(layerProps)

#! Now set phases of retinal oscillators; we use a list comprehension instead
#! of a loop.
[
    nest.SetStatus(
        [n], {
            "phi":
            phiInit(
                topo.GetPosition([n])[0], Params["lambda_dg"],
                Params["phi_dg"])
        }) for n in nest.GetLeaves(retina)[0]
]

#! Thalamus
#! --------

#! We first introduce specific neuron models for the thalamic relay
#! cells and interneurons. These have identical properties, but by
#! treating them as different models, we can address them specifically
#! when building connections.
#!
#! We use a list comprehension to do the model copies.
[
Ejemplo n.º 21
0
Plot several runs of the iaf_cond_exp_sfa_rr neuron with no input and
various initial values for the membrane potential.
"""

import cynest as nest
import numpy
import pylab

for vinit in numpy.arange(-100, -50, 10, float):

    nest.ResetKernel()

    cbn = nest.Create('iaf_cond_exp_sfa_rr')

    # set the initial membrane potential
    nest.SetStatus(cbn, 'V_m', vinit)

    voltmeter = nest.Create('voltmeter')
    nest.SetStatus(voltmeter, {'withtime': True})
    nest.Connect(voltmeter, cbn)

    nest.Simulate(75.0)

    t = nest.GetStatus(voltmeter, "events")[0]["times"]
    v = nest.GetStatus(voltmeter, "events")[0]["V_m"]

    pylab.plot(t, v, label="initial V_m=%.2f mV" % vinit)

pylab.legend(loc=4)
pylab.xlabel("time (ms)")
pylab.ylabel("V_m (mV)")
Ejemplo n.º 22
0
fac_params = {"U": 0.1, "tau_fac": 1000., "tau_rec": 100., "weight": 250.}

# Here we assign the parameter set to the synapse models
t1_params = fac_params  # for tsodyks_synapse
t2_params = t1_params.copy()  # for tsodyks2_synapse

nest.SetDefaults("tsodyks_synapse", t1_params)
nest.SetDefaults("tsodyks2_synapse", t2_params)
nest.SetDefaults("iaf_psc_exp", {"tau_syn_ex": 3.})

neuron = nest.Create("iaf_psc_exp", 3)

nest.Connect([neuron[0]], [neuron[1]], model="tsodyks_synapse")
nest.Connect([neuron[0]], [neuron[2]], model="tsodyks2_synapse")
voltmeter = nest.Create("voltmeter", 2)
nest.SetStatus(voltmeter, {"withgid": True, "withtime": True})
nest.Connect([voltmeter[0]], [neuron[1]])
nest.Connect([voltmeter[1]], [neuron[2]])

nest.SetStatus([neuron[0]], "I_e", 376.0)
nest.Simulate(500.0)
nest.SetStatus([neuron[0]], "I_e", 0.0)
nest.Simulate(800.0)
nest.SetStatus([neuron[0]], "I_e", 376.0)
nest.Simulate(500.0)
nest.SetStatus([neuron[0]], "I_e", 0.0)
nest.Simulate(100.0)

nest.voltage_trace.from_device([voltmeter[0]])
nest.voltage_trace.from_device([voltmeter[1]])
nest.voltage_trace.show()
Ejemplo n.º 23
0
#! /usr/bin/env python

import matplotlib
# matplotlib.use("macosx")
import pylab

import cynest as nest
import cynest.voltage_trace

weight = 20.0
delay = 1.0
stim = 1000.0

neuron1 = nest.Create("iaf_neuron")
neuron2 = nest.Create("iaf_neuron")
voltmeter = nest.Create("voltmeter")

nest.SetStatus(neuron1, {"I_e": stim})
nest.Connect(neuron1, neuron2, weight, delay)
nest.Connect(voltmeter, neuron2)

nest.Simulate(100.0)

nest.voltage_trace.from_device(voltmeter)
nest.voltage_trace.show()
Ejemplo n.º 24
0
}

nest.SetDefaults("iaf_psc_delta", neuron_params)

nodes_ex = nest.Create("iaf_psc_delta", NE)
nodes_in = nest.Create("iaf_psc_delta", NI)

nest.SetDefaults("poisson_generator", {"rate": p_rate})
noise = nest.Create("poisson_generator")

espikes = nest.Create("spike_detector")
ispikes = nest.Create("spike_detector")

nest.SetStatus([espikes], [{
    "label": "brunel-py-ex",
    "withtime": True,
    "withgid": True
}])

nest.SetStatus([ispikes], [{
    "label": "brunel-py-in",
    "withtime": True,
    "withgid": True
}])

print("Connecting devices.")

nest.CopyModel("static_synapse", "excitatory", {
    "weight": J_ex,
    "delay": delay
})
Ejemplo n.º 25
0
def bias(n):
    # constructs the dictionary with current ramp
    return { 'I_e': (n * (bias_end-bias_begin)/N + bias_begin) }
    

driveparams  = {'amplitude':50., 'frequency':35.}
noiseparams  = {'mean':0.0, 'std':200.}
neuronparams = { 'tau_m':20., 'V_th':20., 'E_L':10.,
                 't_ref':2., 'V_reset':0., 'C_m':200., 'V_m':0.}

neurons = nest.Create('iaf_psc_alpha',N)
sd      = nest.Create('spike_detector')
noise   = nest.Create('noise_generator')
drive   = nest.Create('ac_generator')

nest.SetStatus(drive,   driveparams )
nest.SetStatus(noise,   noiseparams )
nest.SetStatus(neurons, neuronparams)
nest.SetStatus(neurons, map(bias, neurons))

nest.SetStatus(sd, {"withgid": True, "withtime": True})

nest.DivergentConnect(drive, neurons)
nest.DivergentConnect(noise, neurons)
nest.ConvergentConnect(neurons, sd)

nest.Simulate(T)

nest.raster_plot.from_device(sd, hist=True)
nest.raster_plot.show()
Ejemplo n.º 26
0
#!/usr/bin/env python

import cynest as nest
import cynest.voltage_trace

nest.ResetKernel()

neuron = nest.Create("iaf_neuron")
nest.SetStatus(neuron, "I_e", 376.0)

voltmeter = nest.Create("voltmeter")
nest.SetStatus(voltmeter, {"withgid": True, "withtime": True})

nest.Connect(voltmeter, neuron)

nest.Simulate(1000.0)

nest.voltage_trace.from_device(voltmeter)
nest.voltage_trace.show()
Ejemplo n.º 27
0
tmp[len(psp) - 1:-1] += psp
psp = tmp
del tmp

P = a * weight * pylab.convolve(gauss, psp)

l = len(P)
t_P = convolution_resolution * numpy.linspace(
    -l / 2., l / 2., l) + pulsetime + 1.  # one ms delay

#########################################################################
# simulation section

nest.ResetKernel()

nest.SetStatus([0], [{'resolution': simulation_resolution}])
J = Cm * weight / tau_s * fudge
nest.SetDefaults('static_synapse', {'weight': J})

n = nest.Create(
    'iaf_psc_alpha', n_neurons, {
        'V_th': Vth,
        'tau_m': tau_m,
        'tau_syn_ex': tau_s,
        'C_m': Cm,
        'E_L': V0,
        'V_reset': V0,
        'V_m': V0
    })
pp = nest.Create('pulsepacket_generator', n_neurons, {
    'pulse_times': [pulsetime],
Ejemplo n.º 28
0
trial_duration = 1000.0  # trial duration, in ms
num_trials = 5  # number of trials to perform

# set up network
nest.ResetKernel()
pg = nest.Create('poisson_generator',
                 params={
                     'rate': rate,
                     'start': start,
                     'stop': stop
                 })
sd = nest.Create('spike_detector')
nest.Connect(pg, sd)

# before each trial, we set the 'origin' of the poisson_generator to the current
# simulation time
for n in xrange(num_trials):
    nest.SetStatus(pg, {'origin': nest.GetKernelStatus()['time']})
    nest.Simulate(trial_duration)

# now plot the result, including a histogram
# note: The histogram will show spikes seemingly located before 100ms into
#       each trial. This is due to sub-optimal automatic placement of histogram bin borders.
import cynest.raster_plot
nest.raster_plot.from_device(sd,
                             hist=True,
                             hist_binwidth=100.,
                             title='Repeated stimulation by Poisson generator')
nest.raster_plot.show()