def test_ConnectPrePostWD(self): """Connect pre to post with a weight and delay""" # Connect([pre], [post], w, d) nest.ResetKernel() pre = nest.Create("iaf_neuron", 2) post = nest.Create("iaf_neuron", 2) nest.Connect(pre, post, 2.0, 2.0) connections = nest.FindConnections(pre) weights = nest.GetStatus(connections, "weight") self.assertEqual(weights, [2.0, 2.0]) # Connect([pre], [post], [w], [d]) nest.ResetKernel() pre = nest.Create("iaf_neuron", 2) post = nest.Create("iaf_neuron", 2) nest.Connect(pre, post, [2.0], [2.0]) connections = nest.FindConnections(pre) weights = nest.GetStatus(connections, "weight") delays = nest.GetStatus(connections, "delay") self.assertEqual(weights, [2.0, 2.0]) self.assertEqual(delays, [2.0, 2.0]) # Connect([pre], [post], [w, w], [d, d]) nest.ResetKernel() pre = nest.Create("iaf_neuron", 2) post = nest.Create("iaf_neuron", 2) nest.Connect(pre, post, [2.0, 3.0], [2.0, 3.0]) connections = nest.FindConnections(pre) weights = nest.GetStatus(connections, "weight") delays = nest.GetStatus(connections, "delay") self.assertEqual(weights, [2.0, 3.0]) self.assertEqual(delays, [2.0, 3.0])
def test_ConnectPrePostParams(self): """Connect pre to post with a params dict""" # Connect([pre], [post], params) nest.ResetKernel() pre = nest.Create("iaf_neuron", 2) post = nest.Create("iaf_neuron", 2) nest.Connect(pre, post, {"weight": 2.0}) connections = nest.FindConnections(pre) weights = nest.GetStatus(connections, "weight") self.assertEqual(weights, [2.0, 2.0]) # Connect([pre], [post], [params]) nest.ResetKernel() pre = nest.Create("iaf_neuron", 2) post = nest.Create("iaf_neuron", 2) nest.Connect(pre, post, [{"weight": 2.0}]) connections = nest.FindConnections(pre) weights = nest.GetStatus(connections, "weight") self.assertEqual(weights, [2.0, 2.0]) # Connect([pre], [post], [params, params]) nest.ResetKernel() pre = nest.Create("iaf_neuron", 2) post = nest.Create("iaf_neuron", 2) nest.Connect(pre, post, [{"weight": 2.0}, {"weight": 3.0}]) connections = nest.FindConnections(pre) weights = nest.GetStatus(connections, "weight") self.assertEqual(weights, [2.0, 3.0])
def test_CopyModel(self): """CopyModel""" cynest.ResetKernel() cynest.CopyModel("sample_neuron", 'new_neuron', {'V_m': 10.0}) vm = cynest.GetDefaults('new_neuron')['V_m'] self.assertEqual(vm, 10.0) n = cynest.Create('new_neuron', 10) vm = cynest.GetStatus([n[0]])[0]['V_m'] self.assertEqual(vm, 10.0) cynest.CopyModel('static_synapse', 'new_synapse', {'weight': 10.}) cynest.Connect([n[0]], [n[1]], model='new_synapse') w = cynest.GetDefaults('new_synapse')['weight'] self.assertEqual(w, 10.0) try: cynest.CopyModel( "sample_neuron", 'new_neuron') # shouldn't be possible a second time self.fail('an error should have risen!') # should not be reached except: info = sys.exc_info()[1] if not "NewModelNameExists" in info.__str__(): self.fail('could not pass error message to cynest!')
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
def test_ConnectPrePost(self): """Connect pre to post""" # Connect([pre], [post]) nest.ResetKernel() pre = nest.Create("iaf_neuron", 2) post = nest.Create("iaf_neuron", 2) nest.Connect(pre, post) connections = nest.FindConnections(pre) targets = nest.GetStatus(connections, "target") self.assertEqual(targets, post)
def test_UnknownNode(self): """Unknown node""" nest.ResetKernel() try: nest.Connect([99], [99]) self.fail('an error should have risen!') # should not be reached except nest.NESTError: info = sys.exc_info()[1] if not "UnknownNode" in info.__str__(): self.fail('wrong error message') # another error has been thrown, this is wrong except: self.fail('wrong error has been thrown')
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)
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)
def test_UnexcpectedEvent(self): """Unexpected Event""" nest.ResetKernel() n = nest.Create('iaf_neuron') vm = nest.Create('voltmeter') sd = nest.Create('spike_detector') try: nest.Connect(sd, n) self.fail() # should not be reached except nest.NESTError: info = sys.exc_info()[1] if not "UnexpectedEvent" in info.__str__(): self.fail() # another error has been thrown, this is wrong except: self.fail()
def test_WrongConnection(self): """Wrong Connections""" nest.ResetKernel() n = nest.Create('iaf_neuron') vm = nest.Create('voltmeter') sd = nest.Create('spike_detector') try: nest.Connect(n, vm) self.fail() # should not be reached except nest.NESTError: info = sys.exc_info()[1] if not "IllegalConnection" in info.__str__(): self.fail() # another error has been thrown, this is wrong except: self.fail()
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) nest.voltage_trace.from_device(voltmeter) pylab.axis([0, 1000, -85, 0]) nest.voltage_trace.show()
# 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 # from it. Thus, Connect() reflects the direction of signal flow in # the simulation kernel rather than the physical process of inserting # an electrode into the neuron. The latter semantics is presently not # available in NEST. nest.Connect(neuron, spikedetector) nest.Connect(voltmeter, neuron) nest.ConvergentConnect(noise, neuron, [epsc, ipsc], 1.0) # To determine the optimal rate of the neurons in the inhibitory # population, the network is simulated several times for different # values of the inhibitory rate while measuring the rate of the target # neuron. This is done until the rate of the target neuron matches the # rate of the neurons in the excitatory population with a certain # accuracy. The algorithm is implemented in two steps: # # First, the function output_rate() is defined to measure the firing # rate of the target neuron for a given rate of the inhibitory # neurons.
# 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, "delay": 0.1, "weight": A, "u": 0.0, "x": 1.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()
""" 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()
dep_params = {"U": 0.67, "weight": 250.} # parameter set for facilitation 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)
n = nest.Create('iaf_cond_alpha', params={'tau_syn_ex': 1.0, 'V_reset': -70.0}) m = nest.Create('multimeter', params={ 'withtime': True, '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])
#! /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()
'V_m': V0 }) pp = nest.Create('pulsepacket_generator', n_neurons, { 'pulse_times': [pulsetime], 'activity': a, 'sdev': sdev }) vm = nest.Create( 'voltmeter', 1, { 'record_to': ['memory'], 'withtime': True, 'withgid': True, 'interval': sampling_resolution }) nest.Connect(pp, n) nest.DivergentConnect(vm, n) nest.Simulate(simtime) V = nest.GetStatus(vm, 'events')[0]['V_m'] t_V = nest.GetStatus(vm, 'events')[0]['times'] senders = nest.GetStatus(vm, 'events')[0]['senders'] ######################################################################### # plotting... v = {} t = {} for s in range(senders.size):
start = 100.0 # start of simulation relative to trial start, in ms stop = 500.0 # end of simulation relative to trial start, in ms 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')