def build_basic_network(input_stimuli_rates, input_stimuli_duration, class_stimuli_rates, class_stimuli_duration, record, ioffset, train, sim): # Create main input and class populations input_populations = [create_input_population(CLASS_POP_SIZE, record, sim) for _ in input_stimuli_rates] if isinstance(ioffset, list) or isinstance(ioffset, np.ndarray): assert len(ioffset) == len(class_stimuli_rates) class_populations = [create_class_population(CLASS_POP_SIZE, record, o, train, sim) for i, o in enumerate(ioffset)] else: print ioffset class_populations = [create_class_population(CLASS_POP_SIZE, record, ioffset, train, sim) for _ in class_stimuli_rates] # Create pre-synaptic stimuli populations pre_stimuli_connector = sim.OneToOneConnector() pre_stimuli_synapse = sim.StaticSynapse(weight=PRE_STIMULI_WEIGHT) for i, (rate, input_pop) in enumerate(zip(input_stimuli_rates, input_populations)): # Convert stimuli into spike times spike_times = generate_stimuli_spike_times(rate, input_stimuli_duration, CLASS_POP_SIZE) # Build spike source array with these times stim_pop = sim.Population(CLASS_POP_SIZE, sim.SpikeSourceArray(spike_times=spike_times), label="pre_stimuli_%u" % i) # Connect spike source to input sim.Projection(stim_pop, input_pop, pre_stimuli_connector, pre_stimuli_synapse, receptor_type="excitatory", label="%s-%s" % (stim_pop.label, input_pop.label)) # Create training spike source array populations post_stimuli_connector = sim.OneToOneConnector() post_stimuli_synapse = sim.StaticSynapse(weight=POST_STIMULI_WEIGHT) for i, (rate, class_pop) in enumerate(zip(class_stimuli_rates, class_populations)): # Convert stimuli into spike times spike_times = generate_stimuli_spike_times(rate, class_stimuli_duration, CLASS_POP_SIZE) # Build spike source array with these times stim_pop = sim.Population(CLASS_POP_SIZE, sim.SpikeSourceArray, {"spike_times": spike_times}, label="post_stimuli_%u" % i) # Connect spike source to input sim.Projection(stim_pop, class_pop, post_stimuli_connector, post_stimuli_synapse, receptor_type="excitatory", label="%s-%s" % (stim_pop.label, class_pop.label)) # Return created populations return input_populations, class_populations
def __init__(self, name, sim, rng, num_excitatory, num_inhibitory, JE, JI, e_cell_model, i_cell_model, e_cell_params, i_cell_params, e_cell_flush_time, e_cell_mean_firing_rate, stim_spike_times, wta, background_weight, background_rate, stim_weight, simtime, record_bias, record_spikes, record_membrane): logger.info("Creating HCU:%s" % name) logger.debug("num excitatory:%u, num inhibitory:%u", num_excitatory, num_inhibitory) # compute number of excitatory synapses on neuron num_excitatory_synapses = int(epsilon * num_excitatory) # Cache recording flags self.record_bias = record_bias self.record_spikes = record_spikes self.record_membrane = record_membrane self.wta = wta logger.debug("Membrane potentials uniformly distributed between %g mV and %g mV.", -80, U0) membrane_voltage_distribution = RandomDistribution("uniform", low=-80.0, high=U0, rng=rng) logger.debug("Creating excitatory population with %d neurons.", num_excitatory) self.e_cells = sim.Population(num_excitatory, e_cell_model(**e_cell_params), label="%s - e_cells" % name) self.e_cells.initialize(v=membrane_voltage_distribution) # Set e cell mean firing rate self.e_cells.spinnaker_config.mean_firing_rate = e_cell_mean_firing_rate # **HACK** issue #18 means that we end up with 1024 wide clusters # which needs a lot of 256-wide neuron and synapse cores self.e_cells.spinnaker_config.max_cluster_width = 512 # Set flush time self.e_cells.spinnaker_config.flush_time = e_cell_flush_time # **YUCK** record spikes actually entirely ignores # sampling interval but throws exception if it is not set if self.record_spikes: self.e_cells.record("spikes", sampling_interval=1000.0) if self.record_bias: self.e_cells.record("bias", sampling_interval=1000.0) if self.record_membrane: self.e_cells.record("v", sampling_interval=1000.0) e_poisson = sim.Population(num_excitatory, sim.SpikeSourcePoisson(rate=background_rate, duration=simtime), label="%s - e_poisson" % name) logger.debug("Creating background->E AMPA connection weight %g nA.", background_weight) sim.Projection(e_poisson, self.e_cells, sim.OneToOneConnector(), sim.StaticSynapse(weight=background_weight, delay=delay), receptor_type="excitatory") if self.wta: logger.debug("Creating inhibitory population with %d neurons.", num_inhibitory) self.i_cells = sim.Population(num_inhibitory, i_cell_model, i_cell_params, label="%s - i_cells" % name) self.i_cells.initialize(v=membrane_voltage_distribution) # Inhibitory cells generally fire at a low rate self.i_cells.spinnaker_config.mean_firing_rate = 5.0 if self.record_spikes: self.i_cells.record("spikes") i_poisson = sim.Population(num_inhibitory, sim.SpikeSourcePoisson(rate=background_rate, duration=simtime), label="%s - i_poisson" % name) logger.debug("Creating I->E GABA connection with connection probability %g, weight %g nA and delay %g ms.", epsilon, JI, delay) I_to_E = sim.Projection(self.i_cells, self.e_cells, sim.FixedProbabilityConnector(p_connect=epsilon, rng=rng), sim.StaticSynapse(weight=JI, delay=delay), receptor_type="inhibitory") logger.debug("Creating E->I AMPA connection with connection probability %g, weight %g nA and delay %g ms.", epsilon, JE, delay) sim.Projection(self.e_cells, self.i_cells, sim.FixedProbabilityConnector(p_connect=epsilon, rng=rng), sim.StaticSynapse(weight=JE, delay=delay), receptor_type="excitatory") logger.debug("Creating I->I GABA connection with connection probability %g, weight %g nA and delay %g ms.", epsilon, JI, delay) sim.Projection(self.i_cells, self.i_cells, sim.FixedProbabilityConnector(p_connect=epsilon, rng=rng), sim.StaticSynapse(weight=JI, delay=delay), receptor_type="inhibitory") logger.debug("Creating background->I AMPA connection weight %g nA.", background_weight) sim.Projection(i_poisson, self.i_cells, sim.OneToOneConnector(), sim.StaticSynapse(weight=background_weight, delay=delay), receptor_type="excitatory") # Create a spike source capable of stimulating entirely excitatory population stim_spike_source = sim.Population(num_excitatory, sim.SpikeSourceArray(spike_times=stim_spike_times)) # Connect one-to-one to excitatory neurons sim.Projection(stim_spike_source, self.e_cells, sim.OneToOneConnector(), sim.StaticSynapse(weight=stim_weight, delay=delay), receptor_type="excitatory")
''' # Create connector proj = sim.Projection(neurons, neurons, sim.FromListConnector(conn_list), stdp_model, receptor_type="excitatory") # Stimulate stim neuron stim = sim.Population(1, sim.SpikeSourceArray(spike_times=[2.0]), label="stim") sim.Projection( stim, neurons, sim.FromListConnector([ (0, get_neuron_index(stim_x, stim_y, cost_image.shape[1]), instant_spike_weight, 1.0) ]), sim.StaticSynapse()) # Run network sim.run(duration) # Read data data = neurons.get_data() weights = proj.get("weight", format="list", with_address=True) sim.end() # Create weight graph with each neuron marked weight_graph = graphviz.Digraph(engine="neato", format="svg") spacing = 2.0 for n in range(num_neurons): neuron_x, neuron_y = get_neuron_x_y(n, cost_image.shape[1])