Beispiel #1
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
Beispiel #2
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)
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
Beispiel #4
0
    def test_ModelCreateSimulate(self):
        """Model Creation and Simulation"""

        cynest.ResetKernel()

        cynest.SetDefaults("sample_neuron", {"param": 20})
        node = cynest.Create("sample_neuron")
        cynest.Simulate(1)

        self.assertEqual(cynest.GetStatus(node)[0]["param"], 30)
Beispiel #5
0
 def run(self, neuronName, simtime=40.):
     """
     Simulate the model for simtime milliseconds and print the
     firing rates of the network during htis period.  
     """
     if not self.connected:
         self.connect(neuronName)
     cynest.Simulate(simtime)
     events = cynest.GetStatus(self.spikes, "n_events")
     self.rate_ex = events[0] / simtime * 1000.0 / self.N_rec
     print "Excitatory rate   : %.2f Hz" % self.rate_ex
     self.rate_in = events[1] / simtime * 1000.0 / self.N_rec
     print "Inhibitory rate   : %.2f Hz" % self.rate_in
Beispiel #6
0
    def test_EventsVoltage(self):
        """Voltage Events"""

        nest.ResetKernel()

        nest.sr('20 setverbosity')
        n = nest.Create('iaf_neuron')
        vm = nest.Create('voltmeter', 1, {'withtime': True, 'interval': 1.})

        nest.Connect(vm, n)
        nest.SetKernelStatus({'print_time': False})
        nest.Simulate(10)

        d = nest.GetStatus(vm, 'events')[0]

        self.assertEqual(len(d['V_m']), 9)
Beispiel #7
0
    def test_EventsSpikes(self):
        """Spike Events"""

        nest.ResetKernel()

        nest.sr('20 setverbosity')

        n = nest.Create('iaf_neuron', 1, {'I_e': 1000.})
        sd = nest.Create('spike_detector', 1, {'withtime': True})

        nest.Connect(n, sd)
        nest.SetKernelStatus({'print_time': False})
        nest.Simulate(1000)

        d = nest.GetStatus(sd, 'events')[0]

        self.assert_(len(d['times']) > 0)
Beispiel #8
0
    def test_ThreadsGetEvents(self):
        """ Gathering events across threads """

        # Test if we have a thread-enabled NEST
        nest.sr("statusdict /have_pthreads get")
        if not nest.spp(): return

        threads = [1, 2, 4, 8]

        n_events_sd = []
        n_events_vm = []

        N = 128
        Simtime = 1000.

        for t in threads:

            nest.ResetKernel()
            nest.SetKernelStatus({'local_num_threads': t})

            n = nest.Create('iaf_psc_alpha', N,
                            {'I_e': 2000.})  # force a lot of spike events
            sd = nest.Create('spike_detector')
            vm = nest.Create('voltmeter')

            nest.ConvergentConnect(n, sd)
            nest.DivergentConnect(vm, n)

            nest.Simulate(Simtime)

            n_events_sd.append(nest.GetStatus(sd, 'n_events')[0])
            n_events_vm.append(nest.GetStatus(vm, 'n_events')[0])

        ref_vm = N * (Simtime - 1)
        ref_sd = n_events_sd[0]

        # could be done more elegantly with any(), ravel(),
        # but we dont want to be dependent on numpy et al
        [self.assertEqual(x, ref_vm) for x in n_events_vm]
        [self.assertEqual(x, ref_sd) for x in n_events_sd]
    def run(self, neuronName, custom, simtime=40.):
        """
        Simulate the model for simtime milliseconds and print the
        firing rates of the network during htis period.  
        """
        if not self.connected:
            self.connect(neuronName, custom)

        cynest.Simulate(simtime)
        #for i in range(1, 20):
        #    cynest.sps(float(2.0))
        #    cynest.sr("ms Simulate")

        events = cynest.GetStatus(self.spikes, "n_events")

        if sys.version_info >= (3, 0):
            self.rate_ex = events[0] // simtime * 1000.0 / self.N_rec
            self.rate_in = events[1] // simtime * 1000.0 / self.N_rec
        else:
            self.rate_ex = events[0] / simtime * 1000.0 / self.N_rec
            self.rate_in = events[1] / simtime * 1000.0 / self.N_rec

        print("Excitatory rate   : %.2f Hz" % self.rate_ex)
        print("Inhibitory rate   : %.2f Hz" % self.rate_in)
# 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,
    "delay": 0.1,
    "weight": A,
    "u": 0.0,
    "x": 1.0
}

# create desired synapse type with chosen parameters:
nest.CopyModel("tsodyks_synapse", "syn", syn_param)

# connect neuron 1 with neuron 2 via synapse model 'syn':
nest.Connect([neurons[0]], [neurons[1]], model="syn")

# simulate:
nest.Simulate(Tend)

# print membrane potential of neuron 2:
nest.voltage_trace.from_device(volts)
nest.voltage_trace.show()
Beispiel #11
0
"""

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)")
pylab.show()
#! This simulation is set up to create a step-wise visualization of
#! the membrane potential. To do so, we simulate ``sim_interval``
#! milliseconds at a time, then read out data from the multimeters,
#! clear data from the multimeters and plot the data as pseudocolor
#! plots.

#! show time during simulation
nest.SetStatus([0], {'print_time': True})

#! lower and upper limits for color scale, for each of the four
#! populations recorded.
vmn = [-80, -80, -80, -80]
vmx = [-50, -50, -50, -50]

nest.Simulate(Params['sim_interval'])

#! loop over simulation intervals
for t in pylab.arange(Params['sim_interval'], Params['simtime'],
                      Params['sim_interval']):

    # do the simulation
    nest.Simulate(Params['sim_interval'])

    # clear figure and choose colormap
    pylab.clf()
    pylab.jet()

    # now plot data from each recorder in turn, assume four recorders
    for name, r in recorders.iteritems():
        rec = r[0]
# 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()
Beispiel #14
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()
Beispiel #15
0
                    'interval': 0.1,
                    'record_from': ['V_m', 'g_ex', 'g_in']
                })

# Create spike generators and connect
gex = nest.Create('spike_generator',
                  params={'spike_times': np.array([10.0, 20.0, 50.0])})
gin = nest.Create('spike_generator',
                  params={'spike_times': np.array([15.0, 25.0, 55.0])})

nest.Connect(gex, n, params={'weight': 40.0})  # excitatory
nest.Connect(gin, n, params={'weight': -20.0})  # inhibitory
nest.Connect(m, n)

# simulate
nest.Simulate(100)

# obtain and display data
events = nest.GetStatus(m)[0]['events']
t = events['times']

pl.clf()

pl.subplot(211)
pl.plot(t, events['V_m'])
pl.axis([0, 100, -75, -53])
pl.ylabel('Membrane potential [mV]')

pl.subplot(212)
pl.plot(t, events['g_ex'], t, events['g_in'])
pl.axis([0, 100, 0, 45])
Beispiel #16
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()