def allocateSpinnakerInputs(self): import spynnaker_external_devices_plugin.pyNN as externaldevices self.InputWordSource = self.sim.Population( self.NUMBER_WORDS + 1, #for the start externaldevices.SpikeInjector, {'port': 12345}, label="wordSpikeToBoard") externaldevices.activate_live_output_for( self.InputWordSource, database_notify_port_num=12345)
def setupLayerAN(params, settings, neuronModel, cell_params, popClassActivation, popPoissionNoiseSource, populationsPN, populationsAN,learning,projectionsPNAN): #create an Association Neuron AN cluster population per class #this will be fed by: #1) PN clusters via plastic synapses #2) Class activation to innervate the correct AN cluster for a given input #3) laterally inhibit between AN clusters numClasses = params['NUM_CLASSES'] anClusterSize = int(params['CLUSTER_SIZE']) #* params['NETWORK_SCALE'] for an in range(numClasses): popName = 'popClusterAN_' + str(an) ; popClusterAN = spynnaker.Population(anClusterSize, neuronModel, cell_params, label=popName) populationsAN.append(popClusterAN) #connect neurons in every PN popn to x% (e.g 50%) neurons in this AN cluster for pn in range(len(populationsPN)): if learning: projLabel = 'Proj_PN' + str(pn) + '_AN' + str(an) projClusterPNToClusterAN = connectClusterPNtoAN(params,populationsPN[pn],popClusterAN,float(settings['OBSERVATION_EXPOSURE_TIME_MS']),projLabel) projectionsPNAN.append(projClusterPNToClusterAN) #keep handle to use later for saving off weights at end of learning else: #Without plasticity, create PNAN FromList connectors using weights saved during learning stage connections = utils.loadListFromFile(getWeightsFilename(settings,'PNAN',pn,an)) #print 'Loaded weightsList[',pn,',',an,']',connections tupleList = utils.createListOfTuples(connections) #new version only accepts list of tuples not list of lists #print 'tupleList[',pn,',',an,']',tupleList conn = spynnaker.FromListConnector(tupleList) projClusterPNToClusterAN = spynnaker.Projection(populationsPN[pn], popClusterAN,conn, target='excitatory') if learning: #use the class activity input neurons to create correlated activity during learining in the corresponding class cluster weight = params['WEIGHT_CLASS_EXCITATION_TO_CLUSTER_AN'] connections = utils.fromList_SpecificNeuronToAll(an,anClusterSize,weight,params['MIN_DELAY_CLASS_ACTIVITY_TO_CLUSTER_AN'],params['MAX_DELAY_CLASS_ACTIVITY_TO_CLUSTER_AN']) projClassActivityToClusterAN = spynnaker.Projection(popClassActivation, popClusterAN, spynnaker.FromListConnector(connections), target='excitatory') else: #testing #send spikes on these outputs back to correct host port , these will be used to determine winner etc anHostReceivePort = int(settings['AN_HOST_RECEIVE_PORT']) ExternalDevices.activate_live_output_for(popClusterAN,port=anHostReceivePort) #connect each AN cluster to inhibit every other AN cluster utils.createInterPopulationWTA(populationsAN,params['WEIGHT_WTA_AN_AN'],params['DELAY_WTA_AN_AN'],float(params['CONNECTIVITY_WTA_AN_AN'])) #inhibit other non-corresponding class clusters if learning: weight = params['WEIGHT_CLASS_INHIBITION_TO_CLUSTER_AN'] for activeCls in range(numClasses): connections = utils.fromList_SpecificNeuronToAll(activeCls,anClusterSize,weight,params['MIN_DELAY_CLASS_ACTIVITY_TO_CLUSTER_AN'],params['MAX_DELAY_CLASS_ACTIVITY_TO_CLUSTER_AN']) for an in range(numClasses): if an != activeCls: projClassActivityToClusterAN = spynnaker.Projection(popClassActivation, populationsAN[an], spynnaker.FromListConnector(connections), target='inhibitory')
def setupSpikeReceiver(self, network=None): print "\tSetting up Spike Receiver..." networkLabels = [] for pop in network: ExternalDevices.activate_live_output_for(pop[1], database_notify_host="localhost", database_notify_port_num=19996) networkLabels.append(pop[1].label) liveConnection = SpynnakerLiveSpikesConnection(receive_labels=networkLabels, local_port=19996, send_labels=None) for label in networkLabels: liveConnection.add_receive_callback(label, self.plotReceivedSpike)
def setupSpikeReceiver(network=None): print "Setting up Spike Receiver..." networkLabels = [] for pop in network: ExternalDevices.activate_live_output_for(pop[1], database_notify_host="localhost", database_notify_port_num=19996, board_address='10.162.177.122') networkLabels.append(pop[1].label) if not useCVisualiser: liveConnection = SpynnakerLiveSpikesConnection(receive_labels=networkLabels, local_port=19996, send_labels=None) for label in networkLabels: liveConnection.add_receive_callback(label, receiveSpike) return liveConnection
def createNeurons(self): numberGoalCells = self.NUMBER_GOALS * self.fsa.CA_SIZE numberModuleCells = self.NUMBER_MODULES * self.fsa.CA_SIZE numberFactCells = self.NUMBER_FACTS * self.fsa.CA_SIZE numberActionCells = self.NUMBER_ACTIONS localGoalCells = self.sim.Population(numberGoalCells, self.sim.IF_cond_exp, self.fsa.CELL_PARAMS) localModuleCells = self.sim.Population(numberModuleCells, self.sim.IF_cond_exp, self.fsa.CELL_PARAMS) localFactCells = self.sim.Population(numberFactCells, self.sim.IF_cond_exp, self.fsa.CELL_PARAMS) resetCells = self.sim.Population(self.fsa.CA_SIZE, self.sim.IF_cond_exp, self.fsa.CELL_PARAMS) if (self.simName == 'spinnaker') and (self.spinnVersion == 7): import spynnaker_external_devices_plugin.pyNN as ExternalDevices localActionCells = self.sim.Population(numberActionCells, self.sim.IF_cond_exp, self.fsa.CELL_PARAMS, label='actionFromBoard') ExternalDevices.activate_live_output_for( localActionCells, database_notify_port_num=12346) elif (self.simName == 'spinnaker') and (self.spinnVersion == 8): import spynnaker8.external_devices as ExternalDevices localActionCells = self.sim.Population(numberActionCells, self.sim.IF_cond_exp, self.fsa.CELL_PARAMS, label='actionFromBoard') ExternalDevices.activate_live_output_for( localActionCells, database_notify_port_num=12346) print "hey" elif (self.simName == 'nest'): #change tau_refrac so that the action cells don't fire too fast actionCellParams = self.fsa.CELL_PARAMS.copy() actionCellParams["tau_refrac"] = 10.0 localActionCells = self.sim.Population(numberActionCells, self.sim.IF_cond_exp, actionCellParams) return [ localGoalCells, localModuleCells, localFactCells, localActionCells, resetCells ]
def setupVisualiser(network=None, retinaLeft=None, retinaRight=None): print "Setting up Visualiser..." global retinaThreads, disparityThread, logFile logFile = open("dipsarities.txt", 'w') print "\tSetting up Spike Receiver..." networkLabels = [] for pop in network: ExternalDevices.activate_live_output_for(pop[1], database_notify_host="localhost", database_notify_port_num=19996) networkLabels.append(pop[1].label) liveConnection_receiver = SpynnakerLiveSpikesConnection(receive_labels=networkLabels, local_port=19996, send_labels=None) disparityThread = spike_plotter() for label in networkLabels: liveConnection_receiver.add_receive_callback(label, disparityThread.plotReceivedSpike) disparityThread.start() print "\tSetting up Spike Injectors for Retina Left and Retina Right..." retinaLabels = [] for popL, popR in zip(retinaLeft, retinaRight): retinaLabels.append(popL[1].label) retinaLabels.append(popR[1].label) liveConnection_sender = SpynnakerLiveSpikesConnection(receive_labels=None, local_port=19999, send_labels=retinaLabels) bg_col=pygame.Color(230,230,230,0) on_col=pygame.Color(10,220,10,0) off_col=pygame.Color(220,10,10,0) retinaThreads[ports[0]] = dvs_reader(port=ports[0], colors = {"bg": bg_col, "on": on_col, "off": off_col}, label="RetL", liveConnection=liveConnection_sender) retinaThreads[ports[1]] = dvs_reader(port=ports[1], colors = {"bg": bg_col, "on": on_col, "off": off_col}, label="RetR", liveConnection=liveConnection_sender) liveConnection_sender.add_start_callback(retinaLabels[0], startInjecting) panelsDrawer = Thread(target=setupPanels) panelsDrawer.start()
def __init__(self): # initial call to set up the front end (pynn requirement) Frontend.setup(timestep=1.0, min_delay=1.0, max_delay=144.0) use_c_visualiser = True use_spike_injector = True # neurons per population and the length of runtime in ms for the # simulation, as well as the expected weight each spike will contain self.n_neurons = 100 # set up gui p = None if use_spike_injector: from multiprocessing import Process from multiprocessing import Event ready = Event() p = Process(target=GUI, args=[self.n_neurons, ready]) p.start() ready.wait() # different runtimes for demostration purposes run_time = None if not use_c_visualiser and not use_spike_injector: run_time = 1000 elif use_c_visualiser and not use_spike_injector: run_time = 10000 elif use_c_visualiser and use_spike_injector: run_time = 100000 elif not use_c_visualiser and use_spike_injector: run_time = 10000 weight_to_spike = 2.0 # neural parameters of the IF_curr model used to respond to injected # spikes. # (cell params for a synfire chain) 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': -50.0 } ################################## # Parameters for the injector population. This is the minimal set of # parameters required, which is for a set of spikes where the key is # not important. Note that a virtual key *will* be assigned to the # population, and that spikes sent which do not match this virtual key # will be dropped; however, if spikes are sent using 16-bit keys, they # will automatically be made to match the virtual key. The virtual # key assigned can be obtained from the database. ################################## cell_params_spike_injector = { # The port on which the spiNNaker machine should listen for # packets. Packets to be injected should be sent to this port on # the spiNNaker machine 'port': 12345 } ################################## # Parameters for the injector population. Note that each injector # needs to be given a different port. The virtual key is assigned # here, rather than being allocated later. As with the above, spikes # injected need to match this key, and this will be done automatically # with 16-bit keys. ################################## cell_params_spike_injector_with_key = { # The port on which the spiNNaker machine should listen for # packets. Packets to be injected should be sent to this port on # the spiNNaker machine 'port': 12346, # This is the base key to be used for the injection, which is used # to allow the keys to be routed around the spiNNaker machine. # This assignment means that 32-bit keys must have the high-order # 16-bit set to 0x7; This will automatically be prepended to # 16-bit keys. 'virtual_key': 0x70000 } # create synfire populations (if cur exp) pop_forward = Frontend.Population( self.n_neurons, Frontend.IF_curr_exp, cell_params_lif, label='pop_forward') pop_backward = Frontend.Population( self.n_neurons, Frontend.IF_curr_exp, cell_params_lif, label='pop_backward') # Create injection populations injector_forward = None injector_backward = None if use_spike_injector: injector_forward = Frontend.Population( self.n_neurons, ExternalDevices.SpikeInjector, cell_params_spike_injector_with_key, label='spike_injector_forward') injector_backward = Frontend.Population( self.n_neurons, ExternalDevices.SpikeInjector, cell_params_spike_injector, label='spike_injector_backward') else: spike_times = [] for _ in range(0, self.n_neurons): spike_times.append([]) spike_times[0] = [0] spike_times[20] = [(run_time / 100) * 20] spike_times[40] = [(run_time / 100) * 40] spike_times[60] = [(run_time / 100) * 60] spike_times[80] = [(run_time / 100) * 80] cell_params_forward = {'spike_times': spike_times} spike_times_backwards = [] for _ in range(0, self.n_neurons): spike_times_backwards.append([]) spike_times_backwards[0] = [(run_time / 100) * 80] spike_times_backwards[20] = [(run_time / 100) * 60] spike_times_backwards[40] = [(run_time / 100) * 40] spike_times_backwards[60] = [(run_time / 100) * 20] spike_times_backwards[80] = [0] cell_params_backward = {'spike_times': spike_times_backwards} injector_forward = Frontend.Population( self.n_neurons, Frontend.SpikeSourceArray, cell_params_forward, label='spike_injector_forward') injector_backward = Frontend.Population( self.n_neurons, Frontend.SpikeSourceArray, cell_params_backward, label='spike_injector_backward') # Create a connection from the injector into the populations Frontend.Projection( injector_forward, pop_forward, Frontend.OneToOneConnector(weights=weight_to_spike)) Frontend.Projection( injector_backward, pop_backward, Frontend.OneToOneConnector(weights=weight_to_spike)) # Synfire chain connections where each neuron is connected to its next # neuron # NOTE: there is no recurrent connection so that each chain stops once # it reaches the end loop_forward = list() loop_backward = list() for i in range(0, self.n_neurons - 1): loop_forward.append((i, (i + 1) % self.n_neurons, weight_to_spike, 3)) loop_backward.append(((i + 1) % self.n_neurons, i, weight_to_spike, 3)) Frontend.Projection(pop_forward, pop_forward, Frontend.FromListConnector(loop_forward)) Frontend.Projection(pop_backward, pop_backward, Frontend.FromListConnector(loop_backward)) # record spikes from the synfire chains so that we can read off valid # results in a safe way afterwards, and verify the behavior pop_forward.record() pop_backward.record() # Activate the sending of live spikes ExternalDevices.activate_live_output_for( pop_forward, database_notify_host="localhost", database_notify_port_num=19996) ExternalDevices.activate_live_output_for( pop_backward, database_notify_host="localhost", database_notify_port_num=19996) if not use_c_visualiser: # if not using the c visualiser, then a new spynnaker live spikes # connection is created to define that there are python code which # receives the outputted spikes. live_spikes_connection_receive = SpynnakerLiveSpikesConnection( receive_labels=["pop_forward", "pop_backward"], local_port=19999, send_labels=None) # Set up callbacks to occur when spikes are received live_spikes_connection_receive.add_receive_callback( "pop_forward", receive_spikes) live_spikes_connection_receive.add_receive_callback( "pop_backward", receive_spikes) # Run the simulation on spiNNaker Frontend.run(run_time) # Retrieve spikes from the synfire chain population spikes_forward = pop_forward.getSpikes() spikes_backward = pop_backward.getSpikes() # If there are spikes, plot using matplotlib if len(spikes_forward) != 0 or len(spikes_backward) != 0: pylab.figure() if len(spikes_forward) != 0: pylab.plot([i[1] for i in spikes_forward], [i[0] for i in spikes_forward], "b.") if len(spikes_backward) != 0: pylab.plot([i[1] for i in spikes_backward], [i[0] for i in spikes_backward], "r.") pylab.ylabel('neuron id') pylab.xlabel('Time/ms') pylab.title('spikes') pylab.show() else: print "No spikes received" # Clear data structures on spiNNaker to leave the machine in a clean # state for future executions Frontend.end() if use_spike_injector: p.join()
} # The port on which the spiNNaker machine should listen for packets. # Packets to be injected should be sent to this port on the spiNNaker machine cell_params_spike_injector_1 = {'port': spikeInjectionPort1} cell_params_spike_injector_2 = {'port': spikeInjectionPort2} populations = list() projections = list() weight_to_spike = 2.0 pop_spikes_out_1 = spynn.Population(nNeurons1, spynn.IF_curr_exp, cell_params_lif, label=spikeReceivePopLabel1) ExternalDevices.activate_live_output_for(pop_spikes_out_1, port=hostReceivePortPop1) #spikes will get transmitted to specfieid port on workstation (else defaults to port set in spynnaker.cfg "live_spike_port" param) populations.append(pop_spikes_out_1) pop_spikes_out_2 = spynn.Population(nNeurons2, spynn.IF_curr_exp, cell_params_lif, label='pop_spikes_out_2') populations.append(pop_spikes_out_2) pop_spikes_in_1 = spynn.Population(nNeurons1,ExternalDevices.SpikeInjector,cell_params_spike_injector_1,label=spikeInjectionPopLabel1) populations.append(pop_spikes_in_1) pop_spikes_in_2 = spynn.Population(nNeurons2,ExternalDevices.SpikeInjector,cell_params_spike_injector_2,label=spikeInjectionPopLabel2) populations.append(pop_spikes_in_2) pop_spikes_out_1.record() pop_spikes_out_2.record() projections.append(spynn.Projection(pop_spikes_in_1, pop_spikes_out_1,spynn.OneToOneConnector(weights=weight_to_spike))) projections.append(spynn.Projection(pop_spikes_in_2, pop_spikes_out_2,spynn.OneToOneConnector(weights=weight_to_spike)))
print cell_params if (benchmark == "COBA"): cell_params['e_rev_E'] = Erev_exc cell_params['e_rev_I'] = Erev_inh timer.start() print "%s Creating cell populations..." % node_id exc_cells = Population(n_exc, celltype, cell_params, label="Excitatory_Cells") inh_cells = Population(n_inh, celltype, cell_params, label="Inhibitory_Cells") if benchmark == "COBA": ext_stim = Population(20, SpikeSourcePoisson, {'rate' : rate, 'duration' : stim_dur}, label="expoisson") rconn = 0.01 ext_conn = FixedProbabilityConnector(rconn, weights=0.1) q.activate_live_output_for(ext_stim) ext_stim.record() 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.initialize('v', uniformDistr) inh_cells.initialize('v', uniformDistr) print "%s Connecting populations..." % node_id exc_conn = FixedProbabilityConnector(pconn, weights=w_exc, delays=delay) inh_conn = FixedProbabilityConnector(pconn, weights=w_inh, delays=delay) connections={} connections['e2e'] = Projection(exc_cells, exc_cells, exc_conn, target='excitatory', rng=rng)
spikeArray = {'spike_times': [[0]]} populations.append(p.Population(nNeurons, p.IF_curr_exp, cell_params_lif, label='pop_1')) populations.append(p.Population(1, p.SpikeSourceArray, spikeArray, label='inputSpikes_1')) projections.append(p.Projection(populations[0], populations[0], p.FromListConnector(loopConnections))) projections.append(p.Projection(populations[1], populations[0], p.FromListConnector(injectionConnection))) populations[0].record() # Activate live output for the population ExternalDevices.activate_live_output_for( populations[0], database_notify_host="localhost", database_notify_port_num=19999) # Start the simulation p.run(5000) spikes = populations[0].getSpikes(compatible_output=True) if spikes is not None: print spikes pylab.figure() pylab.plot([i[1] for i in spikes], [i[0] for i in spikes], ".") pylab.xlabel('Time/ms') pylab.ylabel('spikes') pylab.title('spikes') pylab.show()
#~ ) learn_layer = {} learn_layer['exc'] = sim.Population(num_exc+1, neuron_model, cell_params_izk_exc, label="Learn layer - exc") learn_layer['inh'] = sim.Population(num_inh+1, neuron_model, cell_params_izk_inh, label="Learn layer - inh") learn_layer['inv'] = sim.Population(img_neurons, neuron_model, cell_params_izk_inv, label="Learn layer - inv") learn_layer['exc'].record() learn_layer['inh'].record() learn_layer['inv'].record() ExternalDevices.activate_live_output_for(learn_layer['exc'], database_notify_host="localhost", database_notify_port_num=19996) ExternalDevices.activate_live_output_for(learn_layer['inh'], database_notify_host="localhost", database_notify_port_num=19997) ExternalDevices.activate_live_output_for(learn_layer['inv'], database_notify_host="localhost", database_notify_port_num=19998) print("Total neurons: %s"%(2*img_neurons+num_exc*2+num_inh+1)) ############ connectors
for i in range(0, n_neurons - 1): loop_forward.append((i, (i + 1) % n_neurons, weight_to_spike, 3)) loop_backward.append(((i + 1) % n_neurons, i, weight_to_spike, 3)) Frontend.Projection(pop_forward, pop_forward, Frontend.FromListConnector(loop_forward)) Frontend.Projection(pop_backward, pop_backward, Frontend.FromListConnector(loop_backward)) # record spikes from the synfire chains so that we can read off valid results # in a safe way afterwards, and verify the behavior pop_forward.record() pop_backward.record() # Activate the sending of live spikes ExternalDevices.activate_live_output_for(pop_forward, database_notify_host="localhost", database_notify_port_num=19997) ExternalDevices.activate_live_output_for(pop_backward, database_notify_host="localhost", database_notify_port_num=19997) # Create a condition to avoid overlapping prints print_condition = Condition() # Run the simulation on spiNNaker Frontend.run(run_time) # Retrieve spikes from the synfire chain population spikes_forward = pop_forward.getSpikes() spikes_backward = pop_backward.getSpikes()
Frontend.Projection(injector_forward, pop_forward, Frontend.OneToOneConnector(weights=weight_to_spike)) # Synfire chain connections where each neuron is connected to its next neuron # NOTE: there is no recurrent connection so that each chain stops once it # reaches the end loop_forward = list() loop_backward = list() for i in range(0, n_neurons - 1): loop_forward.append((i, (i + 1) % n_neurons, weight_to_spike, 3)) Frontend.Projection(pop_forward, pop_forward, Frontend.FromListConnector(loop_forward)) # record spikes from the synfire chains so that we can read off valid results # in a safe way afterwards, and verify the behavior pop_forward.record() # Activate the sending of live spikes ExternalDevices.activate_live_output_for( pop_forward, database_notify_host="localhost", database_notify_port_num=19996) # Create a sender of packets for the forward population def send_input_forward(label, sender): print "Sending forward spike for neuron 0" sender.send_spike(label, 0) # Create a receiver of live spikes def receive_spikes(label, time, neuron_ids): for neuron_id in neuron_ids: print "Received spike at time", time, "from", label, "-", neuron_id # Set up the live connection for sending spikes live_spikes_connection = SpynnakerLiveSpikesConnection( receive_labels=None, local_port=19999, send_labels=["spike_injector_forward"]) # Set up callbacks to occur at the start of simulation live_spikes_connection.add_start_callback("spike_injector_forward", send_input_forward) # if not using the c visualiser, then a new spynnaker live spikes connection
import pyNN.spiNNaker as p import spynnaker_external_devices_plugin.pyNN as q from spinnman.messages.eieio.eieio_type import EIEIOType p.setup(1.0) #pop = p.Population(4, p.SpikeSourceArray, {"spike_times": [[0], [1000], [2000], [3000]]}) pop = p.Population(4, p.SpikeSourcePoisson, {"rate": 5}) q.activate_live_output_for( pop, port=18000, message_type=EIEIOType.KEY_16_BIT, payload_as_time_stamps=False, use_payload_prefix=False) p.run(5000)
Frontend.Projection(pop_forward, pop_forward, Frontend.FromListConnector(loop_forward)) Frontend.Projection(pop_backward, pop_backward, Frontend.FromListConnector(loop_backward)) # Add links to the parrot populations for closed loop calculations Frontend.Projection(pop_forward, pop_forward_parrot, Frontend.OneToOneConnector(weight_to_spike, 1)) Frontend.Projection(pop_backward, pop_backward_parrot, Frontend.OneToOneConnector(weight_to_spike, 1)) # record spikes from the synfire chains so that we can read off valid results # in a safe way afterwards, and verify the behavior pop_forward.record() pop_backward.record() # Activate the sending of live spikes for visualiser ExternalDevices.activate_live_output_for( pop_forward, database_notify_host="localhost", database_notify_port_num=19996) ExternalDevices.activate_live_output_for( pop_backward, database_notify_host="localhost", database_notify_port_num=19996) # Activate the sending of spikes for the python reciever ExternalDevices.activate_live_output_for( pop_forward_parrot, database_notify_host="localhost", database_notify_port_num=19995, port=13333) ExternalDevices.activate_live_output_for( pop_backward_parrot, database_notify_host="localhost", database_notify_port_num=19995, port=13333) # Create a condition to avoid overlapping prints print_condition = Condition() # Create a sender of packets for the forward population def send_input_forward(label, sender):
# The port on which the spiNNaker machine should listen for packets. # Packets to be injected should be sent to this port on the spiNNaker machine cell_params_spike_injector_1 = {'port': spikeInjectionPort1} cell_params_spike_injector_2 = {'port': spikeInjectionPort2} populations = list() projections = list() weight_to_spike = 2.0 pop_spikes_out_1 = spynn.Population(nNeurons1, spynn.IF_curr_exp, cell_params_lif, label=spikeReceivePopLabel1) ExternalDevices.activate_live_output_for( pop_spikes_out_1, port=hostReceivePortPop1 ) #spikes will get transmitted to specfieid port on workstation (else defaults to port set in spynnaker.cfg "live_spike_port" param) populations.append(pop_spikes_out_1) pop_spikes_out_2 = spynn.Population(nNeurons2, spynn.IF_curr_exp, cell_params_lif, label='pop_spikes_out_2') populations.append(pop_spikes_out_2) pop_spikes_in_1 = spynn.Population(nNeurons1, ExternalDevices.SpikeInjector, cell_params_spike_injector_1, label=spikeInjectionPopLabel1) populations.append(pop_spikes_in_1) pop_spikes_in_2 = spynn.Population(nNeurons2,
def __init__(self): # initial call to set up the front end (pynn requirement) Frontend.setup(timestep=1.0, min_delay=1.0, max_delay=144.0) # neurons per population and the length of runtime in ms for the # simulation, as well as the expected weight each spike will contain self.n_neurons = 100 run_time = 100000 weight_to_spike = 2.0 # neural parameters of the IF_curr model used to respond to injected # spikes. # (cell params for a synfire chain) 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': -50.0 } ################################## # Parameters for the injector population. This is the minimal set of # parameters required, which is for a set of spikes where the key is # not important. Note that a virtual key *will* be assigned to the # population, and that spikes sent which do not match this virtual key # will be dropped; however, if spikes are sent using 16-bit keys, they # will automatically be made to match the virtual key. The virtual # key assigned can be obtained from the database. ################################## cell_params_spike_injector = { # The port on which the spiNNaker machine should listen for # packets. Packets to be injected should be sent to this port on # the spiNNaker machine 'port': 12345 } ################################## # Parameters for the injector population. Note that each injector # needs to be given a different port. The virtual key is assigned # here, rather than being allocated later. As with the above, spikes # injected need to match this key, and this will be done automatically # with 16-bit keys. ################################## cell_params_spike_injector_with_key = { # The port on which the spiNNaker machine should listen for # packets. Packets to be injected should be sent to this port on # the spiNNaker machine 'port': 12346, # This is the base key to be used for the injection, which is used # to allow the keys to be routed around the spiNNaker machine. # This assignment means that 32-bit keys must have the high-order # 16-bit set to 0x7; This will automatically be prepended to # 16-bit keys. 'virtual_key': 0x70000 } # create synfire populations (if cur exp) pop_forward = Frontend.Population(self.n_neurons, Frontend.IF_curr_exp, cell_params_lif, label='pop_forward') pop_backward = Frontend.Population(self.n_neurons, Frontend.IF_curr_exp, cell_params_lif, label='pop_backward') # Create injection populations injector_forward = Frontend.Population( self.n_neurons, ExternalDevices.SpikeInjector, cell_params_spike_injector_with_key, label='spike_injector_forward') injector_backward = Frontend.Population( self.n_neurons, ExternalDevices.SpikeInjector, cell_params_spike_injector, label='spike_injector_backward') # Create a connection from the injector into the populations Frontend.Projection( injector_forward, pop_forward, Frontend.OneToOneConnector(weights=weight_to_spike)) Frontend.Projection( injector_backward, pop_backward, Frontend.OneToOneConnector(weights=weight_to_spike)) # Synfire chain connections where each neuron is connected to its next # neuron # NOTE: there is no recurrent connection so that each chain stops once # it reaches the end loop_forward = list() loop_backward = list() for i in range(0, self.n_neurons - 1): loop_forward.append( (i, (i + 1) % self.n_neurons, weight_to_spike, 3)) loop_backward.append( ((i + 1) % self.n_neurons, i, weight_to_spike, 3)) Frontend.Projection(pop_forward, pop_forward, Frontend.FromListConnector(loop_forward)) Frontend.Projection(pop_backward, pop_backward, Frontend.FromListConnector(loop_backward)) # record spikes from the synfire chains so that we can read off valid # results in a safe way afterwards, and verify the behavior pop_forward.record() pop_backward.record() # Activate the sending of live spikes ExternalDevices.activate_live_output_for( pop_forward, database_notify_host="localhost", database_notify_port_num=19996) ExternalDevices.activate_live_output_for( pop_backward, database_notify_host="localhost", database_notify_port_num=19996) # set up gui from multiprocessing import Process p = Process(target=GUI, args=[self.n_neurons]) p.start() # Run the simulation on spiNNaker Frontend.run(run_time) # Retrieve spikes from the synfire chain population spikes_forward = pop_forward.getSpikes() spikes_backward = pop_backward.getSpikes() # If there are spikes, plot using matplotlib if len(spikes_forward) != 0 or len(spikes_backward) != 0: pylab.figure() if len(spikes_forward) != 0: pylab.plot([i[1] for i in spikes_forward], [i[0] for i in spikes_forward], "b.") if len(spikes_backward) != 0: pylab.plot([i[1] for i in spikes_backward], [i[0] for i in spikes_backward], "r.") pylab.ylabel('neuron id') pylab.xlabel('Time/ms') pylab.title('spikes') pylab.show() else: print "No spikes received" # Clear data structures on spiNNaker to leave the machine in a clean # state for future executions Frontend.end() p.join()
# 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') # Build inhibitory plasticity model stdp_model = sim.STDPMechanism( timing_dependence = extra_sim.Vogels2011Rule(alpha=0.12,tau=20.0), weight_dependence = sim.AdditiveWeightDependence(w_min=0.0, w_max=1.0, A_plus=0.0005), mad=True ) # Make inhibitory->excitatory projections sim.Projection(in_pop, ex_pop, sim.FixedProbabilityConnector(0.02, weights=0), target='inhibitory', synapse_dynamics=sim.SynapseDynamics(slow=stdp_model)) # Activate live output for excitatory spikes ext.activate_live_output_for(ex_pop) ext.activate_live_output_for(in_pop) # Run simulation sim.run(5000) # End simulation on SpiNNaker sim.end()
cell_params_spike_injector_new = {"virtual_key": 0x70800, "port": 12345} populations = list() projections = list() weight_to_spike = 2.0 populations.append(FrontEnd.Population(nNeurons, FrontEnd.IF_curr_exp, cell_params_lif, label="pop_1")) populations.append( FrontEnd.Population( nNeurons, ExternalDevices.SpikeInjector, cell_params_spike_injector_new, label="spike_injector_1" ) ) populations[0].record() ExternalDevices.activate_live_output_for(populations[0]) projections.append( FrontEnd.Projection(populations[1], populations[0], FrontEnd.OneToOneConnector(weights=weight_to_spike)) ) loopConnections = list() for i in range(0, nNeurons - 1): singleConnection = (i, ((i + 1) % nNeurons), weight_to_spike, 3) loopConnections.append(singleConnection) projections.append(FrontEnd.Projection(populations[0], populations[0], FrontEnd.FromListConnector(loopConnections))) FrontEnd.run(run_time)
Frontend.Projection(ret_left, collector, Frontend.OneToOneConnector(weights=w2, delays=1.6), target='excitatory') Frontend.Projection(ret_right, inh_right, Frontend.OneToOneConnector(weights=w1, delays=0.2), target='excitatory') Frontend.Projection(ret_right, inh_left, Frontend.OneToOneConnector(weights=-w1, delays=0.2), target='inhibitory') Frontend.Projection(ret_right, collector, Frontend.OneToOneConnector(weights=w2, delays=1.6), target='excitatory') Frontend.Projection(inh_left, collector, Frontend.OneToOneConnector(weights=w2, delays=0.2), target='inhibitory') Frontend.Projection(inh_right, collector, Frontend.OneToOneConnector(weights=w2, delays=0.2), target='inhibitory') # record spikes from the synfire chains so that we can read off valid results # in a safe way afterwards, and verify the behavior collector.record() inh_left.record() inh_right.record() # Activate the sending of live spikes ExternalDevices.activate_live_output_for(inh_left, database_notify_host="localhost",database_notify_port_num=19996) ExternalDevices.activate_live_output_for(collector, database_notify_host="localhost",database_notify_port_num=19996) ExternalDevices.activate_live_output_for(inh_right, database_notify_host="localhost",database_notify_port_num=19996) # Create a sender of packets for the forward population def send_spike_retina(label, sender): print "Sending spike from ", label sender.send_spike(label, 0, send_full_keys=True) # if not using the c visualiser, then a new spynnaker live spikes connection # is created to define that there are python code which receives the # outputted spikes. def receive_spike_cell(label, time, neuron_ids): print label, " received a spike at time ", time def threadLeft_run(liveConnectionRetina): retinasSpikes = [(1, 0, 0, 0), (100, 0, 0, 0), (250, 0, 0, 0), (300, 0, 0, 0)]#cp.load(open('../src/realInput/timesorted_50_persAway.p', 'rb'))
import pyNN.spiNNaker as p import spynnaker_external_devices_plugin.pyNN as q from spinnman.messages.eieio.eieio_type import EIEIOType p.setup(1.0) #pop = p.Population(4, p.SpikeSourceArray, {"spike_times": [[0], [1000], [2000], [3000]]}) pop = p.Population(4, p.SpikeSourcePoisson, {"rate": 5}) q.activate_live_output_for(pop, port=18000, message_type=EIEIOType.KEY_16_BIT, payload_as_time_stamps=False, use_payload_prefix=False) p.run(5000)
def memory(subjects, locations, objects): pop_subject = p.Population(subjects, p.IF_curr_exp, cell_params_lif, label='pop_subject') pop_locations = p.Population(locations, p.IF_curr_exp, cell_params_lif, label='pop_locations') pop_object = p.Population(objects, p.IF_curr_exp, cell_params_lif, label='pop_object') query_pop_subject = p.Population(subjects, p.IF_curr_exp, cell_params_lif, label='query_pop_subject') query_pop_locations = p.Population(locations, p.IF_curr_exp, cell_params_lif, label='query_pop_locations') query_pop_object = p.Population(objects, p.IF_curr_exp, cell_params_lif, label='query_pop_object') who_gate = p.Population(subjects, p.IF_curr_exp, cell_params_lif, label='who_gate') where_gate = p.Population(locations, p.IF_curr_exp, cell_params_lif, label='where_gate') what_gate = p.Population(objects, p.IF_curr_exp, cell_params_lif, label='what_gate') #symmetric STDP rule # Plastic Connection between pre_pop and post_pop t_rule = p.SpikePairRule(tau_plus=0.5, tau_minus=0.5) w_rule = p.AdditiveWeightDependence(w_min=0.0, w_max=weight_to_spike, A_plus=weight_to_spike, A_minus=-weight_to_spike) stdp_model = p.STDPMechanism( timing_dependence = t_rule, weight_dependence = w_rule ) s_d = p.SynapseDynamics(slow = stdp_model) statement_binding_sub_loc = p.Projection(pop_subject, pop_locations, p.AllToAllConnector(weights=0, delays=1), synapse_dynamics = s_d, target="excitatory") statement_binding_loc_sub = p.Projection(pop_locations, pop_subject, p.AllToAllConnector(weights=0, delays=1), synapse_dynamics = s_d, target="excitatory") statement_binding_sub_obj = p.Projection(pop_subject, pop_object, p.AllToAllConnector(weights=0, delays=1), synapse_dynamics = s_d, target="excitatory") statement_binding_obj_sub = p.Projection(pop_object, pop_subject, p.AllToAllConnector(weights=0, delays=1), synapse_dynamics = s_d, target="excitatory") statement_binding_obj_loc = p.Projection(pop_object, pop_locations, p.AllToAllConnector(weights=0, delays=1), synapse_dynamics = s_d, target="excitatory") statement_binding_loc_obj = p.Projection(pop_locations, pop_object, p.AllToAllConnector(weights=0, delays=1), synapse_dynamics = s_d, target="excitatory") query_subject = p.Projection(query_pop_subject, pop_subject, p.OneToOneConnector(weights=weight_to_spike, delays=1)) query_locations = p.Projection(query_pop_locations, pop_locations, p.OneToOneConnector(weights=weight_to_spike, delays=1)) query_object = p.Projection(query_pop_object, pop_object, p.OneToOneConnector(weights=weight_to_spike, delays=1)) input_subjects = p.Population(subjects, p.IF_curr_exp, cell_params_lif, label='input_subjects') input_locations = p.Population(locations, p.IF_curr_exp, cell_params_lif, label='input_locations') input_objects = p.Population(objects, p.IF_curr_exp, cell_params_lif, label='input_objects') network_stabilizer = p.Population(1, p.IF_curr_exp, cell_params_lif, label='network_stabilizer') stabilize_subjects = p.Projection(network_stabilizer, pop_subject, p.AllToAllConnector(weights = weight_to_inhibit, delays = 1), target = "inhibitory") stabilize_locations = p.Projection(network_stabilizer, pop_locations, p.AllToAllConnector(weights = weight_to_inhibit, delays = 1), target = "inhibitory") stabilize_objects = p.Projection(network_stabilizer, pop_object, p.AllToAllConnector(weights = weight_to_inhibit, delays = 1), target = "inhibitory") list_connector = [[i, i+1, weight_to_spike, delay_reps] for i in xrange (input_reps-1)] input_pop_subject = list() input_pop_subject_int_conn = list() input_subject_conn = list() input_subject_injection = list() input_subject_inh_locations = list() input_subject_inh_conn = list() for i in xrange (subjects): input_pop_subject.append( p.Population(input_reps, p.IF_curr_exp, cell_params_lif, label='pop_subject_input_{0:d}'.format(i)) ) input_pop_subject_int_conn.append( p.Projection(input_pop_subject[i], input_pop_subject[i], p.FromListConnector(list_connector)) ) list_connector2 = list() for j in xrange (input_reps): list_connector2.append([j, i, 1.5*weight_to_spike, 1]) # print "Subjects {0:d}: {1:s}".format(i, list_connector2) input_subject_conn.append( p.Projection(input_pop_subject[i], pop_subject, p.FromListConnector(list_connector2)) ) input_subject_injection.append( p.Projection(input_subjects, input_pop_subject[i], p.FromListConnector([[i, 0, weight_to_spike, 1]])) ) input_subject_inh_locations = p.Projection(input_pop_subject[i], pop_locations, p.AllToAllConnector(weights = 0.5*weight_to_spike, delays = 1), target='inhibitory') input_subject_inh_objects = p.Projection(input_pop_subject[i], pop_object, p.AllToAllConnector(weights = 0.5*weight_to_spike, delays = 1), target='inhibitory') input_subject_inh_conn.append( p.Projection(input_pop_subject[i], network_stabilizer, p.FromListConnector([[input_reps-1, 0, weight_to_spike, 1]])) ) input_pop_location = list() input_pop_location_int_conn = list() input_location_conn = list() input_location_injection = list() input_location_inh_conn = list() for i in xrange (locations): input_pop_location.append( p.Population(input_reps, p.IF_curr_exp, cell_params_lif, label='pop_location_input_{0:d}'.format(i)) ) input_pop_location_int_conn.append( p.Projection(input_pop_location[i], input_pop_location[i], p.FromListConnector(list_connector)) ) list_connector2 = list() for j in xrange (input_reps): list_connector2.append([j, i, 1.5*weight_to_spike, 1]) # print "Locations {0:d}: {1:s}".format(i, list_connector2) input_location_conn.append( p.Projection(input_pop_location[i], pop_locations, p.FromListConnector(list_connector2)) ) input_location_injection.append( p.Projection(input_locations, input_pop_location[i], p.FromListConnector([[i, 0, weight_to_spike, 1]])) ) input_location_inh_subjects = p.Projection(input_pop_location[i], pop_subject, p.AllToAllConnector(weights = 0.5*weight_to_spike, delays = 1), target='inhibitory') input_location_inh_objects = p.Projection(input_pop_location[i], pop_object, p.AllToAllConnector(weights = 0.5*weight_to_spike, delays = 1), target='inhibitory') input_location_inh_conn.append( p.Projection(input_pop_location[i], network_stabilizer, p.FromListConnector([[input_reps-1, 0, weight_to_spike, 1]])) ) input_pop_object = list() input_pop_object_int_conn = list() input_object_conn = list() input_object_injection = list() input_object_inh_conn = list() for i in xrange (objects): input_pop_object.append( p.Population(input_reps, p.IF_curr_exp, cell_params_lif, label='pop_object_input_{0:d}'.format(i)) ) input_pop_object_int_conn.append( p.Projection(input_pop_object[i], input_pop_object[i], p.FromListConnector(list_connector)) ) list_connector2 = list() for j in xrange (input_reps): list_connector2.append([j, i, 1.5*weight_to_spike, 1]) #print "Objects {0:d}: {1:s}".format(i, list_connector2) input_object_conn.append( p.Projection(input_pop_object[i], pop_object, p.FromListConnector(list_connector2)) ) input_object_injection.append( p.Projection(input_objects, input_pop_object[i], p.FromListConnector([[i, 0, weight_to_spike, 1]]), target="excitatory")) input_object_inh_subjects = p.Projection(input_pop_object[i], pop_subject, p.AllToAllConnector(weights = 0.5*weight_to_spike, delays = 1), target='inhibitory') input_object_inh_locations = p.Projection(input_pop_object[i], pop_locations, p.AllToAllConnector(weights = 0.5*weight_to_spike, delays = 1), target='inhibitory') input_object_inh_conn.append( p.Projection(input_pop_object[i], network_stabilizer, p.FromListConnector([[input_reps-1, 0, weight_to_spike, 1]])) ) who = p.Population(1, p.IF_curr_exp, cell_params_lif, label='who') where = p.Population(1, p.IF_curr_exp, cell_params_lif, label='where') what = p.Population(1, p.IF_curr_exp, cell_params_lif, label='what') who_gating = p.Projection(pop_subject, who_gate, p.OneToOneConnector(weights = weight_to_gate, delays = 1)) where_gating = p.Projection(pop_locations, where_gate, p.OneToOneConnector(weights = weight_to_gate, delays = 1)) what_gating = p.Projection(pop_object, what_gate, p.OneToOneConnector(weights = weight_to_gate, delays = 1)) who_control = p.Projection(who, who_gate, p.AllToAllConnector(weights = weight_to_control, delays = 1)) where_control = p.Projection(where, where_gate, p.AllToAllConnector(weights = weight_to_control, delays = 1)) what_control = p.Projection(what, what_gate, p.AllToAllConnector(weights = weight_to_control, delays = 1)) #once the output is given, stabilize the network who_gate_inh_conn = list() where_gate_inh_conn = list() what_gate_inh_conn = list() who_self_inh = p.Projection(who_gate, who_gate, p.AllToAllConnector(weights=2*weight_to_inhibit, delays=1), target="inhibitory") where_self_inh = p.Projection(where_gate, where_gate, p.OneToOneConnector(weights=2*weight_to_inhibit, delays=1), target="inhibitory") what_self_inh = p.Projection(what_gate, what_gate, p.OneToOneConnector(weights=2*weight_to_inhibit, delays=1), target="inhibitory") who_gate_inh_conn.append( p.Projection(who_gate, pop_subject, p.AllToAllConnector(weights = weight_to_inhibit, delays = 1), target="inhibitory") ) #who_gate_inh_conn.append( p.Projection(who_gate, pop_locations, p.AllToAllConnector(weights = weight_to_inhibit, delays = 1), target="inhibitory") ) #who_gate_inh_conn.append( p.Projection(who_gate, pop_object, p.AllToAllConnector(weights = weight_to_inhibit, delays = 1), target="inhibitory") ) #where_gate_inh_conn.append( p.Projection(where_gate, pop_subject, p.AllToAllConnector(weights = weight_to_inhibit, delays = 1), target="inhibitory") ) where_gate_inh_conn.append( p.Projection(where_gate, pop_locations, p.AllToAllConnector(weights = weight_to_inhibit, delays = 1), target="inhibitory") ) #where_gate_inh_conn.append( p.Projection(where_gate, pop_object, p.AllToAllConnector(weights = weight_to_inhibit, delays = 1), target="inhibitory") ) #what_gate_inh_conn.append( p.Projection(what_gate, pop_subject, p.AllToAllConnector(weights = weight_to_inhibit, delays = 1), target="inhibitory") ) #what_gate_inh_conn.append( p.Projection(what_gate, pop_locations, p.AllToAllConnector(weights = weight_to_inhibit, delays = 1), target="inhibitory") ) what_gate_inh_conn.append( p.Projection(what_gate, pop_object, p.AllToAllConnector(weights = weight_to_inhibit, delays = 1), target="inhibitory") ) who_network_stabilize = p.Projection(who_gate, network_stabilizer, p.AllToAllConnector(weights = weight_to_spike, delays = 1), target="excitatory") where_network_stabilize = p.Projection(where_gate, network_stabilizer, p.AllToAllConnector(weights = weight_to_spike, delays = 1), target="excitatory") what_network_stabilize = p.Projection(what_gate, network_stabilizer, p.AllToAllConnector(weights = weight_to_spike, delays = 1), target="excitatory") total_input_neurons = 2 * (subjects + locations + objects) + 3 external_conn_pop = p.Population(total_input_neurons, ExternalDevices.SpikeInjector, external_conns_params, 'external_conn_pop') current_input_neuron = 0 list_connector_subject = [[current_input_neuron + i, i, weight_to_spike, 1] for i in xrange(subjects)] current_input_neuron += subjects list_connector_location = [[current_input_neuron + i, i, weight_to_spike, 1] for i in xrange(locations)] current_input_neuron += locations list_connector_object = [[current_input_neuron + i, i, weight_to_spike, 1] for i in xrange(objects)] current_input_neuron += objects list_connector_query_subject = [[current_input_neuron + i, i, weight_to_spike, 1] for i in xrange(subjects)] current_input_neuron += subjects list_connector_query_location = [[current_input_neuron + i, i, weight_to_spike, 1] for i in xrange(locations)] current_input_neuron += locations list_connector_query_object = [[current_input_neuron + i, i, weight_to_spike, 1] for i in xrange(objects)] current_input_neuron += objects list_connector_query_who = [[current_input_neuron, 0, weight_to_spike, 6]] current_input_neuron += 1 list_connector_query_where = [[current_input_neuron, 0, weight_to_spike, 6]] current_input_neuron += 1 list_connector_query_what = [[current_input_neuron, 0, weight_to_spike, 6]] external_injection_proj = list() p.Projection(external_conn_pop, input_subjects, p.FromListConnector(list_connector_subject), target='excitatory') p.Projection(external_conn_pop, input_locations, p.FromListConnector(list_connector_location), target='excitatory') p.Projection(external_conn_pop, input_objects, p.FromListConnector(list_connector_object), target='excitatory') p.Projection(external_conn_pop, query_pop_subject, p.FromListConnector(list_connector_query_subject), target='excitatory') p.Projection(external_conn_pop, query_pop_locations, p.FromListConnector(list_connector_query_location), target='excitatory') p.Projection(external_conn_pop, query_pop_object, p.FromListConnector(list_connector_query_object), target='excitatory') p.Projection(external_conn_pop, who, p.FromListConnector(list_connector_query_who), target='excitatory') p.Projection(external_conn_pop, where, p.FromListConnector(list_connector_query_where), target='excitatory') p.Projection(external_conn_pop, what, p.FromListConnector(list_connector_query_what), target='excitatory') ExternalDevices.activate_live_output_for(who_gate) ExternalDevices.activate_live_output_for(where_gate) ExternalDevices.activate_live_output_for(what_gate) input_populations = { 'input_subjects': input_subjects, 'input_locations': input_locations, 'input_objects': input_objects, 'query_pop_subject': query_pop_subject, 'query_pop_locations': query_pop_locations, 'query_pop_object': query_pop_object, 'who': who, 'where': where, 'what': what } output_populations = { 'who_gate': who_gate, 'where_gate': where_gate, 'what_gate': what_gate } projections = { 'statement_binding_sub_loc': statement_binding_sub_loc, 'statement_binding_loc_sub': statement_binding_loc_sub, 'statement_binding_sub_obj': statement_binding_sub_obj, 'statement_binding_obj_sub': statement_binding_obj_sub, 'statement_binding_obj_loc': statement_binding_obj_loc, 'statement_binding_loc_obj': statement_binding_loc_obj } state_populations = { 'pop_subject': pop_subject, 'pop_locations': pop_locations, 'pop_object': pop_object } who.record() where.record() what.record() who_gate.record() where_gate.record() what_gate.record() pop_subject.record() pop_locations.record() pop_object.record() return [input_populations, state_populations, output_populations, projections] ''' #simulate a sentence to link first subject and first location #and then ask for the location of the first subject injection1a = {'spike_times' : [[50]]} injection1b = {'spike_times' : [[250]]} injection1c = {'spike_times' : [[450]]} injection2 = {'spike_times' : [[800]]} injection3 = {'spike_times' : [[806]]} ss1a = p.Population(1, p.SpikeSourceArray, injection1a) ss1b = p.Population(1, p.SpikeSourceArray, injection1b) ss1c = p.Population(1, p.SpikeSourceArray, injection1c) ss2 = p.Population(1, p.SpikeSourceArray, injection2) ss3 = p.Population(1, p.SpikeSourceArray, injection3) #john has a ball ss1a_inj_1 = p.Projection(ss1a, input_subjects, p.FromListConnector([[0, 0, weight_to_spike, 1]])) ss1a_inj_2 = p.Projection(ss1a, input_objects, p.FromListConnector([[0, 0, weight_to_spike, 1]])) #john is in the kitchen ss1b_inj_1 = p.Projection(ss1b, input_subjects, p.FromListConnector([[0, 0, weight_to_spike, 1]])) ss1b_inj_1 = p.Projection(ss1b, input_locations, p.FromListConnector([[0, 0, weight_to_spike, 1]])) #sergio is in the kitchen ss1c_inj_1 = p.Projection(ss1c, input_subjects, p.FromListConnector([[0, 1, weight_to_spike, 1]])) ss1c_inj_1 = p.Projection(ss1c, input_locations, p.FromListConnector([[0, 0, weight_to_spike, 1]])) #who has the ball #ss2_inj = p.Projection(ss2, query_pop_object, p.FromListConnector([[0, 0, weight_to_spike, 1]])) #who is in the kitchen ss2_inj = p.Projection(ss2, query_pop_locations, p.FromListConnector([[0, 0, weight_to_spike, 1]])) ss3_inj = p.Projection(ss3, who, p.FromListConnector([[0, 0, weight_to_spike, 1]])) ''' ''' #recording section for i in xrange(subjects): input_pop_subject[i].record() for i in xrange(locations): input_pop_location[i].record() for i in xrange(objects): input_pop_object[i].record() pop_subject.record() pop_locations.record() pop_object.record() pop_subject.record_v() pop_subject.record_gsyn() pop_locations.record_v() pop_locations.record_gsyn() network_stabilizer.record() who.record() where.record() what.record() who_gate.record() where_gate.record() what_gate.record() where_gate.record_v() where_gate.record_gsyn() query_pop_locations.record() query_pop_object.record() query_pop_subject.record() ''' ''' #retrieving section pop_subject_spikes = pop_subject.getSpikes(compatible_output=True) pop_subject_v = pop_subject.get_v() pop_subject_i = pop_subject.get_gsyn() pop_locations_spikes = pop_locations.getSpikes(compatible_output=True) pop_object_spikes = pop_object.getSpikes(compatible_output=True) who_spikes = who.getSpikes(compatible_output=True) where_spikes = where.getSpikes(compatible_output=True) what_spikes = what.getSpikes(compatible_output=True) who_gate_spikes = who_gate.getSpikes(compatible_output=True) where_gate_spikes = where_gate.getSpikes(compatible_output=True) what_gate_spikes = what_gate.getSpikes(compatible_output=True) where_gate_v = where_gate.get_v() where_gate_gsyn = where_gate.get_gsyn() query_pop_locations_spikes = query_pop_locations.getSpikes(compatible_output=True) query_pop_object_spikes = query_pop_object.getSpikes(compatible_output=True) query_pop_subject_spikes = query_pop_subject.getSpikes(compatible_output=True) network_stabilizer_spikes = network_stabilizer.getSpikes(compatible_output=True) input_pop_subject_spikes = list() input_pop_subject_spikes.append(input_pop_subject[0].getSpikes(compatible_output=True)) input_pop_subject_spikes.append(input_pop_subject[1].getSpikes(compatible_output=True)) input_pop_subject_spikes.append(input_pop_subject[2].getSpikes(compatible_output=True)) input_pop_subject_spikes.append(input_pop_subject[3].getSpikes(compatible_output=True)) input_pop_subject_spikes.append(input_pop_subject[4].getSpikes(compatible_output=True)) input_pop_location_spikes = list() input_pop_location_spikes.append(input_pop_location[0].getSpikes(compatible_output=True)) input_pop_location_spikes.append(input_pop_location[1].getSpikes(compatible_output=True)) input_pop_location_spikes.append(input_pop_location[2].getSpikes(compatible_output=True)) input_pop_location_spikes.append(input_pop_location[3].getSpikes(compatible_output=True)) input_pop_location_spikes.append(input_pop_location[4].getSpikes(compatible_output=True)) input_pop_object_spikes = list() input_pop_object_spikes.append(input_pop_object[0].getSpikes(compatible_output=True)) input_pop_object_spikes.append(input_pop_object[1].getSpikes(compatible_output=True)) input_pop_object_spikes.append(input_pop_object[2].getSpikes(compatible_output=True)) input_pop_object_spikes.append(input_pop_object[3].getSpikes(compatible_output=True)) input_pop_object_spikes.append(input_pop_object[4].getSpikes(compatible_output=True)) print pop_subject_i[800:820] print pop_subject_i[1800:1820] w_sub_loc = statement_binding_sub_loc.getWeights() w_loc_sub = statement_binding_loc_sub.getWeights() w_sub_obj = statement_binding_sub_obj.getWeights() w_obj_sub = statement_binding_obj_sub.getWeights() w_obj_loc = statement_binding_obj_loc.getWeights() w_loc_obj = statement_binding_loc_obj.getWeights() ''' '''
"i_offset": 0, } cell_params_ext_dev = {"port": 34567} populations = list() projections = list() weight_to_spike = 20 populations.append(p.Population(nNeurons, p.IF_curr_exp, cell_params_lif_in, label="pop_%d" % 0)) populations[0].randomInit(v_distr) q.activate_live_output_for( populations[0], port=34567, host="130.88.198.209", tag=2, payload_as_time_stamps=False, use_payload_prefix=False ) # populations.append(Population(nNeurons, IF_curr_exp, cell_params_lif, label='pop_%d' % i)) pop_external = p.Population(nNeurons, q.SpikeInjector, cell_params_ext_dev, label="Babel_Dummy") populations.append(p.Population(nNeurons, p.IF_curr_exp, cell_params_lif, label="pop_%d" % 1)) projections.append(p.Projection(pop_external, populations[1], p.OneToOneConnector(weights=weight_to_spike, delays=10))) # populations[0].record_v() # at the moment is only possible to observe one population per core populations[1].record_v() for pop in populations: pop.record(to_file=False) # sends spike to the Monitoring application
delays.append(float(delay)) singleConnection = (i, ((i + 1) % nNeurons), weight_to_spike, delay) connections.append(singleConnection) injectionConnection = [(0, 0, weight_to_spike, 1)] spikeArray = {"spike_times": [[0]]} populations.append(p.Population(nNeurons, p.IF_curr_exp, cell_params_lif, label="pop_1")) populations.append(p.Population(1, p.SpikeSourceArray, spikeArray, label="inputSpikes_1")) # populations[0].set_mapping_constraint({"x": 1, "y": 0}) projections.append(p.Projection(populations[0], populations[0], p.FromListConnector(connections))) projections.append(p.Projection(populations[1], populations[0], p.FromListConnector(injectionConnection))) q.activate_live_output_for(populations[0]) populations[0].set_constraint(p.PlacerChipAndCoreConstraint(0, 0, 4)) populations[1].set_constraint(p.PlacerChipAndCoreConstraint(0, 0, 5)) run_time = 100 print "Running for {} ms".format(run_time) populations[0].record() p.run(run_time) v = None gsyn = None spikes = None spikes = populations[0].getSpikes(compatible_output=True) # print(projections[0].getWeights()) # print(projections[0].getDelays())
#anim = animation.FuncAnimation(fig, animate, init_func=init, interval=time_period) #pylab.show() #~ cv2.imshow("new window", out) #~ cv2.waitKey(1) sim.setup(timestep=1.0, min_delay=1.0, max_delay=10.0) # echo population ---------------------------------------------------------- target = sim.Population(num_neurons, model, cell_params, label="echo") target.record() ExternalDevices.activate_live_output_for(target, database_notify_host="localhost", database_notify_port_num=live_out_port) live_spikes_receive = SpynnakerLiveSpikesConnection(receive_labels=["echo",], local_port=receive_port, send_labels=None) live_spikes_receive.add_receive_callback("echo", receive_spikes) # END: echo population ---------------------------------------------------------- # stim population ---------------------------------------------------------- stimulation = sim.Population(num_neurons, ImageDvsEmulatorDevice, cam_params, label="Webcam population")
def __init__(self, n_neurons_source=None, Spike_Source_Class=None, Spike_Sink_Class=None, output_population=None, ros_topic_send='to_spinnaker', ros_topic_recv='from_spinnaker', clk_rate=1000, ros_output_rate=10, benchmark=False): # Members self.n_neurons = n_neurons_source if n_neurons_source is not None else 1 self._Spike_Source_Class = Spike_Source_Class self._Spike_Sink_Class = Spike_Sink_Class self.interface_id = self._instance_counter.next() self._output_population = output_population self.send_topic = ros_topic_send self.recv_topic = ros_topic_recv self._clk_rate = clk_rate # in Hz self._ros_output_rate = ros_output_rate # Hz self._benchmark = benchmark self._injector_label = 'injector{}'.format(self.interface_id) spike_injector_port = 12345 + self.interface_id local_port = 19999 + self.interface_id local_recv_port = 17895 self._database_notify_port = local_port self._queue_ros_spinnaker = Queue() self._queue_spinnaker_ros = Queue() # My own "population" data structures to send and receive spikes, initialized later. self._spike_source = None self._spike_sink = None send_labels = [self._injector_label] rcv_labels = None self.sender_active = n_neurons_source is not None and self._Spike_Source_Class is not None self.receiver_active = self._output_population is not None and self._Spike_Sink_Class is not None if self.receiver_active: rcv_labels = [self._output_population.label] self._spike_injector_population = pynn.Population(size=self.n_neurons, cellclass=ExternalDevices.SpikeInjector, cellparams={'port': spike_injector_port, 'database_notify_port_num':local_port}, label=self._injector_label) self._spinnaker_connection = LiveSpikesConnection(receive_labels=rcv_labels, local_port=local_port, send_labels=send_labels) self._spinnaker_connection.add_start_callback(self._injector_label, self._init_ros_node) # spinnaker thread! if self.receiver_active: self._spinnaker_connection.add_receive_callback(self._output_population.label, self._incoming_spike_callback) ExternalDevices.activate_live_output_for(self._output_population, port=local_recv_port+self.interface_id, database_notify_port_num=self._database_notify_port)
'tau_syn_E': 5.0, 'tau_syn_I': 5.0, 'v_reset': -70.0, 'v_rest': -65.0, 'v_thresh': -50.0 } weight_to_spike = 2. rate_weight = 1.5 delay = 1 rate_delay = 16 pool_size = 1 # Create breakout population and activate live output for it breakout_pop = p.Population(1, spinn_breakout.Breakout, {}, label="breakout") ex.activate_live_output_for(breakout_pop, host="0.0.0.0", port=UDP_PORT) # Create spike injector to inject keyboard input into simulation key_input = p.Population(2, ex.SpikeInjector, {"port": 12367}, label="key_input") key_input_connection = SpynnakerLiveSpikesConnection(send_labels=["key_input"]) # Connect key spike injector to breakout population p.Projection(key_input, breakout_pop, p.OneToOneConnector(weights=2)) # Create visualiser visualiser = spinn_breakout.Visualiser(UDP_PORT, key_input_connection, x_res=X_RESOLUTION, y_res=Y_RESOLUTION,