def setup(self, load_tuning_prop=False, times={}):
self.projections = {}
self.projections['ee'] = []
self.projections['ei'] = []
self.projections['ie'] = []
self.projections['ii'] = []
if not load_tuning_prop:
self.tuning_prop_exc = utils.set_tuning_prop(self.params, mode='hexgrid', cell_type='exc') # set the tuning properties of exc cells: space (x, y) and velocity (u, v)
self.tuning_prop_inh = utils.set_tuning_prop(self.params, mode='hexgrid', cell_type='inh') # set the tuning properties of exc cells: space (x, y) and velocity (u, v)
else:
self.tuning_prop_exc = np.loadtxt(self.params['tuning_prop_means_fn'])
self.tuning_prop_inh = np.loadtxt(self.params['tuning_prop_inh_fn'])
indices, distances = utils.sort_gids_by_distance_to_stimulus(self.tuning_prop_exc, self.params) # cells in indices should have the highest response to the stimulus
if self.pc_id == 0:
print "Saving tuning_prop to file:", self.params['tuning_prop_means_fn']
np.savetxt(self.params['tuning_prop_means_fn'], self.tuning_prop_exc)
print "Saving tuning_prop to file:", self.params['tuning_prop_inh_fn']
np.savetxt(self.params['tuning_prop_inh_fn'], self.tuning_prop_inh)
print 'Saving gids to record to: ', self.params['gids_to_record_fn']
np.savetxt(self.params['gids_to_record_fn'], indices[:self.params['n_gids_to_record']], fmt='%d')
# np.savetxt(params['gids_to_record_fn'], indices[:params['n_gids_to_record']], fmt='%d')
if self.comm != None:
self.comm.Barrier()
from pyNN.utility import Timer
self.timer = Timer()
self.timer.start()
self.times = times
self.times['t_all'] = 0
# # # # # # # # # # # #
# S E T U P #
# # # # # # # # # # # #
(delay_min, delay_max) = self.params['delay_range']
setup(timestep=0.1, min_delay=delay_min, max_delay=delay_max, rng_seeds_seed=self.params['seed'])
rng_v = NumpyRNG(seed = sim_cnt*3147 + self.params['seed'], parallel_safe=True) #if True, slower but does not depend on number of nodes
self.rng_conn = NumpyRNG(seed = self.params['seed'], parallel_safe=True) #if True, slower but does not depend on number of nodes
# # # # # # # # # # # # # # # # # # # # # # # # #
# R A N D O M D I S T R I B U T I O N S #
# # # # # # # # # # # # # # # # # # # # # # # # #
self.v_init_dist = RandomDistribution('normal',
(self.params['v_init'], self.params['v_init_sigma']),
rng=rng_v,
constrain='redraw',
boundaries=(-80, -60))
self.times['t_setup'] = self.timer.diff()
self.times['t_calc_conns'] = 0
if self.comm != None:
self.comm.Barrier()
self.torus = space.Space(axes='xy', periodic_boundaries=((0., self.params['torus_width']), (0., self.params['torus_height'])))
from connector_functions import create_cortical_to_cortical_connection
from connector_functions import normalize_connection_list
from connector_functions import create_cortical_to_cortical_connection_corr
from connector_functions import create_thalamocortical_connection
from analysis_functions import calculate_tuning, visualize_conductances, visualize_conductances_and_voltage
from analysis_functions import conductance_analysis
from plot_functions import plot_spiketrains
#############################
simulator = get_script_args(1)[0]
exec("import pyNN.%s as simulator" % simulator)
#import pyNN.nest as simulator
#import pyNN.neuron as simulator
timer = Timer()
#############################
## Parameters
#############################
# ============== Network and simulation parameters =================
contrast = 0.50 # Contrast used (possible range available in ./data)
Nside_lgn = 30 # N_lgn x N_lgn is the size of the LGN
Nside_exc = 40 # N_exc x N_exc is the size of the cortical excitatory layer
Nside_inh = 20 # N_inh x N_inh is the size of the cortical inhibitory layer
factor = 1 # Reduction factor
def setup(self, load_tuning_prop=False, times={}):
self.projections = {}
self.projections["ee"] = []
self.projections["ei"] = []
self.projections["ie"] = []
self.projections["ii"] = []
if not load_tuning_prop:
self.tuning_prop_exc = utils.set_tuning_prop(
self.params, mode="hexgrid", cell_type="exc"
) # set the tuning properties of exc cells: space (x, y) and velocity (u, v)
self.tuning_prop_inh = utils.set_tuning_prop(
self.params, mode="hexgrid", cell_type="inh"
) # set the tuning properties of exc cells: space (x, y) and velocity (u, v)
else:
self.tuning_prop_exc = np.loadtxt(self.params["tuning_prop_means_fn"])
self.tuning_prop_inh = np.loadtxt(self.params["tuning_prop_inh_fn"])
indices, distances = utils.sort_gids_by_distance_to_stimulus(
self.tuning_prop_exc, self.params["motion_params"], self.params
) # cells in indices should have the highest response to the stimulus
if self.pc_id == 0:
print "Saving tuning_prop to file:", self.params["tuning_prop_means_fn"]
np.savetxt(self.params["tuning_prop_means_fn"], self.tuning_prop_exc)
print "Saving tuning_prop to file:", self.params["tuning_prop_inh_fn"]
np.savetxt(self.params["tuning_prop_inh_fn"], self.tuning_prop_inh)
print "Saving gids to record to: ", self.params["gids_to_record_fn"]
np.savetxt(self.params["gids_to_record_fn"], indices[: self.params["n_gids_to_record"]], fmt="%d")
# np.savetxt(params['gids_to_record_fn'], indices[:params['n_gids_to_record']], fmt='%d')
if self.comm != None:
self.comm.Barrier()
from pyNN.utility import Timer
self.timer = Timer()
self.timer.start()
self.times = times
self.times["t_all"] = 0
# # # # # # # # # # # #
# S E T U P #
# # # # # # # # # # # #
(delay_min, delay_max) = self.params["delay_range"]
setup(timestep=0.1, min_delay=delay_min, max_delay=delay_max, rng_seeds_seed=self.params["seed"])
rng_v = NumpyRNG(
seed=sim_cnt * 3147 + self.params["seed"], parallel_safe=True
) # if True, slower but does not depend on number of nodes
self.rng_conn = NumpyRNG(
seed=self.params["seed"], parallel_safe=True
) # if True, slower but does not depend on number of nodes
# # # # # # # # # # # # # # # # # # # # # # # # #
# R A N D O M D I S T R I B U T I O N S #
# # # # # # # # # # # # # # # # # # # # # # # # #
self.v_init_dist = RandomDistribution(
"normal",
(self.params["v_init"], self.params["v_init_sigma"]),
rng=rng_v,
constrain="redraw",
boundaries=(-80, -60),
)
self.times["t_setup"] = self.timer.diff()
self.times["t_calc_conns"] = 0
if self.comm != None:
self.comm.Barrier()
self.torus = space.Space(
axes="xy", periodic_boundaries=((0.0, self.params["torus_width"]), (0.0, self.params["torus_height"]))
)
The IF network is based on the CUBA and COBA models of Vogels & Abbott
(J. Neurosci, 2005). The model consists of a network of excitatory and
inhibitory neurons, connected via current-based "exponential"
synapses (instantaneous rise, exponential decay).
Andrew Davison, UNIC, CNRS
August 2006
Author: Bernhard Kaplan, [email protected]
"""
import time
t0 = time.time()
# to store timing information
from pyNN.utility import Timer
timer = Timer()
timer.start()
times = {}
times['t_startup'] = time.time() - t0
# check imports
import numpy as np
import os
import socket
from math import *
import json
from pyNN.utility import get_script_args
simulator_name = 'nest'
from pyNN.nest import *
#exec("from pyNN.%s import *" % simulator_name)
try:
def run_model(sim, **options):
"""
Run a simulation using the parameters read from the file "spike_train_statistics.json"
:param sim: the PyNN backend module to be used.
:param options: should contain a keyword "simulator" which is the name of the PyNN backend module used.
:return: a tuple (`data`, `times`) where `data` is a Neo Block containing the recorded spikes
and `times` is a dict containing the time taken for different phases of the simulation.
"""
import json
from pyNN.utility import Timer
print("Running")
timer = Timer()
g = open("spike_train_statistics.json", 'r')
d = json.load(g)
N = d['param']['N']
max_rate = d['param']['max_rate']
tstop = d['param']['tstop']
d['SpikeSourcePoisson'] = {
"duration": tstop
}
if options['simulator'] == "hardware.brainscales":
hardware_preset = d['setup'].pop('hardware_preset', None)
if hardware_preset:
d['setup']['hardware'] = sim.hardwareSetup[hardware_preset]
d['SpikeSourcePoisson']['random'] = True
place = mapper.place()
timer.start()
sim.setup(**d['setup'])
spike_sources = sim.Population(N, sim.SpikeSourcePoisson, d['SpikeSourcePoisson'])
delta_rate = max_rate/N
rates = numpy.linspace(delta_rate, max_rate, N)
print("Firing rates: %s" % rates)
if PYNN07:
spike_sources.tset("rate", rates)
else:
spike_sources.set(rate=rates)
if options['simulator'] == "hardware.brainscales":
for i, spike_source in enumerate(spike_sources):
place.to(spike_source, hicann=i//8, neuron=i%64)
place.commit()
if PYNN07:
spike_sources.record()
else:
spike_sources.record('spikes')
setup_time = timer.diff()
sim.run(tstop)
run_time = timer.diff()
if PYNN07:
spike_array = spike_sources.getSpikes()
data = spike_array_to_neo(spike_array, spike_sources, tstop)
else:
data = spike_sources.get_data()
sim.end()
closing_time = timer.diff()
times = {'setup_time': setup_time, 'run_time': run_time, 'closing_time': closing_time}
return data, times
#from pyNN.brian import *
#simulator_name = 'brian'
import simulation_parameters
ps = simulation_parameters.parameter_storage()
params = ps.params
# ===================================
# G E T P A R A M E T E R S
# ===================================
x0, y0 = params['motion_params'][0:2]
sim_cnt = int(sys.argv[1])
mp = float(sys.argv[2]), float(sys.argv[3]), float(sys.argv[4]), float(sys.argv[5])
from pyNN.utility import Timer
timer = Timer()
timer.start()
times = {} # stores time stamps
tuning_prop = utils.set_tuning_prop(params, mode='hexgrid')
time = np.arange(0, params['t_stimulus'], params['dt_rate'])
#print 'Prepare spike trains'
#L_input = np.zeros((params['n_exc'], time.shape[0]))
#for i_time, time_ in enumerate(time):
# if (i_time % 100 == 0):
# print "t:", time_
# L_input[:, i_time] = utils.get_input(tuning_prop, params, time_/params['t_sim'])
# L_input[:, i_time] *= params['f_max_stim']
# ===============
# S E T U P
请发表评论