def connect(self, neuronName, custom): """ Connect all nodes in the model. """ if self.connected: return if not self.built: self.build(neuronName, custom) cynest.CopyModel("static_synapse_hom_wd", "excitatory", { "weight": self.J_E, "delay": self.delay }) cynest.CopyModel("static_synapse_hom_wd", "inhibitory", { "weight": self.J_I, "delay": self.delay }) cynest.RandomConvergentConnect(self.nodes_E, self.nodes, self.C_E, model="excitatory") cynest.RandomConvergentConnect(self.nodes_I, self.nodes, self.C_I, model="inhibitory") cynest.DivergentConnect(self.noise, self.nodes, model="excitatory") cynest.ConvergentConnect(self.nodes_E[:self.N_rec], self.spikes_E) cynest.ConvergentConnect(self.nodes_I[:self.N_rec], self.spikes_I) self.connected = True
def test_ConvergentConnect(self): """ConvergentConnect pre to post""" nest.ResetKernel() pre = nest.Create("iaf_neuron", 3) post = nest.Create("iaf_neuron", 1) nest.ConvergentConnect(pre, post) expected_targets = [post[0] for x in range(len(pre))] connections = nest.FindConnections(pre) targets = nest.GetStatus(connections, "target") self.assertEqual(expected_targets, targets)
def test_ConvergentConnect(self): """ConvergentConnect""" cynest.ResetKernel() a=cynest.Create("iaf_neuron", 10) target=[1] sources=[1 * x for x in list(range(2,11))] cynest.ConvergentConnect(sources, target, [1.0], [1.0]) conn1=cynest.GetConnections(sources) stat1=cynest.GetStatus(conn1) target1=[ d['source'] for d in stat1] self.assertEqual(sources, target1)
def test_ConvergentConnectWD(self): """ConvergentConnect pre to post with weight and delay""" nest.ResetKernel() pre = nest.Create("iaf_neuron", 3) post = nest.Create("iaf_neuron", 1) nest.ConvergentConnect(pre, post, weight=[2.0, 2.0, 2.0], delay=[1.0, 2.0, 3.0]) connections = nest.FindConnections(pre) weights = nest.GetStatus(connections, "weight") delays = nest.GetStatus(connections, "delay") self.assertEqual(weights, [2.0, 2.0, 2.0]) self.assertEqual(delays, [1.0, 2.0, 3.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]
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()
# 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. def output_rate(guess): print "Inhibitory rate estimate: %5.2f Hz ->" % guess,
#! /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()
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()
print("Connecting devices.") nest.CopyModel("static_synapse", "excitatory", { "weight": J_ex, "delay": delay }) nest.CopyModel("static_synapse", "inhibitory", { "weight": J_in, "delay": delay }) nest.DivergentConnect(noise, nodes_ex, model="excitatory") nest.DivergentConnect(noise, nodes_in, model="excitatory") nest.ConvergentConnect(list(range(1, N_rec + 1)), espikes, model="excitatory") nest.ConvergentConnect(list(range(NE + 1, NE + 1 + N_rec)), ispikes, model="excitatory") print("Connecting network.") # We now iterate over all neuron IDs, and connect the neuron to # the sources from our array. The first loop connects the excitatory neurons # and the second loop the inhibitory neurons. print("Excitatory connections") nest.RandomConvergentConnect(nodes_ex, nodes_ex + nodes_in, CE,
def connect(self): nest.DivergentConnect(self.noise,self.neuron) nest.ConvergentConnect(self.neuron, self.spike)
print("Connecting devices.") nest.CopyModel("static_synapse", "excitatory", { "weight": J_ex, "delay": delay }) nest.CopyModel("static_synapse", "inhibitory", { "weight": J_in, "delay": delay }) nest.DivergentConnect(noise, nodes_ex, model="excitatory") nest.DivergentConnect(noise, nodes_in, model="excitatory") nest.ConvergentConnect(list(range(1, N_rec + 1)), espikes, model="excitatory") nest.ConvergentConnect(list(range(NE + 1, NE + 1 + N_rec)), ispikes, model="excitatory") print("Connecting network.") # Here, we create the connections from the excitatory neurons to all other # neurons. We exploit that the neurons have consecutive IDs, running from # 1,...,NE for the excitatory neurons and from # (NE+1),...,(NE+NI) for the inhibitory neurons. numpy.random.seed(1234) sources_ex = numpy.random.random_integers(1, NE, (N_neurons, CE)) sources_in = numpy.random.random_integers(NE + 1, N_neurons, (N_neurons, CI))