def build_network(self, dynamics, cell_params): """ Function to build the basic network - dynamics should be a PyNN synapse dynamics object :param dynamics: :return: """ # SpiNNaker setup model = sim.IF_curr_exp sim.setup(timestep=1.0, min_delay=1.0, max_delay=10.0) # 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() # Make excitatory->inhibitory projections sim.Projection(ex_pop, in_pop, sim.FixedProbabilityConnector(0.02, weights=0.03), target='excitatory') sim.Projection(ex_pop, ex_pop, sim.FixedProbabilityConnector(0.02, weights=0.03), target='excitatory') # Make inhibitory->inhibitory projections sim.Projection(in_pop, in_pop, sim.FixedProbabilityConnector(0.02, weights=-0.3), target='inhibitory') # Make inhibitory->excitatory projections ie_projection = sim.Projection(in_pop, ex_pop, sim.FixedProbabilityConnector( 0.02, weights=0), target='inhibitory', synapse_dynamics=dynamics) return ex_pop, ie_projection
def test_generate_synapse_list_probability_zero_percent(self): number_of_neurons = 5 first_population = pyNN.Population(number_of_neurons, pyNN.IF_curr_exp, cell_params_lif, label="One pop") weight = 2 delay = 1 synapse_type = 0 connection = pyNN.FixedProbabilityConnector(0, weight, delay) synaptic_list = connection.generate_synapse_list( first_population, first_population, 1, 1.0, synapse_type) pp(synaptic_list.get_rows())
def test_synapse_list_generation_for_different_sized_populations(self): number_of_neurons = 10 first_population = pyNN.Population(number_of_neurons, pyNN.IF_curr_exp, cell_params_lif, label="One pop") second_population = pyNN.Population(number_of_neurons + 5, pyNN.IF_curr_exp, cell_params_lif, label="Second pop") weight = 2 delay = 1 connection = pyNN.FixedProbabilityConnector(0.1, weight, delay) synaptic_list = connection.generate_synapse_list( first_population, second_population, 1, 1.0, 0) pp(synaptic_list.get_rows())
def test_generate_synapse_list_probability_100_percent(self): number_of_neurons = 5 first_population = pyNN.Population(number_of_neurons, pyNN.IF_curr_exp, cell_params_lif, label="One pop") weight = 2 delay = 1 synapse_type = 0 connection = pyNN.FixedProbabilityConnector(1, weight, delay) synaptic_list = connection.generate_synapse_list( first_population, first_population, 1, 1.0, synapse_type) pp(synaptic_list.get_rows()) self.assertEqual(synaptic_list.get_max_weight(), weight) self.assertEqual(synaptic_list.get_min_weight(), weight) self.assertEqual(synaptic_list.get_n_rows(), number_of_neurons) self.assertEqual(synaptic_list.get_max_delay(), delay) self.assertEqual(synaptic_list.get_min_delay(), delay)
def test_synapse_list_generation_for_negative_sized_populations(self): with self.assertRaises(ConfigurationException): weight = 2 delay = 1 pyNN.FixedProbabilityConnector(-0.5, weight, delay)
def test_generate_synapse_list_probability_200_percent(self): with self.assertRaises(ConfigurationException): weight = 2 delay = 1 pyNN.FixedProbabilityConnector(2, weight, delay)
# +-------------------------------------------------------------------+ # | Creation of connections | # +-------------------------------------------------------------------+ # Connection type between noise poisson generator and presynaptic populations #sim.Projection(pre_stim, pre_pop, sim.FixedProbabilityConnector(0.1, weights=.5)) # Pre to Post (inlcuding defninition of STDP model) stdp_model = sim.STDPMechanism( timing_dependence=sim.SpikePairRule(tau_plus=20.0, tau_minus=20.0), weight_dependence=sim.AdditiveWeightDependence(w_min=0, w_max=1, A_plus=0.2, A_minus=0.2)) variableWeights = sim.Projection( pre_pop, post_pop, sim.FixedProbabilityConnector(0.1, weights=.5), synapse_dynamics=sim.SynapseDynamics(slow=stdp_model)) # Record spikes pre_stim.record() pre_pop.record() post_pop.record() # Run simulation sim.run(sim_time) # Dump data #pre_pop.printSpikes("results/stdp_pre.spikes") #post_pop.printSpikes("results/stdp_post.spikes") #pre_pop.print_v("results/stdp_pre.v") #post_pop.print_v("results/stdp_post.v")
p.Projection(INoisePost, post_pop, ee_connector, target='excitatory') # Additional Inputs projections for i in range(len(IAddPre)): p.Projection(IAddPre[i], pre_pop, ee_connector, target='excitatory') for i in range(len(IAddPost)): p.Projection(IAddPost[i], post_pop, ee_connector, target='excitatory') # Plastic Connections between pre_pop and post_pop stdp_model = p.STDPMechanism( timing_dependence = p.SpikePairRule(tau_plus = 20., tau_minus = 50.0, nearest=True), weight_dependence = p.AdditiveWeightDependence(w_min = 0, w_max = 0.9, A_plus=0.02, A_minus = 0.02) ) plastic_projection = \ p.Projection(pre_pop, post_pop, p.FixedProbabilityConnector(p_connect=0.5), synapse_dynamics = p.SynapseDynamics(slow= stdp_model) ) # +-------------------------------------------------------------------+ # | Simulation and results | # +-------------------------------------------------------------------+ # Record neurons' potentials pre_pop.record_v() post_pop.record_v() # Record spikes pre_pop.record() post_pop.record()
def test_fixed_probabilityies(self): pop_size = 1024 rng_weights = p.NumpyRNG(seed=369121518) min_weight = 0.1 max_weight = 5.0 weight_scale_ex_in = 0.25 weight_dependence_n = \ p.RandomDistribution( distribution='uniform', parameters=[1.0 + min_weight, 1.0 + max_weight], rng=rng_weights) weight_dependence_e = \ p.RandomDistribution(distribution='uniform', parameters=[min_weight, max_weight], rng=rng_weights) weight_dependence_i = \ p.RandomDistribution(distribution='uniform', parameters=[-(max_weight * weight_scale_ex_in), -min_weight], rng=rng_weights) runtime = 1000.0 stim_start = 0.0 stim_rate = 10 pops_to_observe = ['mapped_pop_1'] # Simulation Setup p.setup(timestep=1.0, min_delay=1.0, max_delay=11.0) # Neural Parameters tau_m = 24.0 # (ms) cm = 1 v_rest = -65.0 # (mV) v_thresh = -45.0 # (mV) v_reset = -65.0 # (mV) t_refrac = 3.0 # (ms) (clamped at v_reset) tau_syn_exc = 3.0 tau_syn_inh = tau_syn_exc * 3 # cell_params will be passed to the constructor of the Population Object cell_params = { 'tau_m': tau_m, 'cm': cm, 'v_init': v_reset, 'v_rest': v_rest, 'v_reset': v_reset, 'v_thresh': v_thresh, 'tau_syn_E': tau_syn_exc, 'tau_syn_I': tau_syn_inh, 'tau_refrac': t_refrac, 'i_offset': 0 } observed_pop_list = [] inputs = p.Population( pop_size, p.SpikeSourcePoisson, {'duration': runtime, 'start': stim_start, 'rate': stim_rate}, label="inputs") if 'inputs' in pops_to_observe: inputs.record() observed_pop_list.append(inputs) mapped_pop_1 = p.Population(pop_size, p.IF_curr_exp, cell_params, label="mapped_pop_1") if 'mapped_pop_1' in pops_to_observe: mapped_pop_1.record() observed_pop_list.append(mapped_pop_1) pop_inhibit = p.Population(pop_size, p.IF_curr_exp, cell_params, label="pop_inhibit") if 'pop_inhibit' in pops_to_observe: pop_inhibit.record() observed_pop_list.append(pop_inhibit) mapped_pop_2 = p.Population(pop_size, p.IF_curr_exp, cell_params, label="mapped_pop_2") if 'mapped_pop_2' in pops_to_observe: mapped_pop_2.record() observed_pop_list.append(mapped_pop_2) p.Projection(inputs, mapped_pop_1, p.OneToOneConnector( weights=weight_dependence_n, delays=1.0), target='excitatory') p.Projection(mapped_pop_1, pop_inhibit, p.OneToOneConnector( weights=weight_dependence_e, delays=1.0), target='excitatory') p.NativeRNG(123456) p.Projection(pop_inhibit, mapped_pop_2, p.FixedProbabilityConnector( p_connect=0.5, allow_self_connections=True, weights=weight_dependence_i, delays=4.0), target='inhibitory') p.Projection(mapped_pop_1, mapped_pop_2, p.FixedProbabilityConnector( p_connect=0.5, allow_self_connections=True, weights=weight_dependence_e, delays=4.0), target='excitatory') p.run(runtime) current_file_path = os.path.dirname(os.path.abspath(__file__)) for pop in observed_pop_list: data = numpy.asarray(pop.getSpikes()) current_pop_file_path = os.path.join(current_file_path, "{}.data".format(pop.label)) pre_recorded_data = p.utility_calls.read_spikes_from_file( current_pop_file_path, 0, pop_size, 0, runtime) for spike_element, read_element in zip(data, pre_recorded_data): self.assertEqual(round(spike_element[0], 1), round(read_element[0], 1)) self.assertEqual(round(spike_element[1], 1), round(read_element[1], 1))