def run(self, params, verbose=True): tmpdir = tempfile.mkdtemp() timer = Timer() timer.start() # start timer on construction # === Build the network ======================================================== if verbose: print "Setting up simulation" sim.setup(timestep=params.simulation.dt, max_delay=params.simulation.syn_delay, debug=False) N = params.N #dc_generator current_source = sim.DCSource(amplitude=params.snr, start=params.simulation.simtime / 4, stop=params.simulation.simtime / 4 * 3) # internal noise model (NEST specific) noise = sim.Population(N, 'noise_generator', { 'mean': 0., 'std': params.noise_std }) # target population output = sim.Population(N, sim.IF_cond_exp) # initialize membrane potential numpy.random.seed(params.simulation.kernelseed) V_rest, V_spike = -70., -53. output.tset('v_init', V_rest + numpy.random.rand(N, ) * (V_spike - V_rest)) # Connecting the network conn = sim.OneToOneConnector(weights=params.weight) sim.Projection(noise, output, conn) for cell in output: cell.inject(current_source) output.record() # reads out time used for building buildCPUTime = timer.elapsedTime() # === Run simulation =========================================================== if verbose: print "Running simulation" timer.reset() # start timer on construction sim.run(params.simulation.simtime) simCPUTime = timer.elapsedTime() timer.reset() # start timer on construction output_filename = os.path.join(tmpdir, 'output.gdf') #print output_filename output.printSpikes(output_filename) # output_DATA = load_spikelist(output_filename, N, t_start=0.0, t_stop=params.simulation.simtime) writeCPUTime = timer.elapsedTime() if verbose: print "\nFiber Network Simulation:" print "Number of Neurons : ", N print "Mean Output rate : ", output_DATA.mean_rate( ), "Hz during ", params.simulation.simtime, "ms" print("Build time : %g s" % buildCPUTime) print("Simulation time : %g s" % simCPUTime) print("Writing time : %g s" % writeCPUTime) os.remove(output_filename) os.rmdir(tmpdir) return output_DATA
def run(self, params, verbose=True): """ params are the parameters to use """ tmpdir = tempfile.mkdtemp() myTimer = Timer() # === Build the network ======================================================== if verbose: print "Setting up simulation" myTimer.start() # start timer on construction sim.setup(timestep=params['dt'], max_delay=params['syn_delay']) N = params['N'] #dc_generator phr_ON = sim.Population((N, ), 'dc_generator') phr_OFF = sim.Population((N, ), 'dc_generator') for factor, phr in [(-params['snr'], phr_OFF), (params['snr'], phr_ON)]: phr.tset('amplitude', params['amplitude'] * factor) phr.set({ 'start': params['simtime'] / 4, 'stop': params['simtime'] / 4 * 3 }) # internal noise model (see benchmark_noise) noise_ON = sim.Population((N, ), 'noise_generator', { 'mean': 0., 'std': params['noise_std'] }) noise_OFF = sim.Population((N, ), 'noise_generator', { 'mean': 0., 'std': params['noise_std'] }) # target ON and OFF populations (what about a tridimensional Population?) out_ON = sim.Population( (N, ), sim.IF_curr_alpha ) #'IF_cond_alpha) #iaf_sfa_neuron')# EIF_cond_alpha_isfa_ista, IF_cond_exp_gsfa_grr,sim.IF_cond_alpha)#'iaf_sfa_neuron',params['parameters_gc'])#'iaf_cond_neuron')# IF_cond_alpha) # out_OFF = sim.Population( (N, ), sim.IF_curr_alpha ) #'IF_cond_alpha) #IF_curr_alpha)#'iaf_sfa_neuron')#sim.IF_curr_alpha)#,params['parameters_gc']) # initialize membrane potential TODO: and conductances? from pyNN.random import RandomDistribution, NumpyRNG rng = NumpyRNG(seed=params['kernelseed']) vinit_distr = RandomDistribution(distribution='uniform', parameters=[-70, -55], rng=rng) for out_ in [out_ON, out_OFF]: out_.randomInit(vinit_distr) retina_proj_ON = sim.Projection(phr_ON, out_ON, sim.OneToOneConnector()) retina_proj_ON.setWeights(params['weight']) # TODO fix setWeight, add setDelays to 10 ms (relative to stimulus onset) retina_proj_OFF = sim.Projection(phr_OFF, out_OFF, sim.OneToOneConnector()) retina_proj_OFF.setWeights(params['weight']) noise_proj_ON = sim.Projection(noise_ON, out_ON, sim.OneToOneConnector()) noise_proj_ON.setWeights(params['weight']) noise_proj_OFF = sim.Projection( noise_OFF, out_OFF, sim.OneToOneConnector( )) # implication if ON and OFF have the same noise input? noise_proj_OFF.setWeights(params['weight']) out_ON.record() out_OFF.record() # reads out time used for building buildCPUTime = myTimer.elapsedTime() # === Run simulation =========================================================== if verbose: print "Running simulation" myTimer.reset() # start timer on construction sim.run(params['simtime']) simCPUTime = myTimer.elapsedTime() myTimer.reset() # start timer on construction # TODO LUP use something like "for pop in [phr, out]" ? out_ON_filename = os.path.join(tmpdir, 'out_on.gdf') out_OFF_filename = os.path.join(tmpdir, 'out_off.gdf') out_ON.printSpikes(out_ON_filename) # out_OFF.printSpikes(out_OFF_filename) # # TODO LUP get out_ON_DATA on a 2D grid independantly of out_ON.cell.astype(int) out_ON_DATA = load_spikelist(out_ON_filename, range(N), t_start=0.0, t_stop=params['simtime']) out_OFF_DATA = load_spikelist(out_OFF_filename, range(N), t_start=0.0, t_stop=params['simtime']) out = { 'out_ON_DATA': out_ON_DATA, 'out_OFF_DATA': out_OFF_DATA } #,'out_ON_pos':out_ON} # cleans up os.remove(out_ON_filename) os.remove(out_OFF_filename) os.rmdir(tmpdir) writeCPUTime = myTimer.elapsedTime() if verbose: print "\nRetina Network Simulation:" print(params['description']) print "Number of Neurons : ", N print "Output rate (ON) : ", out_ON_DATA.mean_rate( ), "Hz/neuron in ", params['simtime'], "ms" print "Output rate (OFF) : ", out_OFF_DATA.mean_rate( ), "Hz/neuron in ", params['simtime'], "ms" print("Build time : %g s" % buildCPUTime) print("Simulation time : %g s" % simCPUTime) print("Writing time : %g s" % writeCPUTime) return out
def run(self,params, verbose =True): tmpdir = tempfile.mkdtemp() timer = Timer() timer.start() # start timer on construction # === Build the network ======================================================== if verbose: print "Setting up simulation" sim.setup(timestep=params.simulation.dt,max_delay=params.simulation.syn_delay, debug=False) N = params.N #dc_generator current_source = sim.DCSource( amplitude= params.snr, start=params.simulation.simtime/4, stop=params.simulation.simtime/4*3) # internal noise model (NEST specific) noise = sim.Population(N,'noise_generator',{'mean':0.,'std':params.noise_std}) # target population output = sim.Population(N , sim.IF_cond_exp) # initialize membrane potential numpy.random.seed(params.simulation.kernelseed) V_rest, V_spike = -70., -53. output.tset('v_init',V_rest + numpy.random.rand(N,)* (V_spike -V_rest)) # Connecting the network conn = sim.OneToOneConnector(weights = params.weight) sim.Projection(noise, output, conn) for cell in output: cell.inject(current_source) output.record() # reads out time used for building buildCPUTime= timer.elapsedTime() # === Run simulation =========================================================== if verbose: print "Running simulation" timer.reset() # start timer on construction sim.run(params.simulation.simtime) simCPUTime = timer.elapsedTime() timer.reset() # start timer on construction output_filename = os.path.join(tmpdir,'output.gdf') #print output_filename output.printSpikes(output_filename)# output_DATA = load_spikelist(output_filename,N, t_start=0.0, t_stop=params.simulation.simtime) writeCPUTime = timer.elapsedTime() if verbose: print "\nFiber Network Simulation:" print "Number of Neurons : ", N print "Mean Output rate : ", output_DATA.mean_rate(), "Hz during ",params.simulation.simtime, "ms" print("Build time : %g s" % buildCPUTime) print("Simulation time : %g s" % simCPUTime) print("Writing time : %g s" % writeCPUTime) os.remove(output_filename) os.rmdir(tmpdir) return output_DATA
def run(self, params, verbose=True): """ params are the parameters to use """ tmpdir = tempfile.mkdtemp() myTimer = Timer() # === Build the network ======================================================== if verbose: print "Setting up simulation" myTimer.start() # start timer on construction sim.setup(timestep=params["dt"], max_delay=params["syn_delay"]) N = params["N"] # dc_generator phr_ON = sim.Population((N,), "dc_generator") phr_OFF = sim.Population((N,), "dc_generator") for factor, phr in [(-params["snr"], phr_OFF), (params["snr"], phr_ON)]: phr.tset("amplitude", params["amplitude"] * factor) phr.set({"start": params["simtime"] / 4, "stop": params["simtime"] / 4 * 3}) # internal noise model (see benchmark_noise) noise_ON = sim.Population((N,), "noise_generator", {"mean": 0.0, "std": params["noise_std"]}) noise_OFF = sim.Population((N,), "noise_generator", {"mean": 0.0, "std": params["noise_std"]}) # target ON and OFF populations (what about a tridimensional Population?) out_ON = sim.Population( (N,), sim.IF_curr_alpha ) #'IF_cond_alpha) #iaf_sfa_neuron')# EIF_cond_alpha_isfa_ista, IF_cond_exp_gsfa_grr,sim.IF_cond_alpha)#'iaf_sfa_neuron',params['parameters_gc'])#'iaf_cond_neuron')# IF_cond_alpha) # out_OFF = sim.Population( (N,), sim.IF_curr_alpha ) #'IF_cond_alpha) #IF_curr_alpha)#'iaf_sfa_neuron')#sim.IF_curr_alpha)#,params['parameters_gc']) # initialize membrane potential TODO: and conductances? from pyNN.random import RandomDistribution, NumpyRNG rng = NumpyRNG(seed=params["kernelseed"]) vinit_distr = RandomDistribution(distribution="uniform", parameters=[-70, -55], rng=rng) for out_ in [out_ON, out_OFF]: out_.randomInit(vinit_distr) retina_proj_ON = sim.Projection(phr_ON, out_ON, sim.OneToOneConnector()) retina_proj_ON.setWeights(params["weight"]) # TODO fix setWeight, add setDelays to 10 ms (relative to stimulus onset) retina_proj_OFF = sim.Projection(phr_OFF, out_OFF, sim.OneToOneConnector()) retina_proj_OFF.setWeights(params["weight"]) noise_proj_ON = sim.Projection(noise_ON, out_ON, sim.OneToOneConnector()) noise_proj_ON.setWeights(params["weight"]) noise_proj_OFF = sim.Projection( noise_OFF, out_OFF, sim.OneToOneConnector() ) # implication if ON and OFF have the same noise input? noise_proj_OFF.setWeights(params["weight"]) out_ON.record() out_OFF.record() # reads out time used for building buildCPUTime = myTimer.elapsedTime() # === Run simulation =========================================================== if verbose: print "Running simulation" myTimer.reset() # start timer on construction sim.run(params["simtime"]) simCPUTime = myTimer.elapsedTime() myTimer.reset() # start timer on construction # TODO LUP use something like "for pop in [phr, out]" ? out_ON_filename = os.path.join(tmpdir, "out_on.gdf") out_OFF_filename = os.path.join(tmpdir, "out_off.gdf") out_ON.printSpikes(out_ON_filename) # out_OFF.printSpikes(out_OFF_filename) # # TODO LUP get out_ON_DATA on a 2D grid independantly of out_ON.cell.astype(int) out_ON_DATA = load_spikelist(out_ON_filename, range(N), t_start=0.0, t_stop=params["simtime"]) out_OFF_DATA = load_spikelist(out_OFF_filename, range(N), t_start=0.0, t_stop=params["simtime"]) out = {"out_ON_DATA": out_ON_DATA, "out_OFF_DATA": out_OFF_DATA} # ,'out_ON_pos':out_ON} # cleans up os.remove(out_ON_filename) os.remove(out_OFF_filename) os.rmdir(tmpdir) writeCPUTime = myTimer.elapsedTime() if verbose: print "\nRetina Network Simulation:" print (params["description"]) print "Number of Neurons : ", N print "Output rate (ON) : ", out_ON_DATA.mean_rate(), "Hz/neuron in ", params["simtime"], "ms" print "Output rate (OFF) : ", out_OFF_DATA.mean_rate(), "Hz/neuron in ", params["simtime"], "ms" print ("Build time : %g s" % buildCPUTime) print ("Simulation time : %g s" % simCPUTime) print ("Writing time : %g s" % writeCPUTime) return out