def build_network(stdp_model): # SpiNNaker setup sim.setup(timestep=1.0, min_delay=1.0, max_delay=10.0) # Reduce number of neurons to simulate on each core sim.set_number_of_neurons_per_core(sim.IF_curr_exp, 10) # Create excitatory and inhibitory populations of neurons ex_pop = sim.Population(NUM_EXCITATORY, model(**cell_params)) in_pop = sim.Population(NUM_EXCITATORY / 4, model(**cell_params)) # Record excitatory spikes ex_pop.record(['spikes']) # Make excitatory->inhibitory projections sim.Projection(ex_pop, in_pop, sim.FixedProbabilityConnector(0.02), receptor_type='excitatory', synapse_type=sim.StaticSynapse(weight=0.03)) sim.Projection(ex_pop, ex_pop, sim.FixedProbabilityConnector(0.02), receptor_type='excitatory', synapse_type=sim.StaticSynapse(weight=0.03)) # Make inhibitory->inhibitory projections sim.Projection(in_pop, in_pop, sim.FixedProbabilityConnector(0.02), receptor_type='inhibitory', synapse_type=sim.StaticSynapse(weight=-0.3)) # Make inhibitory->excitatory projections ie_projection = sim.Projection(in_pop, ex_pop, sim.FixedProbabilityConnector(0.02), receptor_type='inhibitory', synapse_type=stdp_model) return ex_pop, ie_projection
def fixedprob_population_views(self): sim.setup(timestep=1.0) in_pop = sim.Population(4, sim.SpikeSourceArray([0]), label="in_pop") pop = sim.Population(4, sim.IF_curr_exp(), label="pop") rng = NumpyRNG(seed=1) conn = sim.Projection(in_pop[1:3], pop[2:4], sim.FixedProbabilityConnector(0.5, rng=rng), sim.StaticSynapse(weight=0.5, delay=2)) sim.run(1) weights = conn.get(['weight', 'delay'], 'list') sim.end() # The fixed seed means this gives the same answer each time target = [[1, 3, 0.5, 2.], [2, 2, 0.5, 2.], [2, 3, 0.5, 2]] self.assertCountEqual(weights, target)
def do_run(seed=None): random.seed(seed) # SpiNNaker setup sim.setup(timestep=1.0, min_delay=1.0, max_delay=10.0) # +-------------------------------------------------------------------+ # | General Parameters | # +-------------------------------------------------------------------+ # Population parameters model = sim.IF_curr_exp cell_params = { 'cm': 0.25, 'i_offset': 0.0, 'tau_m': 10.0, 'tau_refrac': 2.0, 'tau_syn_E': 2.5, 'tau_syn_I': 2.5, 'v_reset': -70.0, 'v_rest': -65.0, 'v_thresh': -55.4 } # Other simulation parameters e_rate = 200 in_rate = 350 n_stim_test = 5 n_stim_pairing = 10 dur_stim = 20 pop_size = 40 ISI = 150. start_test_pre_pairing = 200. start_pairing = 1500. start_test_post_pairing = 700. simtime = start_pairing + start_test_post_pairing + \ ISI*(n_stim_pairing + n_stim_test) + 550. # let's make it 5000 # Initialisations of the different types of populations IAddPre = [] IAddPost = [] # +-------------------------------------------------------------------+ # | Creation of neuron populations | # +-------------------------------------------------------------------+ # Neuron populations pre_pop = sim.Population(pop_size, model(**cell_params)) post_pop = sim.Population(pop_size, model(**cell_params)) # Test of the effect of activity of the pre_pop population on the post_pop # population prior to the "pairing" protocol : only pre_pop is stimulated for i in range(n_stim_test): IAddPre.append( sim.Population( pop_size, sim.SpikeSourcePoisson(rate=in_rate, start=start_test_pre_pairing + ISI * (i), duration=dur_stim, seed=random.randint(0, 100000000)))) # Pairing protocol : pre_pop and post_pop are stimulated with a 10 ms # difference for i in range(n_stim_pairing): IAddPre.append( sim.Population( pop_size, sim.SpikeSourcePoisson(rate=in_rate, start=start_pairing + ISI * (i), duration=dur_stim, seed=random.randint(0, 100000000)))) IAddPost.append( sim.Population( pop_size, sim.SpikeSourcePoisson(rate=in_rate, start=start_pairing + ISI * (i) + 10., duration=dur_stim, seed=random.randint(0, 100000000)))) # Test post pairing : only pre_pop is stimulated # (and should trigger activity in Post) for i in range(n_stim_test): start = start_pairing + ISI * n_stim_pairing + \ start_test_post_pairing + ISI * i IAddPre.append( sim.Population( pop_size, sim.SpikeSourcePoisson(rate=in_rate, start=start, duration=dur_stim, seed=random.randint(0, 100000000)))) # Noise inputs INoisePre = sim.Population(pop_size, sim.SpikeSourcePoisson(rate=e_rate, start=0, duration=simtime, seed=random.randint( 0, 100000000)), label="expoisson") INoisePost = sim.Population(pop_size, sim.SpikeSourcePoisson(rate=e_rate, start=0, duration=simtime, seed=random.randint( 0, 100000000)), label="expoisson") # +-------------------------------------------------------------------+ # | Creation of connections | # +-------------------------------------------------------------------+ # Connection parameters JEE = 3. # Connection type between noise poisson generator and # excitatory populations ee_connector = sim.OneToOneConnector() # Noise projections sim.Projection(INoisePre, pre_pop, ee_connector, receptor_type='excitatory', synapse_type=sim.StaticSynapse(weight=JEE * 0.05)) sim.Projection(INoisePost, post_pop, ee_connector, receptor_type='excitatory', synapse_type=sim.StaticSynapse(weight=JEE * 0.05)) # Additional Inputs projections for i in range(len(IAddPre)): sim.Projection(IAddPre[i], pre_pop, ee_connector, receptor_type='excitatory', synapse_type=sim.StaticSynapse(weight=JEE * 0.05)) for i in range(len(IAddPost)): sim.Projection(IAddPost[i], post_pop, ee_connector, receptor_type='excitatory', synapse_type=sim.StaticSynapse(weight=JEE * 0.05)) # Plastic Connections between pre_pop and post_pop stdp_model = sim.STDPMechanism( timing_dependence=sim.SpikePairRule(tau_plus=20., tau_minus=50.0, A_plus=0.02, A_minus=0.02), weight_dependence=sim.AdditiveWeightDependence(w_min=0, w_max=0.9)) rng = NumpyRNG(seed=seed, parallel_safe=True) plastic_projection = \ sim.Projection(pre_pop, post_pop, sim.FixedProbabilityConnector( p_connect=0.5, rng=rng), synapse_type=stdp_model) # +-------------------------------------------------------------------+ # | Simulation and results | # +-------------------------------------------------------------------+ # Record spikes and neurons' potentials pre_pop.record(['v', 'spikes']) post_pop.record(['v', 'spikes']) # Run simulation sim.run(simtime) weights = plastic_projection.get('weight', 'list') pre_spikes = neo_convertor.convert_spikes(pre_pop.get_data('spikes')) post_spikes = neo_convertor.convert_spikes(post_pop.get_data('spikes')) # End simulation on SpiNNaker sim.end() return (pre_spikes, post_spikes, weights)
pynn.IF_curr_exp(**exc_cell_params), label="E_pop") I_pop = pynn.Population(N_I, pynn.IF_curr_exp(**inh_cell_params), label="I_pop") Poiss_ext_E = pynn.Population(N_E, pynn.SpikeSourcePoisson(rate=10.0), label="Poisson_pop_E") Poiss_ext_I = pynn.Population(N_I, pynn.SpikeSourcePoisson(rate=10.0), label="Poisson_pop_I") # Connectors E_conn = pynn.FixedProbabilityConnector(epsilon) I_conn = pynn.FixedProbabilityConnector(epsilon) # Use random delays for the external noise and # set the inital membrance voltage below the resting potential # to avoid the overshoot of activity in the beginning of the simulation rng = NumpyRNG(seed=1) delay_distr = RandomDistribution('uniform', low=1.0, high=16.0, rng=rng) Ext_conn = pynn.OneToOneConnector() uniformDistr = RandomDistribution('uniform', low=-10, high=0, rng=rng) E_pop.initialize(v=uniformDistr) I_pop.initialize(v=uniformDistr) # Projections E_E = pynn.Projection(E_pop,
def do_run(seed=None): simulator_name = 'spiNNaker' timer = Timer() # === Define parameters ========================================= parallel_safe = True n = 1500 # number of cells # number of excitatory cells:number of inhibitory cells r_ei = 4.0 pconn = 0.02 # connection probability dt = 1 # (ms) simulation timestep tstop = 200 # (ms) simulaton duration delay = 1 # Cell parameters area = 20000. # (µm²) tau_m = 20. # (ms) cm = 1. # (µF/cm²) g_leak = 5e-5 # (S/cm²) e_leak = -49. # (mV) v_thresh = -50. # (mV) v_reset = -60. # (mV) t_refrac = 5. # (ms) (clamped at v_reset) # (mV) 'mean' membrane potential, for calculating CUBA weights v_mean = -60. tau_exc = 5. # (ms) tau_inh = 10. # (ms) # (nS) #Those weights should be similar to the COBA weights g_exc = 0.27 # (nS) # but the delpolarising drift should be taken into account g_inh = 4.5 e_rev_exc = 0. # (mV) e_rev_inh = -80. # (mV) # === Calculate derived parameters =============================== area *= 1e-8 # convert to cm² cm *= area * 1000 # convert to nF r_m = 1e-6 / (g_leak * area) # membrane resistance in MΩ assert tau_m == cm * r_m # just to check # number of excitatory cells n_exc = int(round((n * r_ei / (1 + r_ei)))) n_inh = n - n_exc # number of inhibitory cells celltype = p.IF_curr_exp # (nA) weight of excitatory synapses w_exc = 1e-3 * g_exc * (e_rev_exc - v_mean) w_inh = 1e-3 * g_inh * (e_rev_inh - v_mean) # (nA) assert w_exc > 0 assert w_inh < 0 # === Build the network ========================================== p.setup(timestep=dt, min_delay=delay, max_delay=delay) if simulator_name == 'spiNNaker': # this will set 100 neurons per core p.set_number_of_neurons_per_core(p.IF_curr_exp, 100) # this will set 50 neurons per core p.set_number_of_neurons_per_core(p.IF_cond_exp, 50) # node_id = 1 # np = 1 # host_name = socket.gethostname() cell_params = {'tau_m': tau_m, 'tau_syn_E': tau_exc, 'tau_syn_I': tau_inh, 'v_rest': e_leak, 'v_reset': v_reset, 'v_thresh': v_thresh, 'cm': cm, 'tau_refrac': t_refrac, 'i_offset': 0} timer.start() exc_cells = p.Population(n_exc, celltype, cell_params, label="Excitatory_Cells") inh_cells = p.Population(n_inh, celltype, cell_params, label="Inhibitory_Cells") rng = NumpyRNG(seed=seed, parallel_safe=parallel_safe) uniform_distr = RandomDistribution('uniform', [v_reset, v_thresh], rng=rng) exc_cells.initialize(v=uniform_distr) inh_cells.initialize(v=uniform_distr) exc_conn = p.FixedProbabilityConnector(pconn, rng=rng) synapse_exc = p.StaticSynapse(weight=w_exc, delay=delay) inh_conn = p.FixedProbabilityConnector(pconn, rng=rng) synapse_inh = p.StaticSynapse(weight=w_inh, delay=delay) connections = dict() connections['e2e'] = p.Projection(exc_cells, exc_cells, exc_conn, synapse_type=synapse_exc, receptor_type='excitatory') connections['e2i'] = p.Projection(exc_cells, inh_cells, exc_conn, synapse_type=synapse_exc, receptor_type='excitatory') connections['i2e'] = p.Projection(inh_cells, exc_cells, inh_conn, synapse_type=synapse_inh, receptor_type='inhibitory') connections['i2i'] = p.Projection(inh_cells, inh_cells, inh_conn, synapse_type=synapse_inh, receptor_type='inhibitory') # === Setup recording ============================== exc_cells.record("spikes") # === Run simulation ================================ p.run(tstop) exc_spikes = exc_cells.get_data("spikes") exc_cells.write_data(neo_path, "spikes") p.end() return exc_spikes
def spinn_net(): np.random.seed(272727) global output_labels global input_labels p.setup(timestep=1.0, min_delay=1, max_delay=60) p.set_number_of_neurons_per_core(p.IF_cond_exp, 64) n_pop_labels = [] n_pop_list = [] n_proj_list = [] spike_source_list = [] if offset != 0: for i in range(2): del output_labels[0] for i in range(2): del input_labels[0] for i in range(no_neuron_pops): #set up the input as a live spike source if i < 2: n_pop_labels.append("Input_pop{}".format(i)) input_labels.append("Input_pop{}".format(i)) n_pop_list.append( p.Population(pop_sizes[i], p.SpikeSourcePoisson(rate=poisson_rate), label=n_pop_labels[i])) n_pop_list[i].record(["spikes"]) p.external_devices.add_poisson_live_rate_control( n_pop_list[i], database_notify_port_num=(160+offset)) #set up output pop elif i < 4: n_pop_labels.append("Output_pop{}".format(i)) output_labels.append("Output_pop{}".format(i)) n_pop_list.append(p.Population(pop_sizes[i], p.IF_cond_exp(), label=n_pop_labels[i])) p.external_devices.activate_live_output_for( n_pop_list[i], database_notify_port_num=(180+offset), port=(17000+offset)) spike_source_list.append(p.Population(pop_sizes[i], p.SpikeSourcePoisson(rate=0.0), label="source ".format(n_pop_labels[i]))) n_pop_list[i].record(["spikes", "v"]) #set up all other populations else: n_pop_labels.append("neuron{}".format(i)) n_pop_list.append(p.Population(pop_sizes[i], p.IF_cond_exp(), label=n_pop_labels[i])) spike_source_list.append(p.Population(pop_sizes[i], p.SpikeSourcePoisson(rate=0.0), label="source ".format(n_pop_labels[i]))) n_pop_list[i].record(["spikes", "v"]) poisson_control = p.external_devices.SpynnakerPoissonControlConnection( poisson_labels=input_labels, local_port=(160+offset)) poisson_control.add_start_callback(n_pop_list[0].label, from_list_poisson) # poisson_control.add_start_callback(n_pop_list[1].label, poisson_setting) # poisson_control.add_start_callback(n_pop_list[0].label, poisson_threading) live_connection = p.external_devices.SpynnakerLiveSpikesConnection( receive_labels=output_labels, local_port=(180+offset)) live_connection.add_receive_callback(n_pop_labels[2], receive_spikes) live_connection.add_receive_callback(n_pop_labels[3], receive_spikes) # weight_mu = 0.015 # weight_sdtev = 0.05 # delay_mu = 40 # delay_sdtev = 5 for i in range(no_neuron_pops): np.random.seed(272727) weights = RandomDistribution("normal_clipped", mu=weight_mu[i], sigma=weight_stdev[i], low=0, high=np.inf) delays = RandomDistribution("normal_clipped", mu=delay_mu[i], sigma=delay_stdev[i], low=1, high=55) synapse = p.StaticSynapse(weight=weights, delay=delays) for j in range(2, no_neuron_pops): print "\npop = {}({}) connecting to {}".format(i,pop_sizes[i],j) if connect_prob_ex[i][j-2] > 1e-10: print "ex = {}\tin = {}".format(connect_prob_ex[i][j-2], connect_prob_in[i][j-2]) print "\tweight mu = {}\t stdev = {}".format(weight_mu[i], weight_stdev[i]) print "\tdelay mu = {}\t stdev = {}".format(delay_mu[i], delay_stdev[i]) n_proj_list.append( p.Projection(n_pop_list[i], n_pop_list[j], p.FixedProbabilityConnector(connect_prob_ex[i][j-2]),#p.OneToOneConnector(),# synapse, receptor_type="excitatory")) n_proj_list.append( p.Projection(n_pop_list[i], n_pop_list[j], p.FixedProbabilityConnector(connect_prob_in[i][j-2]),#p.OneToOneConnector(),# synapse, receptor_type="inhibitory")) # n_proj_list.append(p.Projection(n_pop_list[i], n_pop_list[j], # p.FixedProbabilityConnector(1), # synapse, receptor_type="inhibitory")) run = 0 p.run(duration/timeScaleFactor) print "finished 1st" run = 1 p.reset() p.run(duration/timeScaleFactor) total_v = list() spikes = list() v = list() spikes.append(n_pop_list[0].get_data("spikes")) spikes.append(n_pop_list[1].get_data("spikes")) for j in range(2,no_neuron_pops): spikes.append(n_pop_list[j].get_data("spikes")) v.append(n_pop_list[j].get_data("v")) Figure( # raster plot of the presynaptic neuron spike times Panel(spikes[0].segments[0].spiketrains, yticks=True, markersize=2, xlim=(0, duration)), Panel(spikes[1].segments[0].spiketrains, yticks=True, markersize=2, xlim=(0, duration)), Panel(spikes[2].segments[0].spiketrains, yticks=True, markersize=2, xlim=(0, duration)), Panel(spikes[3].segments[0].spiketrains, yticks=True, markersize=2, xlim=(0, duration)), # Panel(spikes[4].segments[0].spiketrains, # yticks=True, markersize=2, xlim=(0, duration)), # Panel(spikes[no_neuron_pops-2].segments[0].spiketrains, # yticks=True, markersize=2, xlim=(0, duration)), # Panel(spikes[no_neuron_pops-1].segments[0].spiketrains, # yticks=True, markersize=2, xlim=(0, duration)), title="Raster plot", annotations="Simulated with {}".format(p.name()) ) plt.show() Figure( #membrane voltage plots Panel(v[0].segments[0].filter(name='v')[0], ylabel="Membrane potential (mV)", yticks=True, xlim=(0, duration)), Panel(v[1].segments[0].filter(name='v')[0], ylabel="Membrane potential (mV)", yticks=True, xlim=(0, duration)), Panel(v[2].segments[0].filter(name='v')[0], ylabel="Membrane potential (mV)", yticks=True, xlim=(0, duration)), Panel(v[3].segments[0].filter(name='v')[0], ylabel="Membrane potential (mV)", yticks=True, xlim=(0, duration)), # Panel(v[4].segments[0].filter(name='v')[0], # ylabel="Membrane potential (mV)", yticks=True, xlim=(0, duration)), # Panel(v[no_neuron_pops-4].segments[0].filter(name='v')[0], # ylabel="Membrane potential (mV)", yticks=True, xlim=(0, duration)), # Panel(v[no_neuron_pops-3].segments[0].filter(name='v')[0], # ylabel="Membrane potential (mV)", yticks=True, xlim=(0, duration)), title="Membrane voltage plot", ) plt.show() # p.reset() p.end() poisson_control.close() live_connection.close() print "finished run"
pop_input = p.Population(100, p.SpikeSourcePoisson(rate=0), label="Input") pop_exc = p.Population(n_exc, p.IF_curr_exp, label="Excitatory", additional_parameters={"spikes_per_second": 100}) pop_inh = p.Population(n_inh, p.IF_curr_exp, label="Inhibitory", additional_parameters={"spikes_per_second": 100}) stim_exc = p.Population( n_exc, p.SpikeSourcePoisson(rate=1000.0), label="Stim_Exc") stim_inh = p.Population( n_inh, p.SpikeSourcePoisson(rate=1000.0), label="Stim_Inh") delays_exc = RandomDistribution( "normal_clipped", mu=1.5, sigma=0.75, low=1.0, high=14.4) weights_exc = RandomDistribution( "normal_clipped", mu=weight_exc, sigma=0.1, low=0, high=numpy.inf) conn_exc = p.FixedProbabilityConnector(0.1) synapse_exc = p.StaticSynapse(weight=weights_exc, delay=delays_exc) delays_inh = RandomDistribution( "normal_clipped", mu=0.75, sigma=0.375, low=1.0, high=14.4) weights_inh = RandomDistribution( "normal_clipped", mu=weight_inh, sigma=0.1, low=-numpy.inf, high=0) conn_inh = p.FixedProbabilityConnector(0.1) synapse_inh = p.StaticSynapse(weight=weights_inh, delay=delays_inh) p.Projection( pop_exc, pop_exc, conn_exc, synapse_exc, receptor_type="excitatory") p.Projection( pop_exc, pop_inh, conn_exc, synapse_exc, receptor_type="excitatory") p.Projection( pop_inh, pop_inh, conn_inh, synapse_inh, receptor_type="inhibitory") p.Projection( pop_inh, pop_exc, conn_inh, synapse_inh, receptor_type="inhibitory")
spike_source_Poisson_base2 = p.Population( 2, p.SpikeSourcePoisson, { 'rate': Rate_Poisson_Inp_base, 'duration': Duration_Poisson_Inp_base, 'start': start_Poisson_Inp_base }, label='spike_source_Poisson_base2') ######projections for CHANEL 1 for count1 in range(0, 4): if count1 < 3: p.Projection(spike_source_Poisson_base1, poplist_ch1[count1], p.FixedProbabilityConnector(p_connect=pconn_cort2str, weights=g_pop[count1], delays=distr_pop[count1]), target='excitatory') else: p.Projection(spike_source_Poisson_base2, poplist_ch1[count1], p.FixedProbabilityConnector(p_connect=pconn_cort2stn, weights=g_pop[count1], delays=distr_pop[count1]), target='excitatory') ######projections for CHANEL 2 for count2 in range(0, 4): if count2 < 3: p.Projection(spike_source_Poisson_base1, poplist_ch2[count2],
def do_run(Neurons, sim_time, record, seed=None): """ :param Neurons: Number of Neurons :type Neurons: int :param sim_time: times for run :type sim_time: int :param record: If True will aks for spikes to be recorded :type record: bool """ g = 5.0 eta = 2.0 delay = 2.0 epsilon = 0.1 tau_m = 20.0 # ms (20ms will give a FR of 20hz) tau_ref = 2.0 v_reset = 10.0 v_th = 20.0 v_rest = 0.0 tau_syn = 1.0 n_e = int(round(Neurons * 0.8)) n_i = int(round(Neurons * 0.2)) c_e = n_e * 0.1 # Excitatory and inhibitory weights j_e = 0.1 j_i = -g * j_e # The firing rate of a neuron in the external pop # is the product of eta time the threshold rate # the steady state firing rate which is # needed to bring a neuron to threshold. nu_ex = eta * v_th / (j_e * c_e * tau_m) # population rate of the whole external population. # With CE neurons the pop rate is simply the product # nu_ex*c_e the factor 1000.0 changes the units from # spikes per ms to spikes per second. p_rate = 1000.0 * nu_ex * c_e print("Rate is: %f HZ" % (p_rate / 1000)) # Neural Parameters pynn.setup(timestep=1.0, min_delay=1.0, max_delay=16.0) # Makes it easy to scale up the number of cores pynn.set_number_of_neurons_per_core(pynn.IF_curr_exp, 100) pynn.set_number_of_neurons_per_core(pynn.SpikeSourcePoisson, 100) exc_cell_params = { 'cm': 1.0, # pf 'tau_m': tau_m, 'tau_refrac': tau_ref, 'v_rest': v_rest, 'v_reset': v_reset, 'v_thresh': v_th, 'tau_syn_E': tau_syn, 'tau_syn_I': tau_syn, 'i_offset': 0.9 } inh_cell_params = { 'cm': 1.0, # pf 'tau_m': tau_m, 'tau_refrac': tau_ref, 'v_rest': v_rest, 'v_reset': v_reset, 'v_thresh': v_th, 'tau_syn_E': tau_syn, 'tau_syn_I': tau_syn, 'i_offset': 0.9 } # Set-up pynn Populations e_pop = pynn.Population(n_e, pynn.IF_curr_exp(**exc_cell_params), label="e_pop") i_pop = pynn.Population(n_i, pynn.IF_curr_exp, inh_cell_params, label="i_pop") if seed is None: poisson_ext_e = pynn.Population( n_e, pynn.SpikeSourcePoisson(rate=10.0), label="Poisson_pop_E") poisson_ext_i = pynn.Population( n_i, pynn.SpikeSourcePoisson(rate=10.0), label="Poisson_pop_I") else: poisson_ext_e = pynn.Population( n_e, pynn.SpikeSourcePoisson(rate=10.0), label="Poisson_pop_E", additional_parameters={"seed": seed}) poisson_ext_i = pynn.Population( n_i, pynn.SpikeSourcePoisson(rate=10.0), label="Poisson_pop_I", additional_parameters={"seed": seed+1}) # Connectors e_conn = pynn.FixedProbabilityConnector(epsilon) i_conn = pynn.FixedProbabilityConnector(epsilon) # Use random delays for the external noise and # set the initial membrane voltage below the resting potential # to avoid the overshoot of activity in the beginning of the simulation rng = NumpyRNG(seed=seed) delay_distr = RandomDistribution('uniform', [1.0, 16.0], rng=rng) ext_conn = pynn.OneToOneConnector() uniform_distr = RandomDistribution('uniform', [-10, 0], rng=rng) e_pop.initialize(v=uniform_distr) i_pop.initialize(v=uniform_distr) # Projections pynn.Projection( presynaptic_population=e_pop, postsynaptic_population=e_pop, connector=e_conn, receptor_type="excitatory", synapse_type=pynn.StaticSynapse(weight=j_e, delay=delay_distr)) pynn.Projection( presynaptic_population=i_pop, postsynaptic_population=e_pop, connector=i_conn, receptor_type="inhibitory", synapse_type=pynn.StaticSynapse(weight=j_i, delay=delay)) pynn.Projection( presynaptic_population=e_pop, postsynaptic_population=i_pop, connector=e_conn, receptor_type="excitatory", synapse_type=pynn.StaticSynapse(weight=j_e, delay=delay_distr)) pynn.Projection( presynaptic_population=i_pop, postsynaptic_population=i_pop, connector=i_conn, receptor_type="inhibitory", synapse_type=pynn.StaticSynapse(weight=j_i, delay=delay)) pynn.Projection( presynaptic_population=poisson_ext_e, postsynaptic_population=e_pop, connector=ext_conn, receptor_type="excitatory", synapse_type=pynn.StaticSynapse(weight=j_e * 10, delay=delay_distr)) pynn.Projection( presynaptic_population=poisson_ext_i, postsynaptic_population=i_pop, connector=ext_conn, receptor_type="excitatory", synapse_type=pynn.StaticSynapse(weight=j_e * 10, delay=delay_distr)) # Record stuff if record: e_pop.record('spikes') poisson_ext_e.record('spikes') pynn.run(sim_time) esp = None s = None if record: esp = e_pop.get_data('spikes') s = poisson_ext_e.get_data('spikes') pynn.end() return esp, s, n_e
label_time_offset, base_offsets.size) spike_times_for_current_class = repeated_bases + \ repeated_time_offsets label_spikes.append(spike_times_for_current_class) label_pop = sim.Population( classes.size, sim.SpikeSourceArray, {'spike_times': label_spikes}, label="Label population") if args.min_supervised: # Sample from target_pop with initial weight of w_min target_readout_projection = sim.Projection( target_pop, readout_pop, sim.FixedProbabilityConnector( p_connect=p_connect, weights=w_min), synapse_type=structure_model_w_stdp if args.rewiring else stdp_model, label="min_readout_sampling", receptor_type="excitatory") # Supervision provided by an extra Spike Source Array # with high connection weight label_projection = sim.Projection( label_pop, readout_pop, sim.OneToOneConnector(weights=4 * w_max), label="min_label_projection", receptor_type="excitatory") elif args.max_supervised: # Sample from target_pop with initial weight of w_max target_readout_projection = sim.Projection(
def run_delayed_split(): sim.setup(0.1, time_scale_factor=1) source = sim.Population(10, sim.SpikeSourceArray(spike_times=[0])) target_1 = sim.Population( 10, sim.IF_curr_exp(), label="target_1", additional_parameters={ "splitter": SplitterAbstractPopulationVertexNeuronsSynapses(1) }) target_1.record("spikes") target_2 = sim.Population( 10, sim.IF_curr_exp(), label="target_2", additional_parameters={ "splitter": SplitterAbstractPopulationVertexNeuronsSynapses(2) }) target_2.record("spikes") target_3 = sim.Population( 10, sim.IF_curr_exp(), label="target_3", additional_parameters={ "splitter": SplitterAbstractPopulationVertexNeuronsSynapses(3) }) target_3.record("spikes") target_4 = sim.Population( 10, sim.IF_curr_exp(), label="target_4", additional_parameters={ "splitter": SplitterAbstractPopulationVertexNeuronsSynapses(3) }) target_4.record("spikes") # Try from list, which means host generated from_list = sim.Projection( source, target_1, sim.FromListConnector([(a, a, 5, 0.1 + (a * 10)) for a in range(10)])) # Also try a couple of machine generated options fixed_prob = sim.Projection(source, target_2, sim.FixedProbabilityConnector(0.1), sim.StaticSynapse(weight=5.0, delay=34.0)) # Use power-of-two to check border case fixed_total = sim.Projection(source, target_3, sim.FixedTotalNumberConnector(10), sim.StaticSynapse(weight=5.0, delay=2.0)) # Try from list with power-of-two delay to check border case from_list_border = sim.Projection( source, target_4, sim.FromListConnector([(a, a, 5, 4.0) for a in range(10)])) sim.run(100) from_list_delays = list(from_list.get("delay", "list", with_address=False)) fixed_prob_delays = list( fixed_prob.get("delay", "list", with_address=False)) fixed_total_delays = list( fixed_total.get("delay", "list", with_address=False)) from_list_border_delays = list( from_list_border.get("delay", "list", with_address=False)) from_list_spikes = [ s.magnitude for s in target_1.get_data("spikes").segments[0].spiketrains ] from_list_border_spikes = [ s.magnitude for s in target_4.get_data("spikes").segments[0].spiketrains ] sim.end() print(from_list_delays) print(from_list_spikes) print(fixed_prob_delays) print(fixed_total_delays) print(from_list_border_delays) print(from_list_border_spikes) # Check the delays worked out assert (numpy.array_equal(from_list_delays, [0.1 + (a * 10) for a in range(10)])) assert (all(d == 34.0 for d in fixed_prob_delays)) assert (all(d == 2.0 for d in fixed_total_delays)) assert (all(d == 4.0 for d in from_list_border_delays)) for d, s in zip(from_list_delays, from_list_spikes): assert (s > d) for s in from_list_border_spikes: assert (s > 4.0)
def do_run(plot): p.setup(timestep=1.0) cell_params_lif = {'cm': 0.25, 'i_offset': 0.0, 'tau_m': 20.0, 'tau_refrac': 2.0, 'tau_syn_E': 5.0, 'tau_syn_I': 5.0, 'v_reset': -70.0, 'v_rest': -65.0, 'v_thresh': -40.0 } def create_grid(n, label, dx=1.0, dy=1.0): grid_structure = p.Grid2D(dx=dx, dy=dy, x0=0.0, y0=0.0) return p.Population(n*n, p.IF_curr_exp(**cell_params_lif), structure=grid_structure, label=label) n = 4 weight_to_spike = 5.0 delay = 5 runtime = 200 # Network grid = create_grid(n, 'grid') # SpikeInjector injectionConnection = [(0, 0)] spikeArray = {'spike_times': [[0]]} inj_pop = p.Population(1, p.SpikeSourceArray(**spikeArray), label='inputSpikes_1') p.Projection(inj_pop, grid, p.FromListConnector(injectionConnection), p.StaticSynapse(weight=weight_to_spike, delay=delay)) # Connectors exc_connector = p.AllToAllConnector() inh_connector = p.FixedProbabilityConnector(0.5, rng=NumpyRNG(seed=10101)) # Wire grid exc_proj = p.Projection(grid, grid, exc_connector, p.StaticSynapse( weight="1.0 + (2.0*exp(-d))", delay=5)) inh_proj = p.Projection(grid, grid, inh_connector, p.StaticSynapse( weight=1.5, delay="2 + 2.0*d")) grid.record(['v', 'spikes']) p.run(runtime) v = grid.get_data('v') spikes = grid.get_data('spikes') exc_weights_delays = exc_proj.get(['weight', 'delay'], 'list') inh_weights_delays = inh_proj.get(['weight', 'delay'], 'list') if plot: Figure( # raster plot of the presynaptic neurons' spike times Panel(spikes.segments[0].spiketrains, yticks=True, markersize=0.2, xlim=(0, runtime), xticks=True), # membrane potential of the postsynaptic neurons Panel(v.segments[0].filter(name='v')[0], ylabel="Membrane potential (mV)", data_labels=[grid.label], yticks=True, xlim=(0, runtime), xticks=True), title="Simple 2D grid distance-dependent weights and delays", annotations="Simulated with {}".format(p.name()) ) plt.show() p.end() return exc_weights_delays, inh_weights_delays
# Neuronal populations pop_exc = sim.Population(500, sim.IF_curr_exp(**cell_params_exc), label='excitatory_pop') pop_inh = sim.Population(125, sim.IF_curr_exp(**cell_params_inh), label='inhibitory_pop') # Initialise cell membrane potential to some sub-threshold level pop_exc.set(v=sim.RandomDistribution('uniform', [v_reset, v_thresh], rng=rng)) # Spike input projections spike_source_projection = sim.Projection( spike_source_array, pop_exc, sim.FixedProbabilityConnector(p_connect=.1), synapse_type=sim.StaticSynapse(weight=0.06, delay=delay_distribution), receptor_type='excitatory') # Poisson source projections poisson_projection_exc = sim.Projection( poisson_spike_source, pop_exc, sim.FixedProbabilityConnector(p_connect=.1), synapse_type=sim.StaticSynapse(weight=0.06, delay=delay_distribution), receptor_type='excitatory') poisson_projection_inh = sim.Projection( poisson_spike_source, pop_inh, sim.FixedProbabilityConnector(p_connect=.1), synapse_type=sim.StaticSynapse(weight=0.03, delay=delay_distribution),
label='spike_source_Poisson_base1') spike_source_Poisson_base2 = p.Population( 2, p.SpikeSourcePoisson, { 'rate': Rate_Poisson_Inp_base, 'duration': Duration_Poisson_Inp_base, 'start': start_Poisson_Inp_base }, label='spike_source_Poisson_base2') ######projections for CHANEL 1 for count1 in range(0, 4): if count1 < 3: p.Projection(spike_source_Poisson_base1, poplist_ch1[count1], p.FixedProbabilityConnector(p_connect=pconn_cort2str), p.StaticSynapse(weight=g_pop[count1], delay=distr_pop[count1]), receptor_type='excitatory') else: p.Projection(spike_source_Poisson_base2, poplist_ch1[count1], p.FixedProbabilityConnector(p_connect=pconn_cort2stn), p.StaticSynapse(weight=g_pop[count1], delay=distr_pop[count1]), receptor_type='excitatory') ######projections for CHANEL 2 for count2 in range(0, 4): if count2 < 3: p.Projection(spike_source_Poisson_base1,
def __connect(self): """ Based on Buonomano & Merzenich 1997 (Fig 3, p135) +----------------------+------------------+-----------------+------------------+-----------------+ | Populations | excitatory (III) | excitatory (IV) | inhibitory (III) | inhibitory (IV) | +======================+==================+=================+==================+=================+ | **excitatory (III)** | 18/200 = 0.09 | - | 12/200 = 0.06 | - | +----------------------+------------------+-----------------+------------------+-----------------+ | **excitatory (IV)** | 18/120 = 0.15 | 15/120 = 0.125 | 12/120 = 0.1 | 10/120 = 0.083 | +----------------------+------------------+-----------------+------------------+-----------------+ | **inhibitory (III)** | 8/50 = 0.16 | - | 6/50 = 0.12 | - | +----------------------+------------------+-----------------+------------------+-----------------+ | **inhibitory (IV)** | - | 6/30 = 0.2 | - | 4/30 = 0.133 | +----------------------+------------------+-----------------+------------------+-----------------+ | **Input** | - | 15/100 = 0.15 | - | 10/100 = 0.1 | +----------------------+------------------+-----------------+------------------+-----------------+ **Note:** * The numerator correspond to the number of units (elements) within the recieving population. * The denominator is the convergence number of presynaptic inputs for each unit. * The decimal fraction are the probability values for the `sim.FixedProbabilityConnector` function. **Comments on connection with output layer:** The excitatory (III) population connects to the output layer `(1995) <https://doi.org/10.1126/science.7863330>`_ such that it proxies adaptation. The output layer populations recieves signal only at the end of the stimulus, i.e. during second pulse. Due to limitations with `SpNNaker8 <http://spinnakermanchester.github.io/>`_ here the connection is implemented such that it is made from the start of the simulation. However, only responses from the populations in the output layer at the end of the stimulus is returned. """ wire_ex3ex3 = sim.FixedProbabilityConnector( 0.09, allow_self_connections=True) wire_ex3inh3 = sim.FixedProbabilityConnector( 0.06, allow_self_connections=False) wire_ex4ex3 = sim.FixedProbabilityConnector( 0.15, allow_self_connections=False) wire_ex4ex4 = sim.FixedProbabilityConnector( 0.125, allow_self_connections=True) wire_ex4inh3 = sim.FixedProbabilityConnector( 0.1, allow_self_connections=False) wire_ex4inh4 = sim.FixedProbabilityConnector( 0.083, allow_self_connections=False) wire_inh3ex3 = sim.FixedProbabilityConnector( 0.16, allow_self_connections=False) wire_inh3inh3 = sim.FixedProbabilityConnector( 0.12, allow_self_connections=True) wire_inh4ex4 = sim.FixedProbabilityConnector( 0.2, allow_self_connections=False) wire_inh4inh4 = sim.FixedProbabilityConnector( 0.133, allow_self_connections=True) wire_popInex4 = sim.FixedProbabilityConnector( 0.15, allow_self_connections=False) wire_popIninh4 = sim.FixedProbabilityConnector( 0.1, allow_self_connections=False) wire_inputpopIn = sim.FixedProbabilityConnector( 0.25, allow_self_connections=False) # Below is custom made and not given by Buonomano & Merzenich wire_ex3output = sim.FixedProbabilityConnector( 0.15, allow_self_connections=False) ### NOW CONNECT connect_ex3ex3 = sim.Projection(self.layer3["exc"], self.layer3["exc"], wire_ex3ex3, sim.StaticSynapse(weight=5.), receptor_type="excitatory") connect_ex3inh3 = sim.Projection(self.layer3["exc"], self.layer3["inh"], wire_ex3inh3, sim.StaticSynapse(weight=5.), receptor_type="excitatory") connect_ex4ex3 = sim.Projection(self.layer4["exc"], self.layer3["exc"], wire_ex4ex3, sim.StaticSynapse(weight=5.), receptor_type="excitatory") connect_ex4ex4 = sim.Projection(self.layer4["exc"], self.layer4["exc"], wire_ex4ex4, sim.StaticSynapse(weight=2.5), receptor_type="excitatory") connect_ex4inh3 = sim.Projection(self.layer4["exc"], self.layer3["inh"], wire_ex4inh3, sim.StaticSynapse(weight=5.), receptor_type="excitatory") connect_ex4inh4 = sim.Projection(self.layer4["exc"], self.layer4["inh"], wire_ex4inh4, sim.StaticSynapse(weight=2.5), receptor_type="excitatory") connect_inh3ex3 = sim.Projection(self.layer3["inh"], self.layer3["exc"], wire_inh3ex3, sim.StaticSynapse(weight=5.), receptor_type="inhibitory") connect_inh3inh3 = sim.Projection(self.layer3["inh"], self.layer3["inh"], wire_inh3inh3, sim.StaticSynapse(weight=5.), receptor_type="inhibitory") connect_inh4ex4 = sim.Projection(self.layer4["inh"], self.layer4["exc"], wire_inh4ex4, sim.StaticSynapse(weight=2.5), receptor_type="inhibitory") connect_inh4inh4 = sim.Projection(self.layer4["inh"], self.layer4["inh"], wire_inh4inh4, sim.StaticSynapse(weight=2.5), receptor_type="inhibitory") connect_popInex4 = sim.Projection(self.popIn, self.layer4["exc"], wire_popInex4, sim.StaticSynapse(weight=5.0), receptor_type="excitatory") connect_popIninh4 = sim.Projection(self.popIn, self.layer4["inh"], wire_popIninh4, sim.StaticSynapse(weight=5.0), receptor_type="excitatory") connect_inputpopIn = sim.Projection(self.input_src, self.popIn, wire_inputpopIn, sim.StaticSynapse(weight=1.0), receptor_type="excitatory") # connect the exc3 unit with output layer #for i in np.nditer(BuoMerz.dual_pulse_intervals): # Buonomano and Merzenich tested the network for intervals between 30 and 330 ms with 10 ms steps for i in self.dual_pulse_intervals: if i == self.inter_pulse_interval: unit_key = "out" + str(i) prj = [ sim.Projection(self.layer3["exc"], self.output[unit_key], wire_ex3output, sim.StaticSynapse(weight=100.0), receptor_type="excitatory") for k in self.output.keys() if k == unit_key ]
# ff_prob_conn = [(i, j, g_max, hard_delay) for i in range(N_layer) for j in range(N_layer) if np.random.rand() < .05] # lat_prob_conn = [(i, j, g_max, hard_delay) for i in range(N_layer) for j in range(N_layer) if np.random.rand() < .05] # # init_ff_connections = ff_prob_conn # init_lat_connections = lat_prob_conn # one_to_one_conn = [(i, i, g_max, hard_delay) for i in range(N_layer)] one_to_one_conn = [] ff_projection = sim.Projection( source_pop, target_pop, # sim.FromListConnector(one_to_one_conn), # sim.FromListConnector(ff_prob_conn), # sim.OneToOneConnector(weights=g_max, delays=hard_delay), # sim.FromListConnector(init_ff_connections[subsample_ff]), sim.FixedProbabilityConnector(p_connect=0.), synapse_type=structure_model_w_stdp, label="plastic_ff_projection") lat_projection = sim.Projection( target_pop, target_pop, # sim.FromListConnector(one_to_one_conn), # sim.FromListConnector(lat_prob_conn), # sim.OneToOneConnector(weights=g_max, delays=hard_delay), # sim.FromListConnector(init_lat_connections[subsample_lat]), sim.FixedProbabilityConnector(p_connect=0.0), synapse_type=structure_model_w_stdp, label="plastic_lat_projection", receptor_type="inhibitory" if args.lateral_inhibition else "excitatory")
# TODO Values rd_exc_weights = RandomDistribution('normal_clipped', mu=0.1, sigma=0.1, low=0, high=100, rng=rng) rd_exc_delays = RandomDistribution('normal_clipped', mu=1.5, sigma=0.75, low=1, high=15, rng=rng) ex_in_proj = sim.Projection(pop_exc, pop_inh, sim.FixedProbabilityConnector(0.1, rng=rng), synapse_type=sim.StaticSynapse( weight=rd_exc_weights, delay=rd_exc_delays), receptor_type="excitatory") # Create a similar connection between the excitatory population and itself. ex_ex_proj = sim.Projection(pop_exc, pop_exc, sim.FixedProbabilityConnector(0.1, rng=rng), synapse_type=sim.StaticSynapse( weight=rd_exc_weights, delay=rd_exc_delays), receptor_type="excitatory") # Create an inhibitory connection from the inhibitory population to the # excitatory population with a fixed probability of connection of 0.1, # and using a normal distribution of weights with a
print "%s Creating cell populations..." % node_id exc_cells = p.Population(n_exc, celltype(**cell_params), label="Excitatory_Cells") inh_cells = p.Population(n_inh, celltype(**cell_params), label="Inhibitory_Cells") exc_conn = None ext_stim = None if benchmark == "COBA": ext_stim = p.Population(20, p.SpikeSourcePoisson(rate=rate, duration=stim_dur), label="expoisson") rconn = 0.01 ext_conn = p.FixedProbabilityConnector(rconn) ext_stim.record("spikes") print "%s Initialising membrane potential to random values..." % node_id rng = NumpyRNG(seed=rngseed, parallel_safe=parallel_safe) uniformDistr = RandomDistribution('uniform', [v_reset, v_thresh], rng=rng) exc_cells.set(v=uniformDistr) inh_cells.set(v=uniformDistr) print "%s Connecting populations..." % node_id exc_conn = p.FixedProbabilityConnector(pconn, rng=rng) inh_conn = p.FixedProbabilityConnector(pconn, rng=rng) connections = { 'e2e': p.Projection(exc_cells,
str(number))) # Neuron populations target_column.append( sim.Population(N_layer, model, cell_params, label="TARGET_POP # " + str(number))) # Setting up connectivity ff_connections.append( sim.Projection( source_column[number], target_column[number], # sim.FromListConnector(init_ff_connections), sim.FixedProbabilityConnector(0.), synapse_type=structure_model_w_stdp, label="plastic_ff_projection")) if args.case != CASE_CORR_NO_REW: lat_connections.append( sim.Projection( target_column[number], target_column[number], # sim.FromListConnector(init_lat_connections), sim.FixedProbabilityConnector(0.), synapse_type=structure_model_w_stdp, label="plastic_lat_projection", receptor_type="inhibitory" if args.lateral_inhibition else "excitatory"))
#CH --> CH_inh connectivity================================================================== # ch2chinh_proj = sim.Projection(CH_pop,CH_pop_inh,sim.OneToOneConnector(),synapse_type=sim.StaticSynapse(weight=0.5)) #CH_inh --> CH connectivity================================================================== # chinh2ch_proj = sim.Projection(CH_pop_inh,CH_pop,sim.AllToAllConnector(),synapse_type=sim.StaticSynapse(weight=0.1), # receptor_type='inhibitory') #AN --> ON connectivity================================================================== # an2on_prob=400./AN_pop_size an2on_prob = 1. * (88. / AN_pop_size) #0.4#0.15#0.6#0.54# # an2on_weight =RandomDistribution('uniform',(0.05,0.15)) an2on_weight = RandomDistribution('uniform', (0., 5.)) an2on_proj = sim.Projection( AN_pop, ON_pop, sim.FixedProbabilityConnector(p_connect=an2on_prob), synapse_type=sim.StaticSynapse(weight=an2on_weight, delay=1)) #ON --> ON_inh connectivity================================================================== # on2oninh_proj = sim.Projection(ON_pop,ON_pop_inh,sim.OneToOneConnector(),synapse_type=sim.StaticSynapse(weight=15.,delay=1.)) # oninh2on_proj = sim.Projection(ON_pop_inh,ON_pop,sim.AllToAllConnector(),synapse_type=sim.StaticSynapse(weight=0.3,delay=1.), # receptor_type='inhibitory') #AN --> PL connectivity================================================================== an2pl_weight = RandomDistribution('uniform', (25., 40.)) #[25.,35.])# # an2pl_proj = sim.Projection(AN_pop,PL_pop,sim.OneToOneConnector(),synapse_type=sim.StaticSynapse(weight=an2pl_weight,delay=1.0))#(weights=40.,delays=1.0))# #CH --> IC connectivity================================================================== ch2ic_weight = RandomDistribution('uniform', (10., 12.)) #[4.,5.]) # diagonal_width = 2. diagonal_width = AN_pop_size / 500. diagonal_sparseness = 1.