def test_lif_current(self): """ Simulates one LIF neuron and checks the membrane-potential trace matches reference data. TODO add assertion on comparison, rather than just graphing the result. TODO take parameter for machine hostname. """ print "test_lif_current..." pynn.setup(**{'machine':'bluu', 'debug':False}) #TODO take machine parameter lif = {"v_rest":-70.0, "v_reset":-70.0, "v_thresh":-50.0, # mV "tau_m":40.0, "tau_syn_E":20.0, "tau_syn_I":5.0, # mS "tau_refrac":1.0, "cm":40.0/50.0, "i_offset":0.0} # ms, nF, nA pop = pynn.Population(1, pynn.IF_curr_exp, lif) pop.set("i_offset", 0.5) pop.record_v() pynn.run(1000) with open('data/test_lif_current.pickle', 'r') as f: data = f.read() trace = pickle.loads(data) fig = pylab.figure(figsize=(8.0, 5.7)) ax = fig.add_subplot(1,1,1) ax.plot(pop.get_v()[:,2]) ax.plot(trace) pylab.show() pynn.end()
def test_lif_current(self): """ Simulates one LIF neuron and checks the membrane-potential trace matches reference data. TODO add assertion on comparison, rather than just graphing the result. TODO take parameter for machine hostname. """ print "test_lif_current..." pynn.setup(**{ 'machine': 'bluu', 'debug': False }) #TODO take machine parameter lif = { "v_rest": -70.0, "v_reset": -70.0, "v_thresh": -50.0, # mV "tau_m": 40.0, "tau_syn_E": 20.0, "tau_syn_I": 5.0, # mS "tau_refrac": 1.0, "cm": 40.0 / 50.0, "i_offset": 0.0 } # ms, nF, nA pop = pynn.Population(1, pynn.IF_curr_exp, lif) pop.set("i_offset", 0.5) pop.record_v() pynn.run(1000) with open('data/test_lif_current.pickle', 'r') as f: data = f.read() trace = pickle.loads(data) fig = pylab.figure(figsize=(8.0, 5.7)) ax = fig.add_subplot(1, 1, 1) ax.plot(pop.get_v()[:, 2]) ax.plot(trace) pylab.show() pynn.end()
# Plastic Connections between pre_pop and post_pop stdp_model = sim.STDPMechanism( timing_dependence = sim.SpikePairRule(tau_plus = 20.0, tau_minus = 50.0), weight_dependence = sim.AdditiveWeightDependence(w_min = 0.1, w_max = 1, A_plus=0.02, A_minus = 0.02) ) prepostpro = sim.Projection(pre_pop, post_pop, sim.OneToOneConnector(weights=1.0), synapse_dynamics = sim.SynapseDynamics(slow= stdp_model) ) # Record spikes 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") def plot_spikes(spikes, title): if spikes != None: pylab.figure() pylab.xlim((0, sim_time)) pylab.plot([i[1] for i in spikes], [i[0] for i in spikes], ".") pylab.xlabel('Time/ms') pylab.ylabel('spikes') pylab.title(title)
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_v() populations[0].record_gsyn() populations[0].record(visualiser_mode=modes.RASTER) p.run(5000) v = None gsyn = None spikes = None v = populations[0].get_v(compatible_output=True) gsyn = populations[0].get_gsyn(compatible_output=True) spikes = populations[0].getSpikes(compatible_output=True) if spikes != 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')
singleConnection = (i, ((i + 1) % nNeurons), weight_to_spike, delay) loopConnections.append(singleConnection) injectionConnection = [(0, 0, weight_to_spike, delay)] spikeArray = {'spike_times': [[50]]} populations.append(p.Population(nNeurons, p.IZK_curr_exp, cell_params_izk, 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_v() populations[0].record() p.run(500) v = None spikes = None v = populations[0].get_v(compatible_output=True) spikes = populations[0].getSpikes(compatible_output=True) if spikes != None: 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() else:
) # +-------------------------------------------------------------------+ # | Simulation and results | # +-------------------------------------------------------------------+ # Record neurons' potentials pre_pop.record_v() post_pop.record_v() # Record spikes pre_pop.record() post_pop.record() # Run simulation sim.run(simtime) print("Weights:", plastic_projection.getWeights()) def plot_spikes(spikes, title): if spikes != None: pylab.figure() pylab.xlim((0, simtime)) pylab.plot([i[1] for i in spikes], [i[0] for i in spikes], ".") pylab.xlabel('Time/ms') pylab.ylabel('spikes') pylab.title(title) else: print "No spikes received"
projections.append(p.Projection(populations[6], populations[15], p.FromListConnector(injectionConnection))) projections.append(p.Projection(populations[7], populations[15], p.FromListConnector(injectionConnection))) projections.append(p.Projection(populations[8], populations[15], p.FromListConnector(injectionConnection))) projections.append(p.Projection(populations[9], populations[15], p.FromListConnector(injectionConnection))) projections.append(p.Projection(populations[10], populations[15], p.FromListConnector(injectionConnection))) projections.append(p.Projection(populations[11], populations[15], p.FromListConnector(injectionConnection))) projections.append(p.Projection(populations[12], populations[15], p.FromListConnector(injectionConnection))) projections.append(p.Projection(populations[13], populations[15], p.FromListConnector(injectionConnection))) projections.append(p.Projection(populations[14], populations[15], p.FromListConnector(injectionConnection))) #populations[0].record_v() #populations[0].record_gsyn() #populations[0].record() p.run(1000) v = None gsyn = None spikes = None v = populations[0].get_v() #gsyn = populations[0].get_gsyn() spikes = populations[0].getSpikes() if spikes != None: 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')
# +-------------------------------------------------------------------+ # | Simulation and results | # +-------------------------------------------------------------------+ # Record neurons' potentials pre_pop.record_v() post_pop.record_v() # Record spikes pre_pop.record() post_pop.record() # Run simulation sim.run(simtime) #IPython.embed() print("Weights:", plastic_projection.getWeights()) def plot_spikes(spikes, title): if spikes != None: pylab.figure() pylab.xlim((0, simtime)) pylab.plot([i[1] for i in spikes], [i[0] for i in spikes], ".") pylab.xlabel('Time/ms') pylab.ylabel('spikes') pylab.title(title) else: print "No spikes received"
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(loopConnections))) projections.append(p.Projection(populations[1], populations[0], p.FromListConnector(injectionConnection))) populations[0].record_v() populations[0].record_gsyn() populations[0].record(visualiser_mode=modes.RASTER) run_time = (max_delay * nNeurons) print "Running for {} ms".format(run_time) p.run(run_time) v = None gsyn = None spikes = None v = populations[0].get_v(compatible_output=True) gsyn = populations[0].get_gsyn(compatible_output=True) spikes = populations[0].getSpikes(compatible_output=True) if spikes != 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')
out1 = p.Projection(plus_detector, output, p.FromListConnector( retina_lib.AllToOne(subsample_size * subsample_size, BWD, .25, 1)), target='excitatory') #check between forward and backwards and what will happen if left and right directions are given out2 = p.Projection(cross_detector, output, p.FromListConnector( retina_lib.AllToOne(subsample_size * subsample_size, FWD, .25, 1)), target='excitatory') inh_out_1 = p.Projection(output, output, p.AllToAllConnector(weights=-5, delays=1, allow_self_connections=False), target='inhibitory') robot_projections = p.Projection(output, robot_motor_control, p.OneToOneConnector(weights=-5, delays=1), target='excitatory') #output.set_robotic_output() #output1.set_mapping_constraint({'x':0,'y':0}) p.run(runtime) # Simulation time p.end()
#!/usr/bin/python import pacman103.front.pynn as p import numpy, pylab #set up pacman103 p.setup(timestep=1.0, min_delay=1.0, max_delay=32.0) #external stuff population requiremenets connected_chip_coords = {'x': 0, 'y': 0} virtual_chip_coords = {'x': 0, 'y': 5} link = 4 populations = list() projections = list() populations.append(p.Population(1, p.SpikeSourcePoisson, {'rate': 10000})) populations.append( p.Population(1, p.RobotMotorControl, { 'virtual_chip_coords': virtual_chip_coords, 'connected_chip_coords': connected_chip_coords, 'connected_chip_edge': link }, label='External motor control')) projections.append( p.Projection(populations[0], populations[1], p.OneToOneConnector())) p.run(10000)
#projections.append(p.Projection(populations[stimulus], populations[inhib], p.FixedProbabilityConnector(p_connect=p_exc2inh, weights=baseline_excit_weight, delays=inh_delay_distr), target='excitatory')) populations[stimulus].record(visualiser_mode=modes.RASTER) #populations[inhib].record_v() #populations[inhib].record(visualiser_mode=modes.RASTER) populations[excit].record_v() populations[excit].record(visualiser_mode=modes.RASTER) populations[teacher].record(visualiser_mode=modes.RASTER) #populations[noise].record_v() #populations[noise].record(visualiser_mode=modes.RASTER) p.run(runTime) #final_weights = projections[0].getWeights() final_weights = projections[0].getWeights(format="array") print "Length of weights is ", len(final_weights) print "Length of one row of weights is ", len(final_weights[1]) count_plus = 0 count_minus = 0 weightUse = {} for row in final_weights: for i in row: myString = "%f" % i if myString in weightUse: weightUse[myString] += 1 else: weightUse[myString] = 1
# Add place cell to list if DEBUG: print("\tPlace cell mu:%f" % cell_mu) cells.append(PlaceCell(cell_mu, cell_sigma, cell_min_rate, cell_max_rate, population_size, population_label_stem + ("_%u" % c), sdp_connection)) return cells # ------------------------------------------ # PyNN entry point # ------------------------------------------ # SpiNNaker setup sim.setup(timestep=1.0,min_delay=1.0,max_delay=10.0) # Create human vs ai pong game and start it pong_game = PongGame(["human", "computer"]) pong_game.start() # Create spinnaker pong player player_thread = SpiNNakerPlayer(BOARD_ADDRESS, 0, pong_game, MAX_Y, UPDATE_TIMESTEP, NUM_PADDLE_CELLS, PADDLE_CELL_SIGMA, CELL_MIN_RATE, PADDLE_CELL_MAX_RATE, PADDLE_CELL_POP_SIZE, NUM_BALL_CELLS, BALL_CELL_SIGMA, CELL_MIN_RATE, BALL_CELL_MAX_RATE, BALL_CELL_POP_SIZE) # Start player thread and simulation player_thread.start() sim.run(SIM_TIME)
#projections.append(p.Projection(populations[stimulus], populations[inhib], p.FixedProbabilityConnector(p_connect=p_exc2inh, weights=baseline_excit_weight, delays=inh_delay_distr), target='excitatory')) populations[stimulus].record(visualiser_mode=modes.RASTER) #populations[inhib].record_v() #populations[inhib].record(visualiser_mode=modes.RASTER) populations[excit].record_v() populations[excit].record(visualiser_mode=modes.RASTER) populations[teacher].record(visualiser_mode=modes.RASTER) #populations[noise].record_v() #populations[noise].record(visualiser_mode=modes.RASTER) p.run(runTime) #final_weights = projections[0].getWeights() final_weights = projections[0].getWeights(format="array") print "Length of weights is ", len(final_weights) print "Length of one row of weights is ", len(final_weights[1]) count_plus = 0 count_minus = 0 weightUse = {} for row in final_weights: for i in row: myString="%f"%i if myString in weightUse: weightUse[myString] += 1 else: weightUse[myString] = 1
'tau_refrac' : 100, 'i_offset' : 1 } cell_params_lif = { 'tau_m' : 32, 'cm' : 0.35, # added to make PACMAN103 work 'v_init' : -80, 'v_rest' : -70, 'v_reset' : -95, 'v_thresh' : -55, 'tau_syn_E' : 5, 'tau_syn_I' : 10, 'tau_refrac' : 5, 'i_offset' : 0 } populations = list() projections = list() populations.append(p.Population(nNeurons, p.IF_curr_exp, cell_params_lif_in, label='pop_0')) populations.append(p.Population(nNeurons, p.IF_curr_exp, cell_params_lif, label='pop_1')) projections.append(p.Projection(populations[0], populations[1], p.OneToOneConnector(weights=8, delays=16))) populations[0].set_mapping_constraint({'x':7, 'y':7}) populations[1].set_mapping_constraint({'x':3, 'y':4}) p.run(3000)