def run(self, spiketimes): assert spiketimes.shape[0] == self.n_spike_source, 'spiketimes length should be equal to input neurons' start = time.clock() sim.reset() end = time.clock() print "reset uses %f s." % (end - start) for i in range(self.n_spike_source): spiketime = np.array(spiketimes[i], dtype=float) if spiketimes[i].any(): self.spike_source[i].spike_times = spiketime sim.initialize(self.hidden_neurons, V_m=0) sim.initialize(self.output_neurons, V_m=0.) sim.run(self.sim_time) spiketrains = self.output_neurons.get_data(clear=True).segments[0].spiketrains # vtrace = self.hidden_neurons.get_data(clear=True).segments[0].filter(name='V_m')[0] # plt.figure() # plt.plot(vtrace.times, vtrace) # plt.show() hidden_spiketrains = self.hidden_neurons.get_data(clear=True).segments[0].spiketrains spike_cnts = 0 for spiketrain in hidden_spiketrains: spike_cnts += len(list(np.array(spiketrain))) self.hidden_spike_cnts.append(spike_cnts) print 'hidden spikes: ', spike_cnts spiketimes_out = [] for spiketrain in spiketrains: spiketimes_out.append(list(np.array(spiketrain))) return np.array(spiketimes_out)
def create_brain(): """ Initializes PyNN with the minimal neuronal network """ sim.setup(timestep=0.1, min_delay=0.1, max_delay=20.0, threads=1, rng_seeds=[1234]) # Following parameters were taken from the husky braitenberg brain experiment (braitenberg.py) SENSORPARAMS = { 'cm': 0.025, 'v_rest': -60.5, 'tau_m': 10., 'e_rev_E': 0.0, 'e_rev_I': -75.0, 'v_reset': -60.5, 'v_thresh': -60.0, 'tau_refrac': 10.0, 'tau_syn_E': 2.5, 'tau_syn_I': 2.5 } SYNAPSE_PARAMS = { "weight": 0.5e-4, "delay": 20.0, 'U': 1.0, 'tau_rec': 1.0, 'tau_facil': 1.0 } cell_class = sim.IF_cond_alpha(**SENSORPARAMS) # Define the network structure: 2 neurons (1 sensor and 1 actors) population = sim.Population(size=2, cellclass=cell_class) synapse_type = sim.TsodyksMarkramSynapse(**SYNAPSE_PARAMS) connector = sim.AllToAllConnector() # Connect neurons sim.Projection(presynaptic_population=population[0:1], postsynaptic_population=population[1:2], connector=connector, synapse_type=synapse_type, receptor_type='excitatory') sim.initialize(population, v=population.get('v_rest')) return population
import pyNN.nest as sim parameters = { u'E_L': 0.0, u'I_e': 0.9, # 用这个参数来表示leaky u'V_reset': 0.0, u'V_th': 0.5, u't_ref': .0, } sim.setup(timestep=01.0) nt = sim.native_cell_type('iaf_psc_delta_xxq') n = sim.Population(1, nt(**parameters)) s = sim.Population(1, sim.SpikeSourceArray()) s[0].spike_times = [10, 15, 20, 30, 40] p = sim.Projection(s, n, sim.FromListConnector([(0, 0, 0.00025, 0.01)])) # p1 = sim.Projection(n, n, sim.FromListConnector([(0, 0, 0.00025, 1.0)])) n.record('V_m') n.record('V_m') sim.initialize(n, V_m=0.) sim.run(128.0) vtrace = n.get_data(clear=True).segments[0].filter(name='V_m')[0] print p.get(['weight'], format='array') plt.figure() plt.plot(vtrace.times, vtrace, 'o') plt.ylim([0, 0.6]) plt.show() sim.end()
'a': 0, 'b': 0, 'tau_w': 500, 'delta_T': 0.5 } #Creation of the two cell populations Neurons_RS = sim.Population(size=N_exc, cellclass=neuron_model, cellparams=neuron_parameters_RS_cell) Neurons_FS = sim.Population(size=N_inh, cellclass=neuron_model, cellparams=neuron_parameters_FS_cell) #V value initialization sim.initialize(Neurons_RS, v=-65.0, gsyn_exc=0, gsyn_inh=0) # v:mV, gsyn_exc:nS, gsyn_inh:nS sim.initialize(Neurons_FS, v=-65.0, gsyn_exc=0, gsyn_inh=0) ## RECURRENT CONNECTIONS #The two populations of neurons are randomly connected # (internally and mutually) with a connectivity probability of 5% # exc_exc exc_exc = sim.Projection(Neurons_RS, Neurons_RS, sim.FixedProbabilityConnector( 0.05, allow_self_connections=False), receptor_type='excitatory', synapse_type=sim.StaticSynapse(weight=0.001)) # exc_inh exc_inh = sim.Projection(Neurons_RS,
def create_brain(): """ Initializes PyNN with the neuronal network that has to be simulated """ SENSORPARAMS = {'v_rest': -60.5, 'cm': 0.025, 'tau_m': 10., 'tau_refrac': 10.0, 'tau_syn_E': 2.5, 'tau_syn_I': 2.5, 'e_rev_E': 0.0, 'e_rev_I': -75.0, 'v_thresh': -60.0, 'v_reset': -60.5} GO_ON_PARAMS = {'v_rest': -60.5, 'cm': 0.025, 'tau_m': 10.0, 'e_rev_E': 0.0, 'e_rev_I': -75.0, 'v_reset': -61.6, 'v_thresh': -60.51, 'tau_refrac': 10.0, 'tau_syn_E': 2.5, 'tau_syn_I': 2.5} # POPULATION_PARAMS = SENSORPARAMS * 5 + GO_ON_PARAMS + SENSORPARAMS * 2 population = sim.Population(8, sim.IF_cond_alpha()) population[0:5].set(**SENSORPARAMS) population[5:6].set(**GO_ON_PARAMS) population[6:8].set(**SENSORPARAMS) # Shared Synapse Parameters syn_params = {'U': 1.0, 'tau_rec': 0.0, 'tau_facil': 0.0} # Synaptic weights WEIGHT_RED_TO_ACTOR = 1.5e-4 WEIGHT_RED_TO_GO_ON = 1.2e-3 # or -1.2e-3? WEIGHT_GREEN_BLUE_TO_ACTOR = 1.05e-4 WEIGHT_GO_ON_TO_RIGHT_ACTOR = 1.4e-4 DELAY = 0.1 # Connect neurons CIRCUIT = population SYN = sim.TsodyksMarkramSynapse(weight=abs(WEIGHT_RED_TO_ACTOR), delay=DELAY, **syn_params) sim.Projection(presynaptic_population=CIRCUIT[2:3], postsynaptic_population=CIRCUIT[7:8], connector=sim.AllToAllConnector(), synapse_type=SYN, receptor_type='excitatory') sim.Projection(presynaptic_population=CIRCUIT[3:4], postsynaptic_population=CIRCUIT[6:7], connector=sim.AllToAllConnector(), synapse_type=SYN, receptor_type='excitatory') SYN = sim.TsodyksMarkramSynapse(weight=abs(WEIGHT_RED_TO_GO_ON), delay=DELAY, **syn_params) sim.Projection(presynaptic_population=CIRCUIT[0:2], postsynaptic_population=CIRCUIT[5:6], connector=sim.AllToAllConnector(), synapse_type=SYN, receptor_type='inhibitory') SYN = sim.TsodyksMarkramSynapse(weight=abs(WEIGHT_GREEN_BLUE_TO_ACTOR), delay=DELAY, **syn_params) sim.Projection(presynaptic_population=CIRCUIT[4:5], postsynaptic_population=CIRCUIT[7:8], connector=sim.AllToAllConnector(), synapse_type=SYN, receptor_type='excitatory') SYN = sim.TsodyksMarkramSynapse(weight=abs(WEIGHT_GO_ON_TO_RIGHT_ACTOR), delay=DELAY, **syn_params) sim.Projection(presynaptic_population=CIRCUIT[5:6], postsynaptic_population=CIRCUIT[7:8], connector=sim.AllToAllConnector(), synapse_type=SYN, receptor_type='excitatory') sim.initialize(population, v=population.get('v_rest')) logger.info("Circuit description: " + str(population.describe())) return population
def create_brain(): """ Initializes PyNN with the neuronal network that has to be simulated """ SENSORPARAMS = { 'v_rest': -60.5, 'cm': 0.025, 'tau_m': 10., 'tau_refrac': 10.0, 'tau_syn_E': 2.5, 'tau_syn_I': 2.5, 'e_rev_E': 0.0, 'e_rev_I': -75.0, 'v_thresh': -60.0, 'v_reset': -60.5 } GO_ON_PARAMS = { 'v_rest': -60.5, 'cm': 0.025, 'tau_m': 10.0, 'e_rev_E': 0.0, 'e_rev_I': -75.0, 'v_reset': -61.6, 'v_thresh': -60.51, 'tau_refrac': 10.0, 'tau_syn_E': 2.5, 'tau_syn_I': 2.5 } # POPULATION_PARAMS = SENSORPARAMS * 5 + GO_ON_PARAMS + SENSORPARAMS * 2 population = sim.Population(8, sim.IF_cond_alpha()) population[0:5].set(**SENSORPARAMS) population[5:6].set(**GO_ON_PARAMS) population[6:8].set(**SENSORPARAMS) # Shared Synapse Parameters syn_params = {'U': 1.0, 'tau_rec': 1.0, 'tau_facil': 1.0} # Synaptic weights WEIGHT_RED_TO_ACTOR = 1.5e-4 WEIGHT_RED_TO_GO_ON = 1.2e-3 # or -1.2e-3? WEIGHT_GREEN_BLUE_TO_ACTOR = 1.05e-4 WEIGHT_GO_ON_TO_RIGHT_ACTOR = 1.4e-4 DELAY = 0.1 # Connect neurons CIRCUIT = population SYN = sim.TsodyksMarkramSynapse(weight=abs(WEIGHT_RED_TO_ACTOR), delay=DELAY, **syn_params) sim.Projection(presynaptic_population=CIRCUIT[2:3], postsynaptic_population=CIRCUIT[7:8], connector=sim.AllToAllConnector(), synapse_type=SYN, receptor_type='excitatory') sim.Projection(presynaptic_population=CIRCUIT[3:4], postsynaptic_population=CIRCUIT[6:7], connector=sim.AllToAllConnector(), synapse_type=SYN, receptor_type='excitatory') SYN = sim.TsodyksMarkramSynapse(weight=abs(WEIGHT_RED_TO_GO_ON), delay=DELAY, **syn_params) sim.Projection(presynaptic_population=CIRCUIT[0:2], postsynaptic_population=CIRCUIT[5:6], connector=sim.AllToAllConnector(), synapse_type=SYN, receptor_type='inhibitory') SYN = sim.TsodyksMarkramSynapse(weight=abs(WEIGHT_GREEN_BLUE_TO_ACTOR), delay=DELAY, **syn_params) sim.Projection(presynaptic_population=CIRCUIT[4:5], postsynaptic_population=CIRCUIT[7:8], connector=sim.AllToAllConnector(), synapse_type=SYN, receptor_type='excitatory') SYN = sim.TsodyksMarkramSynapse(weight=abs(WEIGHT_GO_ON_TO_RIGHT_ACTOR), delay=DELAY, **syn_params) sim.Projection(presynaptic_population=CIRCUIT[5:6], postsynaptic_population=CIRCUIT[7:8], connector=sim.AllToAllConnector(), synapse_type=SYN, receptor_type='excitatory') sim.initialize(population, v=population.get('v_rest')) logger.debug("Circuit description: " + str(population.describe())) return population
'a': 0, 'b': 0, 'tau_w': 500, 'delta_T': 0.5 } #Create the two cell populations of 1 neuron Neurons_RS = sim.Population(size=1, cellclass=neuron_model, cellparams=neuron_parameters_RS_cell) Neurons_FS = sim.Population(size=1, cellclass=neuron_model, cellparams=neuron_parameters_FS_cell) #V value initialization sim.initialize(Neurons_RS, v=-65.0) # v:mV sim.initialize(Neurons_FS, v=-65.0) # v:mV #parameters recorded : membrane potential & spikes Neurons_RS.record('v') Neurons_RS.record('spikes') Neurons_FS.record('v') Neurons_FS.record('spikes') #The external input pulse = sim.DCSource( amplitude=0.2, start=100, stop=400) #amplitude=200pA, start=100ms and stop=400ms #representaton of the pulse injected
def create_brain(): """ Initializes PyNN with the neuronal network that has to be simulated """ C_m = 25.0 g_L = 2.5 t_m = C_m / g_L SENSORPARAMS = { 'a': 0.0, 'b': 0.0, 'delta_T': 0.0, 'tau_w': 10.0, 'v_spike': 0.0, 'cm': C_m, 'v_rest': -60.5, 'tau_m': t_m, 'e_rev_E': 0.0, 'e_rev_I': -75.0, 'v_reset': -60.5, 'v_thresh': -60.0, 'tau_refrac': 10.0, 'tau_syn_E': 2.5, 'tau_syn_I': 2.5 } GO_ON_PARAMS = { 'a': 0.0, 'b': 0.0, 'delta_T': 0.0, 'tau_w': 10.0, 'v_spike': 0.0, 'cm': C_m, 'v_rest': -60.5, 'tau_m': t_m, 'e_rev_E': 0.0, 'e_rev_I': -75.0, 'v_reset': -61.6, 'v_thresh': -60.51, 'tau_refrac': 10.0, 'tau_syn_E': 2.5, 'tau_syn_I': 2.5 } # 3 sensor neurons # SENSORS = sim.Population(5, sim.EIF_cond_exp_isfa_ista, cellparams=SENSORPARAMS) # # Go-on-node and 2 actor neurons # GO_ON = sim.Population(1, sim.EIF_cond_exp_isfa_ista, cellparams=GO_ON_PARAMS) # ACTORS = sim.Population(2, sim.EIF_cond_exp_isfa_ista, cellparams=SENSORPARAMS) cells = sim.Population(8, sim.EIF_cond_alpha_isfa_ista) params = {'U': 1.0, 'tau_rec': 0.0, 'tau_facil': 0.0} syndynamics = sim.SynapseDynamics(fast=sim.TsodyksMarkramMechanism( **params)) # sim.initialize(SENSORS, 'v', SENSORS[0].v_rest) # sim.initialize(GO_ON, 'v', SENSORS[0].v_rest) # sim.initialize(ACTORS, 'v', ACTORS[0].v_rest) # CIRCUIT = SENSORS + GO_ON + ACTORS # Assembly of 8 neurons # Synaptic weights WEIGHT_RED_TO_ACTOR = 1.5e-4 WEIGHT_RED_TO_GO_ON = 1.2e-3 # or -1.2e-3? WEIGHT_GREEN_BLUE_TO_ACTOR = 1.05e-4 WEIGHT_GO_ON_TO_RIGHT_ACTOR = 1.4e-4 DELAY = 0.1 # Connect neurons CONN = sim.AllToAllConnector(weights=abs(WEIGHT_RED_TO_ACTOR), delays=DELAY) sim.Projection(cells[2:3], cells[7:8], CONN, synapse_dynamics=syndynamics, target='excitatory') sim.Projection(cells[3:4], cells[6:7], CONN, synapse_dynamics=syndynamics, target='excitatory') CONN = sim.AllToAllConnector(weights=abs(WEIGHT_RED_TO_GO_ON), delays=DELAY) sim.Projection(cells[0:2], cells[5:6], CONN, synapse_dynamics=syndynamics, target='inhibitory') CONN = sim.AllToAllConnector(weights=abs(WEIGHT_GREEN_BLUE_TO_ACTOR), delays=DELAY) sim.Projection(cells[4:5], cells[7:8], CONN, synapse_dynamics=syndynamics, target='excitatory') CONN = sim.AllToAllConnector(weights=abs(WEIGHT_GO_ON_TO_RIGHT_ACTOR), delays=DELAY) sim.Projection(cells[5:6], cells[7:8], CONN, synapse_dynamics=syndynamics, target='excitatory') #connect to color detection neurons formatted_circuit = { "population": cells, "x": np.float64(np.array([0, 1, 2, 3, 4, 5, 6, 7])), "y": np.float64(np.array([0, 1, 2, 3, 4, 5, 6, 7])), "z": np.float64(np.array([0, 1, 2, 3, 4, 5, 6, 7])), "layer": np.int16(np.array([1, 1, 1, 1, 1, 2, 3, 3])), "mtype": np.array(['SC', 'SC', 'SC', 'SC', 'SC', 'GOC', 'AC', 'AC']), "a": np.float64( np.array([SENSORPARAMS.get('a')] * 5 + [GO_ON_PARAMS.get('a')] + [SENSORPARAMS.get('a')] * 2)), "b": np.float64( np.array([SENSORPARAMS.get('b')] * 5 + [GO_ON_PARAMS.get('b')] + [SENSORPARAMS.get('b')] * 2)), "V_th": np.float64( np.array([SENSORPARAMS.get('v_thresh')] * 5 + [GO_ON_PARAMS.get('v_thresh')] + [SENSORPARAMS.get('v_thresh')] * 2)), "Delta_T": np.float64( np.array([SENSORPARAMS.get('delta_T')] * 5 + [GO_ON_PARAMS.get('delta_T')] + [SENSORPARAMS.get('delta_T')] * 2)), "C_m": np.float64( np.array([SENSORPARAMS.get('cm')] * 5 + [GO_ON_PARAMS.get('cm')] + [SENSORPARAMS.get('cm')] * 2)), "g_L": np.float64(np.array([g_L] * 8)), "V_reset": np.float64( np.array([SENSORPARAMS.get('v_reset')] * 5 + [GO_ON_PARAMS.get('v_reset')] + [SENSORPARAMS.get('v_reset')] * 2)), "tau_w": np.float64( np.array([SENSORPARAMS.get('tau_w')] * 5 + [GO_ON_PARAMS.get('tau_w')] + [SENSORPARAMS.get('tau_w')] * 2)), "t_ref": np.float64( np.array([SENSORPARAMS.get('tau_refrac')] * 5 + [GO_ON_PARAMS.get('tau_refrac')] + [SENSORPARAMS.get('tau_refrac')] * 2)), "V_peak": np.float64( np.array([SENSORPARAMS.get('v_spike')] * 5 + [GO_ON_PARAMS.get('v_spike')] + [SENSORPARAMS.get('v_spike')] * 2)), "E_L": np.float64( np.array([SENSORPARAMS.get('v_rest')] * 5 + [GO_ON_PARAMS.get('v_rest')] + [SENSORPARAMS.get('v_rest')] * 2)), "E_ex": np.float64( np.array([SENSORPARAMS.get('e_rev_E')] * 5 + [GO_ON_PARAMS.get('e_rev_E')] + [SENSORPARAMS.get('e_rev_E')] * 2)), "E_in": np.float64( np.array([SENSORPARAMS.get('e_rev_I')] * 5 + [GO_ON_PARAMS.get('e_rev_I')] + [SENSORPARAMS.get('e_rev_I')] * 2)), "tau_syn_E": np.float64( np.array([SENSORPARAMS.get('tau_syn_E')] * 5 + [GO_ON_PARAMS.get('tau_syn_E')] + [SENSORPARAMS.get('tau_syn_E')] * 2)), "tau_syn_I": np.float64( np.array([SENSORPARAMS.get('tau_syn_I')] * 5 + [GO_ON_PARAMS.get('tau_syn_I')] + [SENSORPARAMS.get('tau_syn_I')] * 2)), "excitatory": np.array([90, 90, 110, 110, 110, 110, 110, 110]) } population = formatted_circuit['population'] # AdEx parameters are set population.tset('a', formatted_circuit["a"]) # nS population.tset('b', formatted_circuit["b"] * 1e-3) # pA -> nA population.tset('v_thresh', formatted_circuit["V_th"]) population.tset('delta_T', formatted_circuit["Delta_T"]) population.tset('cm', formatted_circuit["C_m"] * 1e-3) # pF->nF population.tset('tau_m', formatted_circuit["C_m"] / formatted_circuit["g_L"]) population.tset('v_reset', formatted_circuit["V_reset"]) population.tset('tau_w', formatted_circuit["tau_w"]) population.tset('tau_refrac', formatted_circuit["t_ref"]) population.tset('v_spike', formatted_circuit["V_peak"]) population.tset('v_rest', formatted_circuit["E_L"]) population.tset('e_rev_E', formatted_circuit["E_ex"]) population.tset('e_rev_I', formatted_circuit["E_in"]) population.tset('tau_syn_E', formatted_circuit["tau_syn_E"]) population.tset('tau_syn_I', formatted_circuit["tau_syn_I"]) sim.initialize(population, 'v', population.get('v_rest')) logger.debug("Circuit description: " + str(population.describe())) return population