def connect_anisotropic(self, conn_type):
        """
        conn_type = ['ee', 'ei', 'ie', 'ii']
        """
        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)

        n_src_cells_per_neuron = int(round(self.params["p_%s" % conn_type] * n_src))
        (delay_min, delay_max) = self.params["delay_range"]
        local_connlist = np.zeros((n_src_cells_per_neuron * len(tgt_cells), 4))
        for i_, tgt in enumerate(tgt_cells):
            if self.params["direction_based_conn"]:
                p, latency = CC.get_p_conn_vec_xpred(
                    tp_src,
                    tp_tgt[tgt, :],
                    self.params["w_sigma_x"],
                    self.params["w_sigma_v"],
                    self.params["connectivity_radius"],
                )
            else:
                p, latency = CC.get_p_conn_vec(
                    tp_src,
                    tp_tgt[tgt, :],
                    self.params["w_sigma_x"],
                    self.params["w_sigma_v"],
                    self.params["connectivity_radius"],
                    self.params["maximal_latency"],
                )
            if conn_type[0] == conn_type[1]:
                p[tgt], latency[tgt] = 0.0, 0.0
            # random delays? --> np.permutate(latency) or latency[sources] * self.params['delay_scale'] * np.rand

            sorted_indices = np.argsort(p)
            if conn_type[0] == "e":
                sources = sorted_indices[-n_src_cells_per_neuron:]
            else:  # source = inhibitory
                if conn_type[0] == conn_type[1]:
                    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]

            #            eta = 1e-9
            eta = 0
            w = (self.params["w_tgt_in_per_cell_%s" % conn_type] / (p[sources].sum() + eta)) * p[sources]
            #            print 'debug p', i_, tgt, p[sources]
            #            print 'debug sources', i_, tgt, sources
            #            print 'debug w', i_, tgt, w

            delays = np.minimum(
                np.maximum(latency[sources] * self.params["delay_scale"], delay_min), delay_max
            )  # map the delay into the valid range
            conn_list = np.array((sources, tgt * np.ones(n_src_cells_per_neuron), w, delays))
            local_connlist[i_ * n_src_cells_per_neuron : (i_ + 1) * n_src_cells_per_neuron, :] = conn_list.transpose()
            connector = FromListConnector(conn_list.transpose())
            if self.params["with_short_term_depression"]:
                prj = Projection(
                    src_pop, tgt_pop, connector, target=syn_type, synapse_dynamics=self.short_term_depression
                )
            else:
                prj = Projection(src_pop, tgt_pop, connector, target=syn_type)
            self.projections[conn_type].append(prj)

        if self.debug_connectivity:
            if self.pc_id == 0:
                print "DEBUG writing to file:", conn_list_fn
            np.savetxt(conn_list_fn, local_connlist, fmt="%d\t%d\t%.4e\t%.4e")
Ejemplo n.º 2
0
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