def plot_connections(self, tgt_ids, tgt_tp, weights, marker, color, with_directions=False, annotate=False, is_target=True): """ """ markersizes = utils.linear_transformation(weights, self.markersize_min, self.markersize_max) direction_color = (.4, .4, .4) if is_target: quiver_style = '-' direction_dict = self.directions['tgt'] else: quiver_style = ':' direction_dict = self.directions['src'] for i_, tgt in enumerate(tgt_ids): x_tgt = tgt_tp[tgt, 0] % self.params['torus_width']#% 1 y_tgt = tgt_tp[tgt, 1] % self.params['torus_height']#% 1 self.x_min = min(x_tgt, self.x_min) self.y_min = min(y_tgt, self.y_min) self.x_max = max(x_tgt, self.x_max) self.y_max = max(y_tgt, self.y_max) # print 'debug', tgt, x_tgt, y_tgt w = weights[i_] # if is_target: # print 'x, y', x_tgt, y_tgt, w plot = self.ax.plot(x_tgt, y_tgt, marker, c=color, markersize=markersizes[i_], zorder=1000) if with_directions: direction_dict[tgt] = (x_tgt, y_tgt, tgt_tp[tgt, 2], tgt_tp[tgt, 3], direction_color, self.shaft_width, quiver_style) if annotate: self.ax.annotate('%d' % tgt, (x_tgt + 0.01, y_tgt + 0.01), fontsize=12) return plot
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()
#p_log_shifted.sort() #p_log_shifted = p_log_shifted[-n:] #print 'log(p) shifted min max mean std', p_log_shifted.min(), p_log_shifted.max(), p_log_shifted.mean(), p_log_shifted.std() n_bins = 200 n, bins = np.histogram(d[:, 2], bins=n_bins) n_log, bins_log = np.histogram(p_log, bins=n_bins) n_w, bins_w = np.histogram(w, bins=n_bins) fig = pylab.figure() ax = fig.add_subplot(311) ax.bar(bins[:-1], n, width = bins[1] - bins[0], label='p_ij') ax = fig.add_subplot(312) ax.bar(bins_log[:-1], n_log, width = bins_log[1] - bins_log[0], label='log(p_ij)') ax = fig.add_subplot(313) ax.bar(bins_w[:-1], n_w, width = bins_w[1] - bins_w[0], label='weights') pylab.legend() w_min, w_max = 0.0001, 0.005 w = utils.linear_transformation(p_top, w_min, w_max) fig = pylab.figure() ax = fig.add_subplot(111) ax.plot(p_top, w, label='p -> weight transformation') pylab.show()
def plot_tgt_connections(self, conn_type, gids_to_plot=None, fig_cnt=1): """ For all gids_to_plot all outgoing connections and the centroid / center of gravitiy is plotted. conn_type = ['ee', 'ei', 'ie', 'ii'] """ tp_src, tp_tgt = self.get_tp(conn_type) if gids_to_plot == None: if conn_type[0] == 'e': gids_to_plot = np.loadtxt(self.params['gids_to_record_fn'], dtype=np.int) gids_to_plot = [gids_to_plot[0]] else: gids_to_plot = np.random.randint(0, tp_src[:, 0].size, 1) fn = self.params['merged_conn_list_%s' % conn_type] print 'Loading:', fn if not os.path.exists(fn): print 'Merging connlists ...' cmd = 'python merge_connlists.py %s' % self.params['params_fn'] os.system(cmd) if not self.conn_lists.has_key(conn_type): self.load_connlist(conn_type) conn_list = self.conn_lists[conn_type] ax = self.fig.add_subplot(self.n_fig_y, self.n_fig_x, fig_cnt) for i_, src_gid in enumerate(gids_to_plot): (x, y, u, v) = tp_src[src_gid, :] tgts = utils.get_targets(conn_list, src_gid) tgt_ids = np.array(tgts[:, 1], dtype=np.int) weights = tgts[:, 2] delays = tgts[:, 3] print 'weights size', weights.size if weights.size > 0: c_x, c_v = self.get_cg_vec(tp_src[src_gid, :], tp_tgt[tgt_ids, :], weights) markersizes = utils.linear_transformation(weights, self.markersize_min, self.markersize_max) else: print '\n WARNING: Cell %d has no outgoing connections!\n' % src_gid c_x, c_v = [(0, 0), (0, 0)] markersizes = [] vector_conn_centroid_x_minus_vsrc = (c_x[0] - u, c_x[1] - v) # c_x *= 100. for j_, tgt_gid in enumerate(tgts[:, 1]): (x_tgt, y_tgt, u_tgt, v_tgt) = tp_tgt[tgt_gid, :] xdiff = (x_tgt - x) ydiff = (y_tgt - y) ax.plot(xdiff, ydiff, 'o', markersize=markersizes[j_], color='r') # ax.quiver( preferred_direction = ax.quiver(0, 0, u, v, angles='xy', scale_units='xy', scale=1, color='r', headwidth=3, width=self.shaft_width * 2, linewidths=(1,), edgecolors=('k'), zorder=100000) connection_centroid = ax.quiver(0, 0, c_x[0], c_x[1], angles='xy', scale_units='xy', scale=1, color='k', headwidth=3, width=self.shaft_width * 2, linewidths=(1,), edgecolors=('k'), zorder=100000) diff_v = ax.quiver(0, 0, vector_conn_centroid_x_minus_vsrc[0], vector_conn_centroid_x_minus_vsrc[1], angles='xy', scale_units='xy', scale=1, color='y', headwidth=3, width=self.shaft_width * 2, linewidths=(1,), edgecolors=('k'), zorder=100000) xlim = ax.get_xlim() ylim = ax.get_ylim() ax.plot((0, 0), (ylim[0], ylim[1]), 'k--') ax.plot((xlim[0], xlim[1]), (0, 0), 'k--') quiverkey_length = .05 * (xlim[1] - xlim[0] + ylim[1] - ylim[0]) ax.quiverkey(preferred_direction, .1, .85, quiverkey_length, 'Preferred direction') ax.quiverkey(connection_centroid, .1, .75, quiverkey_length, 'Connection centroid') ax.quiverkey(diff_v, .8, .95, quiverkey_length, 'Difference vector')