def __init__(self, params=None, comm=None, data_fn=None, sim_cnt=0): if params == None: self.network_params = simulation_parameters.parameter_storage() # network_params class containing the simulation parameters self.params = self.network_params.load_params() # params stores cell numbers, etc as a dictionary else: self.params = params self.no_spikes = False self.comm = comm self.n_fig_x = 2 self.n_fig_y = 2 self.tuning_params = np.loadtxt(self.params['tuning_prop_means_fn']) # define parameters self.n_cells = self.params['n_exc'] self.time_binsize = 20 # [ms] self.n_bins = int((self.params['t_sim'] / self.time_binsize) ) self.time_bins = [self.time_binsize * i for i in xrange(self.n_bins)] self.t_axis = np.arange(0, self.n_bins * self.time_binsize, self.time_binsize) self.n_good = self.params['n_exc'] * .10 # fraction of 'interesting' cells print 'Number of cells with \'good\' tuning_properties = ', self.n_good # create data structures self.nspikes = np.zeros(self.n_cells) # summed activity self.nspikes_binned = np.zeros((self.n_cells, self.n_bins)) # binned activity over time self.spiketrains = [[] for i in xrange(self.n_cells)] self.tuning_prop = np.loadtxt(self.params['tuning_prop_means_fn']) # sort the cells by their proximity to the stimulus into 'good_gids' and the 'rest' # cell in 'good_gids' should have the highest response to the stimulus print 'utils.sort_gids_by_distance_to_stimulus' all_gids, all_distances = utils.sort_gids_by_distance_to_stimulus(self.tuning_prop, self.params['motion_params'], self.params) self.good_gids, self.good_distances = all_gids[0:self.n_good], all_distances[0:self.n_good] print 'Saving gids to record to', self.params['gids_to_record_fn'] np.savetxt(self.params['gids_to_record_fn'], np.array(self.good_gids), fmt='%d') self.rest_gids = range(self.n_cells) for gid in self.good_gids: self.rest_gids.remove(gid) fig_width_pt = 800.0 # Get this from LaTeX using \showthe\columnwidth inches_per_pt = 1.0/72.27 # Convert pt to inch golden_mean = (np.sqrt(5)-1.0)/2.0 # Aesthetic ratio fig_width = fig_width_pt*inches_per_pt # width in inches fig_height = fig_width*golden_mean # height in inches fig_size = [fig_width,fig_height] params = {#'backend': 'png', # 'axes.labelsize': 10, # 'text.fontsize': 10, 'legend.fontsize': 10, # 'xtick.labelsize': 8, # 'ytick.labelsize': 8, # 'text.usetex': True, 'figure.figsize': fig_size} pylab.rcParams.update(params)
def sort_gids(self): print 'ConductanceCalculator.sort_gids' self.tuning_prop = np.loadtxt(self.params['tuning_prop_means_fn']) # sort the cells by their proximity to the stimulus into 'good_gids' and the 'rest' # cell in 'good_gids' should have the highest response to the stimulus all_gids, all_distances = utils.sort_gids_by_distance_to_stimulus(self.tuning_prop, self.params['motion_params']) self.good_gids, self.good_distances = all_gids[0:self.n_good], all_distances[0:self.n_good] self.rest_gids = range(self.n_exc) for gid in self.good_gids: self.rest_gids.remove(gid)
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'])))
def setup(self, load_tuning_prop=False): if load_tuning_prop: print 'Loading tuning properties from', self.params['tuning_prop_means_fn'] self.tuning_prop_exc = np.loadtxt(self.params['tuning_prop_means_fn']) else: print 'Preparing tuning properties with limited range....' x_range = (0, 1.) y_range = (0.2, .5) u_range = (.05, 1.0) v_range = (-.2, .2) tp_exc_good, tp_exc_out_of_range = utils.set_limited_tuning_properties(params, y_range, x_range, u_range, v_range, cell_type='exc') self.tuning_prop_exc = tp_exc_good print 'n_exc within range: ', tp_exc_good[:, 0].size print "Saving tuning_prop to file:", params['tuning_prop_means_fn'] np.savetxt(params['tuning_prop_means_fn'], tp_exc_good) 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 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 = {} # # # # # # # # # # # # # 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()
def sort_gids(self): self.tuning_prop = np.loadtxt(self.params['tuning_prop_means_fn']) # sort the cells by their proximity to the stimulus into 'good_gids' and the 'rest' # cell in 'good_gids' should have the highest response to the stimulus all_gids, all_distances = utils.sort_gids_by_distance_to_stimulus(self.tuning_prop, self.params['motion_params']) n_good = self.params['n_exc'] * 0.02 self.good_gids, self.good_distances = all_gids[0:n_good], all_distances[0:n_good] self.rest_gids = range(self.params['n_exc']) for gid in self.good_gids: self.rest_gids.remove(gid) print 'Saving gids to record to', self.params['gids_to_record_fn'] np.savetxt(self.params['gids_to_record_fn'], np.array(self.good_gids), fmt='%d') return self.good_gids, self.rest_gids
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"])) )
PS.create_folders() PS.write_parameters_to_file() # not yet required #try: # from mpi4py import MPI # USE_MPI = True # comm = MPI.COMM_WORLD # pc_id, n_proc = comm.rank, comm.size # print "USE_MPI:", USE_MPI, 'pc_id, n_proc:', pc_id, n_proc #except: # USE_MPI = False # pc_id, n_proc, comm = 0, 1, None # print "MPI not used" tuning_prop_exc = utils.set_tuning_prop(params, mode='hexgrid', cell_type='exc') # set the tuning properties of exc cells: space (x, y) and velocity (u, v) print "Saving tuning_prop to file:", params['tuning_prop_means_fn'] np.savetxt(params['tuning_prop_means_fn'], tuning_prop_exc) print 'Calculating gids to record...' mp = params['motion_params'] indices, distances = utils.sort_gids_by_distance_to_stimulus(tuning_prop_exc, mp, params) # cells in indices should have the highest response to the stimulus n = params['n_gids_to_record'] np.savetxt(params['gids_to_record_fn'], indices[:n], fmt='%d') print 'Saving gids to record to: ', params['gids_to_record_fn'] tuning_prop_inh= utils.set_tuning_prop(params, mode='hexgrid', cell_type='inh') # set the tuning properties of exc cells: space (x, y) and velocity (u, v) print "Saving tuning_prop to file:", params['tuning_prop_inh_fn'] np.savetxt(params['tuning_prop_inh_fn'], tuning_prop_inh)
print "Missing file: ", fn spike_times = [] ssa = create(SpikeSourceArray, {'spike_times': spike_times}) connect(ssa, exc_pop[tgt], params['w_input_exc'], synapse_type='excitatory') # connect noise if (simulator_name == 'nest'): # for nest one can use the optimized Poisson generator noise_exc = create(native_cell_type('poisson_generator'), {'rate' : params['f_exc_noise']}) else: noise_exc = create(SpikeSourcePoisson, {'rate' : params['f_exc_noise']}) connect(noise_exc, exc_pop[tgt], weight=params['w_exc_noise'], synapse_type='excitatory', delay=1.) # ================== # R E C O R D # ================== cells_closest_to_stim_pos, x_dist_to_stim = utils.sort_gids_by_distance_to_stimulus(tuning_prop, mp) #print 'debug cells_closest_to_stim_pos', cells_closest_to_stim_pos #gids_to_record = cells_closest_to_stim_pos[:5] #exc_pop_view = PopulationView(exc_pop, gids_to_record, label='good_exc_neurons') #exc_pop_view.record_v() exc_pop.record() # ========== # R U N # ========== run(params['t_sim']) times['t_sim'] = timer.diff() #fn_volt = params['exc_volt_fn_base'] + '%d.v' % sim_cnt #print 'print_v to file: %s' % (fn_volt) #exc_pop_view.print_v("%s" % (fn_volt), compatible_output=False)
import numpy as np import utils import simulation_parameters import CreateConnections as CC network_params = simulation_parameters.parameter_storage() # network_params class containing the simulation parameters params = network_params.load_params() # params stores cell numbers, etc as a dictionary tp = np.loadtxt(params['tuning_prop_means_fn']) mp = params['motion_params'] print "Motion parameters", mp sigma_x, sigma_v = params['w_sigma_x'], params['w_sigma_v'] # small sigma values let p and w shrink print 'utils.sort_gids_by_distance_to_stimulus...' indices, distances = utils.sort_gids_by_distance_to_stimulus(tp , mp) # cells in indices should have the highest response to the stimulus print 'utils.convert_connlist_to_matrix...' conn_mat, delays = utils.convert_connlist_to_matrix(params['conn_list_ee_fn_base'] + '0.dat', params['n_exc'], params['n_exc']) #n = 50 n = int(params['n_exc'] * .05) # fraction of 'interesting' cells print "Loading nspikes", params['exc_spiketimes_fn_merged'] + '.ras' nspikes = utils.get_nspikes(params['exc_spiketimes_fn_merged'] + '.ras', n_cells=params['n_exc']) mans = (nspikes.argsort()).tolist() # mans = most active neurons mans.reverse() mans = mans[0:n] print 'w_out_good = weights to other well tuned neurons' print 'w_in_good = weights from other well tuned neurons' print 'w_out_total = sum of all outgoing weights' print 'w_in_total = sum of all incoming weights' print 'distance_to_stim = minimal distance to the moving stimulus (linear sum of (time-varying) spatial distance and (constant) distance in velocity)'