示例#1
0
def get_p_conn(tp_src, tp_tgt, w_sigma_x, w_sigma_v, connectivity_radius=1.0):
    """
    tp_src is a list/array with the 4 tuning property values of the source cell: x, y, u, v
        
    Latex code for formulas:
    \delta_{latency} = \frac{\sqrt{d_{torus}(x_0, x_1)^2 + d_{torus}(y_0, y_1)^2}}{\sqrt{u_0^2 + v_0^2}}
    x_{predicted} = x_0 + u_0 \cdot \delta_{latency}
    y_{predicted} = y_0 + v_0 \cdot \delta_{latency}
    p = exp(-\frac{(d_{torus}(x_{predicted}, x_1))^2 + (d_{torus}(y_{predicted}, y_1))^2}{2 \cdot \sigma_{space}^2})
        \cdot exp(-\frac{(u_0-u_1)^2 + (v_0 - v_1)^2}{2 \cdot \sigma_V^2})
 
    """

#    x0 = tp_src[0]
#    y0 = tp_src[1]
#    u0 = tp_src[2]
#    v0 = tp_src[3]
#    x1 = tp_tgt[0]
#    y1 = tp_tgt[1]
#    u1 = tp_tgt[2]
#    v1 = tp_tgt[3]
#    dx = utils.torus_distance(x0, x1)
#    dy = utils.torus_distance(y0, y1)
#    latency = np.sqrt(dx**2 + dy**2) / np.sqrt(u0**2 + v0**2)
#    x_predicted = x0 + u0 * latency  
#    y_predicted = y0 + v0 * latency  
#    p = np.exp(-.5 * (utils.torus_distance(x_predicted, x1))**2 / w_sigma_x**2 \
#               -.5 * (utils.torus_distance(y_predicted, y1))**2 / w_sigma_x**2) \
#      * np.exp(-.5 * (u0 - u1)**2 / w_sigma_v ** 2 \
#               -.5 * (v0 - v1)**2 / w_sigma_v ** 2)

    d_ij = utils.torus_distance2D(tp_src[0], tp_tgt[0], tp_src[1], tp_tgt[1])
    latency = d_ij / np.sqrt(tp_src[2]**2 + tp_src[3]**2)
#    if latency < connectivity_radius:
    x_predicted = tp_src[0] + tp_src[2] * latency
    y_predicted = tp_src[1] + tp_src[3] * latency
    sigma_x = w_sigma_x#* np.sqrt(latency)
    sigma_v = w_sigma_v# * np.sqrt(latency)
    v1 = (tp_src[2], tp_src[3])
    v2 = (tp_tgt[2], tp_tgt[3])
    p = np.exp(- (utils.torus_distance2D(x_predicted, tp_tgt[0], y_predicted, tp_tgt[1]))**2 / (2 * sigma_x**2)) \
            * np.exp( (np.dot(v1, v2) / (np.sqrt(np.dot(v1, v1) * np.dot(v2, v2)))) / sigma_v**2)
    return p, latency
示例#2
0
def get_distances(tp_src, tp_tgt):
    n_src = tp_src[:, 0].size
    n_tgt = tp_tgt[:, 0].size
    dist = np.zeros(n_src * n_tgt)
    for src in xrange(n_src):
        print '%d / %d' % (src, n_src)
        for tgt in xrange(n_tgt):
            idx = src * n_tgt + tgt
            dist[idx] = utils.torus_distance2D(tp_src[src, 0], tp_tgt[tgt, 0], tp_src[src, 1], tp_tgt[tgt, 1])
    return dist
示例#3
0
def get_exc_inh_connections(pred_pos, inh_pos, tp_exc, n=10):
    """
    This function calculates the adjacency matrix for the exc to inh connections.
    Input:
     pred_pos : array of x, y values storing the positions approximately predicted by exc cells (pred_pos = (x, y) + (u, v))
     pred_pos[i, 0] : x-pos of exc cell i
     pred_pos[i, 1] : y-pos of exc cell i
    
     inh_pos : same format as pred_pos, positions of inhibitory cells
     n : number of incoming connections per target cell

    Returns :
     one adjacency list with n_inh lines containing the exc cell indices connecting to the inh cell in the given line
     - one list of same size with the distances 
    """

    n_tgt = inh_pos[:, 0].size
    n_src = pred_pos[:, 0].size
    output_indices, output_distances = np.zeros((n_tgt, n)), np.zeros((n_tgt, n))
    for tgt in xrange(n_tgt):
        # calculate the distance between the target and all sources
        dist = np.zeros(n_src)
        x0, y0 = inh_pos[tgt, 0], inh_pos[tgt, 1]
#        for src in xrange(n_src):
#            x1, y1 = pred_pos[src, 0], pred_pos[src, 1]
#            dx = utils.torus_distance(x0, x1)
#            dy = utils.torus_distance(y0, y1)
#            dist[src] = np.sqrt(dx**2 + dy**2)
        # choose n most distance indices
#        idx = dist.argsort()[-n:]

        # calculate the scalar product between the vector exc-inh and the predicted vector
        abs_scalar_products = np.zeros(n_src)
        for src in xrange(n_src):
            x_e, y_e = tp_exc[src, 0], tp_exc[src, 1]
            x_pred, y_pred = pred_pos[src, 0], pred_pos[src, 1]
            v_exc_inh = (x0 - x_e, y0 - y_e)
            v_exc_pred = (tp_exc[src, 2], tp_exc[src, 3])
#            v_exc_pred= (x_pred - x_e, y_pred - y_e)
            abs_scalar_products[src] = abs(sum(v_exc_inh[i] * v_exc_pred[i] for i in xrange(len(v_exc_inh))))

        # choose those indices with smallest scalar product (smallest projection of v_exc_pred onto v_exc_inh)
        idx = abs_scalar_products.argsort()[:n]
        output_indices[tgt, :] = idx
        for i in xrange(n):
            src = idx[i]
            d_ij = utils.torus_distance2D(pred_pos[src, 0], inh_pos[tgt, 0], pred_pos[src, 1], inh_pos[tgt, 1])
            output_distances[tgt, i] = d_ij

    return output_indices, output_distances
示例#4
0
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']

#pylab.rcParams.update({'path.simplify' : False})
fig = pylab.figure()
ax1 = fig.add_subplot(211)
ax2 = fig.add_subplot(212)

for fn in sys.argv[1:]:
    gid = int(fn.rsplit('_')[-1].rsplit('.')[0])
    data = np.load(fn)
    x_axis = np.arange(data.size) * .1
    dist = np.zeros(data.size)
    for i in xrange(data.size):
        x_stim = mp[0] + x_axis[i] / params['t_sim'] * mp[2]
        y_stim = mp[1] + x_axis[i] / params['t_sim'] * mp[3]
        d_ij = utils.torus_distance2D(x_stim, tp[gid, 0], y_stim, tp[gid, 1])
        dist[i] = d_ij

    t_min = np.argmin(dist)
    print gid, t_min, data[t_min], np.min(dist), 'mp:', mp, 'tp:', tp[gid, :]

    ax1.plot(x_axis, data, lw=1, label=str(gid))
    ax2.plot(x_axis, dist, lw=1, label=str(gid))

#    ax1.set_title(fn)
#pylab.legend()
pylab.show()
    def connect_isotropic(self, conn_type='ee'):
        """
        conn_type must be 'ee', 'ei', 'ie' or 'ii'
        Connect cells in a distant dependent manner:
            p_ij = exp(- d_ij / (2 * w_sigma_x**2))

        This will give a 'convergence constrained' connectivity, i.e. each cell will have the same sum of incoming weights 
        ---> could be problematic for outlier cells
        """
        if self.pc_id == 0:
            print 'Connect isotropic %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 conn_type == 'ee':
            w_= self.params['w_max']
            w_tgt_in = params['w_tgt_in_per_cell_%s' % conn_type]

        elif conn_type == 'ei':
            w_= self.params['w_ie_mean']
            w_tgt_in = params['w_tgt_in_per_cell_%s' % conn_type]

        elif conn_type == 'ie':
            w_= self.params['w_ie_mean']
            w_tgt_in = params['w_tgt_in_per_cell_%s' % conn_type]

        elif conn_type == 'ii':
            w_= self.params['w_ii_mean']
            w_tgt_in = params['w_tgt_in_per_cell_%s' % 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 = ''

        p_max = utils.get_pmax(self.params['p_%s' % conn_type])
        for tgt in tgt_cells:
            w = np.zeros(n_src, dtype='float32') 
            delays = np.zeros(n_src, dtype='float32')
            for src in xrange(n_src):
                if (src != tgt):
#                    d_ij = np.sqrt((tp_src[src, 0] - tp_tgt[tgt, 0])**2 + (tp_src[src, 1] - tp_tgt[tgt, 1])**2)
                    d_ij = utils.torus_distance2D(tp_src[src, 0], tp_tgt[tgt, 0], tp_src[src, 1], tp_tgt[tgt, 1])
                    p_ij = p_max * np.exp(-d_ij / (2 * params['w_sigma_x']**2))
                    if np.random.rand() <= p_ij:
                        w[src] = w_
                        delays[src] = d_ij * self.params['delay_scale']
            w *= w_tgt_in / w.sum()
            srcs = w.nonzero()[0]
            for src in srcs:
                if w[src] > self.params['w_thresh_connection']:
                    delay = min(max(delays[src], self.params['delay_range'][0]), self.params['delay_range'][1])  # map the delay into the valid range
                    connect(src_pop[int(src)], tgt_pop[int(tgt)], w[src], delay=delay, synapse_type=syn_type)
                    output += '%d\t%d\t%.2e\t%.2e\n' % (src, tgt, w[src], delay) 
    #                connect(src_pop[int(src)], tgt_pop[int(tgt)], w[src], delay=params['standard_delay'], synapse_type=syn_type)
    #                output += '%d\t%d\t%.2e\t%.2e\n' % (src, tgt, w[src], params['standard_delay']) 
                    
        if self.debug_connectivity:
            if self.pc_id == 0:
                print 'DEBUG writing to file:', conn_list_fn
            conn_file.write(output)
            conn_file.close()
示例#6
0
import numpy as np

x, y = 0.0, 0.5 # point 1 
x0, y0, u0, v0 = .5, .5, .5, 0.0 # movement parameters
dt = 0.05

n = 200
d = np.zeros((n, 2))
print 'x_pos', '\t', 'x_pos % 1', '\t', 'y_pos', '\t', 'np.sqrt(dx**2 + dy**2)'
for i in xrange(n):
    x_pos = (x0 + dt * i * u0) % 1.
    y_pos = (y0 + dt * i * v0) % 1.
    dx = utils.torus_distance(x, x_pos)
    dy = utils.torus_distance(y, y_pos)
#    dx = utils.torus_distance(x_pos, x)
#    dy = utils.torus_distance(y_pos, y)
#    d[i, 0] = dt * i
#    d[i, 1] = dx
#    d[i, 0] = dt * i
#    d[i, 1] = dx
    d[i, 0] = dx
    d[i, 1] = dy
    d_ij = utils.torus_distance2D(x, x_pos, y, y_pos)
    print x_pos, '\t', x_pos % 1, '\t\t', y_pos, '\t', np.sqrt(dx**2 + dy**2), d_ij
#    print x_pos, '\t', x_pos % 1, '\t', y_pos, '\t', dx, '\t', dy

print 'x_pos', '\t', 'x_pos % 1', '\t', 'y_pos', '\t', 'np.sqrt(dx**2 + dy**2)'
np.savetxt('delme_torus_movement.dat', d)