def create_connectivity(self, conn_type): """ This function (re-) creates the network connectivity. """ # distribute the cell ids among involved processes (n_src, n_tgt, self.tp_src, self.tp_tgt) = utils.resolve_src_tgt_with_tp(conn_type, self.params) print 'Connect anisotropic %s - %s' % (conn_type[0].capitalize(), conn_type[1].capitalize()) gid_tgt_min, gid_tgt_max = utils.distribute_n(n_tgt, self.n_proc, self.pc_id) print 'Process %d deals with target GIDS %d - %d' % (self.pc_id, gid_tgt_min, gid_tgt_max) gid_src_min, gid_src_max = utils.distribute_n(n_src, self.n_proc, self.pc_id) print 'Process %d deals with source GIDS %d - %d' % (self.pc_id, gid_src_min, gid_src_max) n_my_tgts = gid_tgt_max - gid_tgt_min # data structure for connection storage self.target_adj_list = [ [] for i in xrange(n_my_tgts)] n_src_cells_per_neuron = int(round(self.params['p_%s' % conn_type] * n_src)) # compute all pairwise connection probabilities for i_, tgt in enumerate(range(gid_tgt_min, gid_tgt_max)): if (i_ % 20) == 0: print '%.2f percent complete' % (i_ / float(n_my_tgts) * 100.) p = np.zeros(n_src) latency = np.zeros(n_src) for src in xrange(n_src): if conn_type[0] == conn_type[1]: # no self-connection if (src != tgt): p[src], latency[src] = CC.get_p_conn(self.tp_src[src, :], self.tp_tgt[tgt, :], params['w_sigma_x'], params['w_sigma_v'], params['connectivity_radius']) else: # different populations --> same indices mean different cells, no check for src != tgt p[src], latency[src] = CC.get_p_conn(self.tp_src[src, :], self.tp_tgt[tgt, :], params['w_sigma_x'], params['w_sigma_v'], params['connectivity_radius']) # sort connection probabilities and select remaining connections sorted_indices = np.argsort(p) if conn_type[0] == 'e': sources = sorted_indices[-n_src_cells_per_neuron:] else: if conn_type == 'ii': sources = sorted_indices[1:n_src_cells_per_neuron+1] # shift indices to avoid self-connection, because p_ii = .0 else: sources = sorted_indices[:n_src_cells_per_neuron] w = (self.params['w_tgt_in_per_cell_%s' % conn_type] / p[sources].sum()) * p[sources] for i in xrange(len(sources)): if w[i] > self.params['w_thresh_connection']: delay = min(max(latency[sources[i]] * self.params['delay_scale'], self.params['delay_range'][0]), self.params['delay_range'][1]) # map the delay into the valid range # create adjacency list for all local cells and store connection in class container self.target_adj_list[i_].append(sources[i]) # communicate the resulting target_adj_list to the root process self.send_list_to_root(self.target_adj_list)
def connect_anisotropic(self, conn_type): """ """ if self.pc_id == 0: print 'Connect anisotropic %s - %s' % (conn_type[0].capitalize(), conn_type[1].capitalize()) (n_src, n_tgt, src_pop, tgt_pop, tp_src, tp_tgt, tgt_cells, syn_type) = self.resolve_src_tgt(conn_type) if self.debug_connectivity: conn_list_fn = self.params['conn_list_%s_fn_base' % conn_type] + '%d.dat' % (self.pc_id) conn_file = open(conn_list_fn, 'w') output = '' n_src_cells_per_neuron = int(round(self.params['p_%s' % conn_type] * n_src)) (delay_min, delay_max) = self.params['delay_range'] for tgt in tgt_cells: p = np.zeros(n_src) latency = np.zeros(n_src) for src in xrange(n_src): if conn_type[0] == conn_type[1]: # no self-connection if (src != tgt): p[src], latency[src] = CC.get_p_conn(tp_src[src, :], tp_tgt[tgt, :], params['w_sigma_x'], params['w_sigma_v']) # print 'debug pc_id src tgt ', self.pc_id, src, tgt#, int(ID) < self.params['n_exc'] else: # different populations --> same indices mean different cells, no check for src != tgt p[src], latency[src] = CC.get_p_conn(tp_src[src, :], tp_tgt[tgt, :], params['w_sigma_x'], params['w_sigma_v']) # print 'debug pc_id src tgt ', self.pc_id, src, tgt#, int(ID) < self.params['n_exc'] sorted_indices = np.argsort(p) if conn_type[0] == 'e': sources = sorted_indices[-n_src_cells_per_neuron:] else: if conn_type == 'ii': sources = sorted_indices[1:n_src_cells_per_neuron+1] # shift indices to avoid self-connection, because p_ii = .0 else: sources = sorted_indices[:n_src_cells_per_neuron] w = (self.params['w_tgt_in_per_cell_%s' % conn_type] / p[sources].sum()) * p[sources] for i in xrange(len(sources)): if w[i] > self.params['w_thresh_connection']: # w[i] = max(self.params['w_min'], min(w[i], self.params['w_max'])) delay = min(max(latency[sources[i]] * self.params['t_stimulus'], delay_min), delay_max) # map the delay into the valid range # print 'debug ', delay , ' latency', latency[sources[i]] # delay = min(max(latency[sources[i]] * self.params['delay_scale'], delay_min), delay_max) # map the delay into the valid range connect(src_pop[sources[i]], tgt_pop[tgt], w[i], delay=delay, synapse_type=syn_type) if self.debug_connectivity: output += '%d\t%d\t%.2e\t%.2e\n' % (sources[i], tgt, w[i], delay) # output += '%d\t%d\t%.2e\t%.2e\t%.2e\n' % (sources[i], tgt, w[i], latency[sources[i]], p[sources[i]]) if self.debug_connectivity: if self.pc_id == 0: print 'DEBUG writing to file:', conn_list_fn conn_file.write(output) conn_file.close()
def connect_ee_random(self): """ # # # # # # # # # # # # # # # # # # # # # # # # # # # # # C O N N E C T E X C - E X C R A N D O M # # # # # # # # # # # # # # # # # # # # # # # # # # # # # """ if self.pc_id == 0: print "Drawing random connections" sigma_x, sigma_v = self.params["w_sigma_x"], self.params["w_sigma_v"] (delay_min, delay_max) = self.params["delay_range"] if self.debug_connectivity: conn_list_fn = self.params["conn_list_ee_fn_base"] + "%d.dat" % (self.pc_id) conn_file = open(conn_list_fn, "w") output = "" for tgt in self.local_idx_exc: p = np.zeros(self.params["n_exc"], dtype="float32") latency = np.zeros(self.params["n_exc"], dtype="float32") for src in xrange(self.params["n_exc"]): if src != tgt: p[src], latency[src] = CC.get_p_conn( self.tuning_prop_exc[src, :], self.tuning_prop_exc[tgt, :], sigma_x, sigma_v, params["connectivity_radius"], ) # print 'debug pc_id src tgt ', self.pc_id, src, tgt#, int(ID) < self.params['n_exc'] sources = random.sample(xrange(self.params["n_exc"]), int(self.params["n_src_cells_per_neuron"])) idx = p[sources] > 0 non_zero_idx = np.nonzero(idx)[0] p_ = p[sources][non_zero_idx] l_ = latency[sources][non_zero_idx] * self.params["delay_scale"] w = utils.linear_transformation(p_, self.params["w_min"], self.params["w_max"]) for i in xrange(len(p_)): # w[i] = max(self.params['w_min'], min(w[i], self.params['w_max'])) delay = min(max(l_[i], delay_min), delay_max) # map the delay into the valid range connect(self.exc_pop[non_zero_idx[i]], self.exc_pop[tgt], w[i], delay=delay, synapse_type="excitatory") if self.debug_connectivity: output += "%d\t%d\t%.2e\t%.2e\n" % ( non_zero_idx[i], tgt, w[i], delay, ) # output += '%d\t%d\t%.2e\t%.2e\t%.2e\n' % (sources[i], tgt, w[i], latency[sources[i]], p[sources[i]]) if self.debug_connectivity: if self.pc_id == 0: print "DEBUG writing to file:", conn_list_fn conn_file.write(output) conn_file.close()
import numpy as np import CreateConnections as CC import utils import simulation_parameters ps = simulation_parameters.parameter_storage() params = ps.params tp = np.loadtxt(params['tuning_prop_means_fn']) tgt_gid = 0 srcs = [1, 2, 3, 4, 5, 6, 7, 8] tp_src = tp[srcs, :] tp_tgt = tp[tgt_gid, :] #d_ij = utils.torus_distance2D_vec(tp_src[:, 0], tp_tgt[0] * np.ones(n_src), tp_src[:, 1], tp_tgt[1] * np.ones(n_src), w=np.ones(n_src), h=np.ones(n_src)) print 'tp_src', tp_src print 'tp_tgt', tp_tgt #print 'd_ij', d_ij w_sigma_x, w_sigma_v = .1, .1 v_src = np.array((tp_src[:, 2], tp_src[:, 3])) v_src = v_src.transpose() print 'v_src', v_src.shape p, l = CC.get_p_conn_vec(tp[srcs, :], tp[tgt_gid, :], w_sigma_x, w_sigma_v) print 'p', p print 'l', l for src in xrange(len(srcs)): p_, l_ = CC.get_p_conn(tp_src[src, :], tp_tgt, w_sigma_x, w_sigma_v) print 'src p l', src, p_, p[src], l_, l[src] #print p
mans_set = set(mans) good_gids = set(indices) print mans_set.intersection(good_gids) # sort them according to their x-pos x_sorted_indices = np.argsort(tp[indices, 0]) sorted_gids = indices[x_sorted_indices] print '\nConnection probabilities between the cells with \'good\' tuning properies:' conn_probs = [] latencies = [] for i in xrange(n): src = sorted_gids[i] for tgt in sorted_gids: p, latency = CC.get_p_conn(tp[src, :], tp[tgt, :], sigma_x, sigma_v) conn_probs.append(p) latencies.append(latency) # print "p(%d, %d):\t %.3e\tlatency: %.3e\t" % (src, tgt, p, latency) # print '\n' conn_probs = np.array(conn_probs) latencies = np.array(latencies) print "Average connection probability between neurons with \'good\' tuning_prop", np.mean(conn_probs), '\t std:', np.std(conn_probs) print "Min max and median connection probability between neurons with \'good\' tuning_prop", np.min(conn_probs), np.max(conn_probs), np.median(conn_probs) print "Average latencies between neurons with \'good\' tuning_prop", np.mean(latencies), '\t std:', np.std(latencies) print "Min and max latencies between neurons with \'good\' tuning_prop", np.min(latencies), np.max(latencies) print "\nCompare to cells connected via strong weights" all_weights = conn_mat.flatten() sorted_weight_indices = list(all_weights.argsort())
connect(ssa, exc_pop[tgt], params['w_input_exc'], synapse_type='excitatory') # connect cells # for src, src_gid in enumerate(gids): # if src_gid != tgt_gid: # p, latency = CC.get_p_conn(tuning_prop[src_gid, :], tuning_prop[tgt_gid, :], params['w_sigma_x'], params['w_sigma_v']) # print 'p', p # p = np.array([1e-6, p]) # w = utils.linear_transformation(p, params['w_min'], params['w_max']) # w = w[1] # print "src tgt w", src_gid, tgt_gid, w # delay = min(max(latency * params['delay_scale'], delay_min), delay_max) # map the delay into the valid range # connect(exc_pop[src], exc_pop[tgt], w, delay=delay, synapse_type='excitatory') #delay = 30 p, latency = CC.get_p_conn(tuning_prop[gids[1], :], tuning_prop[gids[0], :], params['w_sigma_x'], params['w_sigma_v']) delay = latency * params['t_stimulus'] * 0.4 #delay = min(max(latency * params['delay_scale'], delay_min), delay_max) # map the delay into the valid range print 'latency %.3e\tdelay %.2e' % (latency, delay) delay = 1 w = 0.5e-2 connect(exc_pop[1], exc_pop[0], w, delay=delay, synapse_type='excitatory') exc_pop.record() exc_pop.record_v() run(params['t_sim']) folder_name = 'BarcelonaData/' exc_pop.printSpikes(folder_name + 'spikes.ras')