コード例 #1
0
 def get_weights(self):
     conn_list_fn = self.params['conn_list_ee_fn_base'] + '0.dat'
     self.conn_mat, self.delays = utils.convert_connlist_to_matrix(conn_list_fn, self.params['n_exc'], self.params['n_exc'])
     self.w_in_sum = np.zeros(self.params['n_exc'])
     n_cells = self.params['n_exc']
     for i in xrange(n_cells):
         self.w_in_sum[i] = self.conn_mat[:, i].sum()
コード例 #2
0
ファイル: PlotConductances.py プロジェクト: MinaKh/bcpnn-mt
    def plot_conductance_composition(self):

        self.load_nspikes()
        if self.no_spikes:
            return

        self.load_input_spikes()
        self.g_exc_noise = self.params['w_exc_noise'] * self.params['tau_syn_exc'] * self.params['f_exc_noise']
        self.g_inh_noise = self.params['w_inh_noise'] * self.params['tau_syn_inh'] * self.params['f_inh_noise']

        conn_list_ee = self.params['merged_conn_list_ee']
        conn_list_ei = self.params['merged_conn_list_ei']
        conn_list_ie = self.params['merged_conn_list_ie']
        conn_list_ii = self.params['merged_conn_list_ii']
        if not os.path.exists(conn_list_ee):
            os.system("python merge_connlists.py")

        print 'Getting connection matrices ...'
        w_ee, delays_ee = utils.convert_connlist_to_matrix(conn_list_ee, self.params['n_exc'], self.params['n_exc'])
        w_ei, delays_ei = utils.convert_connlist_to_matrix(conn_list_ei, self.params['n_exc'], self.params['n_inh'])
        w_ie, delays_ie = utils.convert_connlist_to_matrix(conn_list_ie, self.params['n_inh'], self.params['n_exc'])
        w_ii, delays_ii = utils.convert_connlist_to_matrix(conn_list_ii, self.params['n_inh'], self.params['n_inh'])
        c_ee = self.get_cond_matrix(self.nspikes_exc, w_ee, 'ee')
        c_ei = self.get_cond_matrix(self.nspikes_exc, w_ei, 'ei')
        c_ie = self.get_cond_matrix(self.nspikes_inh, w_ie, 'ie')
        c_ii = self.get_cond_matrix(self.nspikes_inh, w_ii, 'ii')

        self.create_fig()
        self.n_fig_x, self.n_fig_y = 1, 1

        color_net_exc = 'r'
        color_net_inh = 'b'
        color_stim = 'g'
        color_noise = 'w'

        ax = self.fig.add_subplot(111)
        lw = 4
        width=.5
        for gid in xrange(self.params['n_exc']):
            x = self.nspikes_exc[gid]
            y0 = self.g_stim[gid]
            y1 = c_ee[:, gid].sum()
            y3 = c_ie[:, gid].sum()
            ax.bar(x, y0, width=width, color=color_stim)
            ax.bar(x, y1, width=width, bottom=y0, color=color_net_exc)
#            ax.bar(x, self.g_exc_noise, width=width, bottom=y1+y0, color=color_noise)
            ax.bar(x, -y3, width=width, color=color_net_inh)
コード例 #3
0
ファイル: CheckDelayScale.py プロジェクト: MinaKh/bcpnn-mt
 def print_delays(self):
     fn = self.params['merged_conn_list_ee']
     if not os.path.exists(fn):
         print 'File: %s not found\nCalling merge_connlists.py now...\n'
         os.system('python merge_connlists.py')
     conn_mat, delays = utils.convert_connlist_to_matrix(fn, self.params['n_exc'], self.params['n_exc'])
     for i_, src  in enumerate(self.gids_to_plot):
         for j_, tgt in enumerate(self.gids_to_plot):
             if src != tgt:
                 t1 = self.time_of_max_stim[src] 
                 t2 = self.time_of_max_stim[tgt] 
                 w, delay = conn_mat[src, tgt], delays[src, tgt]
                 if t1 < t2:
                     optimal_tau_prediction = (t2 - t1) / self.params['t_stimulus']
                     optimal_delay_scale = delay / (self.params['delay_scale'] * (t2 - t1))
                     print '%d (%d)\t->\t%d (%d)\t: dt_max_stim = %.1f\toptimal_tau_prediction = %.1f\toptimal_delay_scale = %.1f' % (src, t1, tgt, t2, t2 - t1, optimal_tau_prediction, optimal_delay_scale)
コード例 #4
0
    def load_connection_matrices(self, conn_type):
        """
        deprecated - should not be used because of unnecessary memory consumption
        use load_connection_list instead to get sources / targets
        """

        if conn_type == 'ee':
            n_src, n_tgt = self.params['n_exc'], self.params['n_exc']
            loaded = self.conn_mat_loaded[0]
        elif conn_type == 'ei':
            n_src, n_tgt = self.params['n_exc'], self.params['n_inh']
            loaded = self.conn_mat_loaded[1]
        elif conn_type == 'ie':
            n_src, n_tgt = self.params['n_inh'], self.params['n_exc']
            loaded = self.conn_mat_loaded[2]
        elif conn_type == 'ii':
            n_src, n_tgt = self.params['n_inh'], self.params['n_inh']
            loaded = self.conn_mat_loaded[3]

        if loaded:
            return

        conn_mat_fn = self.params['conn_mat_fn_base'] + '%s.dat' % (conn_type)
        delay_mat_fn = self.params['delay_mat_fn_base'] + '%s.dat' % (conn_type)
        if os.path.exists(conn_mat_fn):
            print 'Loading', conn_mat_fn
            self.connection_matrices[conn_type] = np.loadtxt(conn_mat_fn)
        #    delays_ee = np.loadtxt(delay_mat_ee_fn)
        else:
            self.connection_matrices[conn_type], self.delays[conn_type] = utils.convert_connlist_to_matrix(params['merged_conn_list_%s' % conn_type], n_src, n_tgt)
            np.savetxt(conn_mat_fn, self.connection_matrices[conn_type])
#            np.savetxt(delay_mat_fn, self.delays[conn_type])
            
        if conn_type == 'ee':
            self.conn_mat_loaded[0] = True
        elif conn_type == 'ei':
            self.conn_mat_loaded[1] = True
        elif conn_type == 'ie':
            self.conn_mat_loaded[2] = True
        elif conn_type == 'ii':
            self.conn_mat_loaded[3] = True
コード例 #5
0
elif conn_type == 'ie':
    n_src, n_tgt = params['n_inh'], params['n_exc']
elif conn_type == 'ii':
    n_src, n_tgt = params['n_inh'], params['n_inh']

conn_list_fn = params['merged_conn_list_%s' % conn_type]
print 'Loading: ', conn_list_fn

conn_mat_fn = params['conn_mat_fn_base'] + '%s.dat' % (conn_type)
#delay_mat_fn = params['delay_mat_fn_base'] + '%s.dat' % (conn_type)
if os.path.exists(conn_mat_fn):
    print 'Loading', conn_mat_fn
    w = np.loadtxt(conn_mat_fn)
#    delays_ee = np.loadtxt(delay_mat_ee_fn)
else:
    w, delays = utils.convert_connlist_to_matrix(params['merged_conn_list_%s' % conn_type], n_src, n_tgt)
    print 'Saving:', conn_mat_fn
    np.savetxt(conn_mat_fn, w)

print 'Weights: min %.2e median %.2e max %.2e mean %.2e st %.2e' % (w.min(), w.max(), np.median(w), w.mean(), w.std())
fig = pylab.figure()
ax = fig.add_subplot(111)
print "plotting ...."
title = 'Connection matrix %s \nw_sigma_x(v): %.1f (%.1f)' % (conn_type, params['w_sigma_x'], params['w_sigma_v'])
ax.set_title(title)
cax = ax.pcolormesh(w)#, edgecolor='k', linewidths='1')
ax.set_ylim(0, w.shape[0])
ax.set_xlim(0, w.shape[1])
ax.set_ylabel('Target')
ax.set_xlabel('Source')
pylab.colorbar(cax)
コード例 #6
0
def get_cond_matrix(nspikes, w):
    cond_matrix = np.zeros((params['n_exc'], params['n_exc']))
    for tgt in xrange(params['n_exc']):
        for src in xrange(params['n_exc']):
            if src != tgt:
                cond_matrix[src, tgt] =  w[src, tgt] * nspikes[src]
    return cond_matrix



# compute everything
input_cond = calculate_input_cond()
os.system("python merge_connlists.py")
conn_list_fn = params['merged_conn_list_ee']
print 'debug', conn_list_fn
w, delays = utils.convert_connlist_to_matrix(conn_list_fn, params['n_exc'], params['n_exc'])
cond_matrix = get_cond_matrix(nspikes, w)
np.savetxt(params['tmp_folder'] + 'input_cond.dat', input_cond)
np.savetxt(params['tmp_folder'] + 'cond_matrix.dat', cond_matrix)

# or load the computed cond_matrix etc (for replotting)
#input_cond = np.loadtxt(params['tmp_folder'] + 'input_cond.dat')
#cond_matrix = np.loadtxt(params['tmp_folder'] + 'cond_matrix.dat')

summed_network_cond = np.zeros(params['n_exc'])
for tgt in xrange(params['n_exc']):
    summed_network_cond[tgt] = cond_matrix[:, tgt].sum()



コード例 #7
0
ファイル: get_gids_to_record.py プロジェクト: MinaKh/bcpnn-mt
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)'
print "\nGID\tnspikes\tdistance_to_stim\tw_out_good\tw_in_good\tw_out_total\tw_in_total\ttuning_prop"
コード例 #8
0
#    cax = ax.pcolor(data)#, edgecolor='k', linewidths='1')
#    ax.set_ylim(0, data.shape[0])
#    ax.set_xlim(0, data.shape[1])
#    pylab.colorbar(cax)

    #cax = ax.pcolor(data, cmap='binary')
    #cax = ax.pcolor(data, cmap='RdBu')
    #cax = ax.imshow(data[:,:12])

if (n_dw > 0):
#    dws = [np.zeros((n_cells, n_cells)) for i in xrange(n_dw)]
    # plot the difference weight matrix
    for i in xrange(len(fns)-1):
        fn1 = fns[i]
        fn2 = fns[i+1]
        d1 = utils.convert_connlist_to_matrix(fn1, n_cells)
        d2 = utils.convert_connlist_to_matrix(fn2, n_cells)
        dw = d2 - d1
        data = dw

        print "plotting dw"
        fig = pylab.figure()
        ax = fig.add_subplot(121)
        ax.set_title("Difference %s \n- %s" % (fn1, fn2))
        cax = ax.pcolor(data)#, edgecolor='k', linewidths='1')
        #cax = ax.pcolor(data, cmap='binary')
        #cax = ax.pcolor(data, cmap='RdBu')
        #cax = ax.imshow(data[:,:12])
        ax.set_ylim(0, data.shape[0])
        ax.set_xlim(0, data.shape[1])
        pylab.colorbar(cax)