Example #1
0
def EI_networks(landscape,
                nrowE,
                ncolE,
                nrowI,
                ncolI,
                p,
                stdE,
                stdI,
                shift=0,
                seed=0,
                **kwargs):
    np.random.seed(seed)
    npopE = nrowE * ncolE
    npopI = nrowI * ncolI

    if landscape['mode'] != 'symmetric':
        move = cl.move(nrowE)
        ll = cl.__dict__[landscape['mode']](nrowE, landscape.get('specs', {}))

    conmatEE, conmatEI, conmatIE, conmatII = [], [], [], []
    for idx in range(npopE):
        # E -> E
        source = idx, nrowE, ncolE, nrowE, ncolE, int(p * npopE), stdE, False
        targets, delay = lcrn.lcrn_gauss_targets(*source)
        if landscape['mode'] != 'symmetric':  # asymmetry
            targets = (targets + shift * move[ll[idx] % len(move)]) % npopE
        targets = targets[targets != idx]
        hist_targets = np.histogram(targets, bins=range(npopE + 1))[0]
        conmatEE.append(hist_targets)

        # E -> I
        source = idx, nrowE, ncolE, nrowI, ncolI, int(p * npopI), stdI, False
        targets, delay = lcrn.lcrn_gauss_targets(*source)
        hist_targets = np.histogram(targets, bins=range(npopI + 1))[0]
        conmatEI.append(hist_targets)

    for idx in range(npopI):
        # I -> E
        source = idx, nrowI, ncolI, nrowE, ncolE, int(p * npopE), stdE, False
        targets, delay = lcrn.lcrn_gauss_targets(*source)
        hist_targets = np.histogram(targets, bins=range(npopE + 1))[0]
        conmatIE.append(hist_targets)

        # I -> I
        source = idx, nrowI, ncolI, nrowI, ncolI, int(p * npopI), stdI, False
        targets, delay = lcrn.lcrn_gauss_targets(*source)
        targets = targets[targets != idx]
        hist_targets = np.histogram(targets, bins=range(npopI + 1))[0]
        conmatII.append(hist_targets)

    return np.array(conmatEE), np.array(conmatEI), np.array(
        conmatIE), np.array(conmatII)
offsetI = popI[0]

p = 0.05                    # 0.05 - 0.1
stdE = 12
stdI = 9                    # 9 - 11
shift = 1                   # 1 - 3
Jx = 10.0
g = 8                       # 4 - 8


syn_specE = {'weight': Jx}
for idx in range(npopE):

    # E-> E
    source = idx, nrowE, ncolE, nrowE, ncolE, int(p * npopE), stdE
    targets, delay = lcrn.lcrn_gauss_targets(*source)
    if landscape is not None:  # asymmetry
        targets = (targets + shift * move[landscape[idx] % len(move)]) % npopE
    targets = targets[targets != idx]
    nest.Connect([popE[idx]], (targets + offsetE).tolist(), syn_spec=syn_specE)

    # E-> I
    source = idx, nrowE, ncolE, nrowI, ncolI, int(p * npopI), stdI
    targets, delay = lcrn.lcrn_gauss_targets(*source)
    nest.Connect([popE[idx]], (targets + offsetI).tolist(), syn_spec=syn_specE)

syn_specI = {'weight': g * -Jx}
for idx in range(npopI):

    # I-> E
    source = idx, nrowI, ncolI, nrowE, ncolE, int(p * npopE), stdE
Example #3
0
def create_connectivity_EI_dir(neuron_parameters, connectivity_parameters,
                               save_AM_parameters):
    [
        nrowE, ncolE, nrowI, ncolI, nE, nI, nN, neuron_type, neuron_paramsE,
        neuron_paramsI
    ] = neuron_parameters
    [
        landscape_type, landscape_size, asymmetry, p, std, separation, width,
        alpha, seed
    ] = connectivity_parameters
    [pEE, pEI, pIE, pII] = p
    [stdEE, stdEI, stdIE, stdII] = std
    [AM_address, fname] = save_AM_parameters

    if asymmetry[0] == 'E':
        nrowL = nrowE
    else:
        nrowL = nrowI

    if landscape_type == 'symmetric':
        landscape = None
    elif landscape_type == 'random':
        landscape = cl.random(nrowL, {'seed': 0})
    elif landscape_type == 'homogenous':
        landscape = cl.homogeneous(nrowL, {'phi': 3})
    elif landscape_type == 'perlin':
        landscape = cl.Perlin(nrowL, {'size': int(landscape_size)})
    elif landscape_type == 'perlinuniform':
        landscape = cl.Perlin_uniform(nrowL, {
            'size': int(landscape_size),
            'base': seed
        })

    iso_AM = np.zeros((nN, nN))
    dir_AM = np.zeros((nN, nN))

    [alphaEE, alphaEI, alphaIE, alphaII] = [0, 0, 0, 0]
    if asymmetry == 'EE':
        alphaEE = alpha
    elif asymmetry == 'EI':
        alphaEI = alpha
    elif asymmetry == 'IE':
        alphaIE = alpha
    elif asymmetry == 'II':
        alphaII = alpha

    for idx in range(nE):

        targets, delays = lcrn.lcrn_gauss_targets(
            idx, nrowE, ncolE, nrowE, ncolE, int(pEE * nE * (1 - alphaEE)),
            stdEE)
        targets = targets[targets != idx]
        if asymmetry == 'EE':
            if landscape is not None:
                direction = landscape[idx]
                dir_targets = dirconn.get_directional_targets(
                    idx, nrowE, ncolE, nrowE, ncolE, direction, separation,
                    width, int(pEE * nE * alphaEE))
                dir_targets = dir_targets[dir_targets != idx]
                targets = np.setdiff1d(targets, dir_targets)
                dir_AM[idx, dir_targets] = 1.
        iso_AM[idx, targets] = 1.

        targets, delays = lcrn.lcrn_gauss_targets(
            idx, nrowE, ncolE, nrowI, ncolI, int(pEI * nI * (1 - alphaEI)),
            stdEI)
        if asymmetry == 'EI':
            if landscape is not None:
                direction = landscape[idx]
                dir_targets = dirconn.get_directional_targets(
                    idx, nrowE, ncolE, nrowI, ncolI, direction, separation,
                    width, int(pEI * nI * alphaEI))
                targets = np.setdiff1d(targets, dir_targets)
                dir_AM[idx, dir_targets + nE] = 1.
        iso_AM[idx, targets + nE] = 1.

    for idx in range(nI):

        targets, delays = lcrn.lcrn_gauss_targets(
            idx, nrowI, ncolI, nrowE, ncolE, int(pIE * nE * (1 - alphaIE)),
            stdIE)
        if asymmetry == 'IE':
            if landscape is not None:
                direction = landscape[idx]
                dir_targets = dirconn.get_directional_targets(
                    idx, nrowI, ncolI, nrowE, ncolE, direction, separation,
                    width, int(pIE * nE * alphaIE))
                targets = np.setdiff1d(targets, dir_targets)
                dir_AM[idx + nE, dir_targets] = 1.
        iso_AM[idx + nE, targets] = 1.

        targets, delays = lcrn.lcrn_gauss_targets(
            idx, nrowI, ncolI, nrowI, ncolI, int(pII * nI * (1 - alphaII)),
            stdII)
        targets = targets[targets != idx]
        if asymmetry == 'II':
            if landscape is not None:
                direction = landscape[idx]
                dir_targets = dirconn.get_directional_targets(
                    idx, nrowI, ncolI, nrowI, ncolI, direction, separation,
                    width, int(pII * nI * alphaII))
                dir_targets = dir_targets[dir_targets != idx]
                targets = np.setdiff1d(targets, dir_targets)
                dir_AM[idx + nE, dir_targets + nE] = 1.
        iso_AM[idx + nE, targets + nE] = 1.

    print('Multiple connections')
    print(np.where(iso_AM + dir_AM > 1.))

    sparse.save_npz(AM_address + fname + 'isoAM', sparse.coo_matrix(iso_AM))
    sparse.save_npz(AM_address + fname + 'dirAM', sparse.coo_matrix(dir_AM))
    sparse.save_npz(AM_address + fname + 'landscape',
                    sparse.coo_matrix(landscape))

    return [iso_AM, dir_AM, landscape, nrowL]
Example #4
0
def create_connectivity_EI_random_dir(neuron_parameters,
                                      connectivity_parameters,
                                      save_AM_parameters):
    [
        nrowE, ncolE, nrowI, ncolI, nE, nI, nN, neuron_type, neuron_paramsE,
        neuron_paramsI
    ] = neuron_parameters
    [landscape_type, landscape_size, asymmetry, p, shift, std, alpha,
     seed] = connectivity_parameters
    [pEE, pEI, pIE, pII] = p
    [stdEE, stdEI, stdIE, stdII] = std
    [AM_address, fname] = save_AM_parameters

    if asymmetry[0] == 'E':
        nrowL = nrowE
    else:
        nrowL = nrowI

    if asymmetry[-1] == 'E':
        nrowM = nrowE
    else:
        nrowM = nrowI
    move = cl.move(nrowM)

    if landscape_type == 'symmetric':
        landscape = None
    elif landscape_type == 'random':
        landscape = cl.random(nrowL, {'seed': 0})
    elif landscape_type == 'homogenous':
        landscape = cl.homogeneous(nrowL, {'phi': 3})
    elif landscape_type == 'perlin':
        landscape = cl.Perlin(nrowL, {'size': int(landscape_size)})
    elif landscape_type == 'perlinuniform':
        landscape = cl.Perlin_uniform(nrowL, {
            'size': int(landscape_size),
            'base': seed
        })

    ran_AM = np.zeros((nN, nN))
    dir_AM = np.zeros((nN, nN))

    [alphaEE, alphaEI, alphaIE, alphaII] = [0, 0, 0, 0]
    if asymmetry == 'EE':
        alphaEE = alpha
    elif asymmetry == 'EI':
        alphaEI = alpha
    elif asymmetry == 'IE':
        alphaIE = alpha
    elif asymmetry == 'II':
        alphaII = alpha

    for idx in range(nE):

        targets = []
        if (asymmetry == 'EE') and (landscape is not None):
            targets, delays = lcrn.lcrn_gauss_targets(idx, nrowE, ncolE, nrowE,
                                                      ncolE,
                                                      int(pEE * nE * alphaEE),
                                                      stdEE)
            targets = (targets + shift * move[landscape[idx] % len(move)]) % nE
            targets = targets[targets != idx].astype(int)
            dir_AM[idx, targets] = 1.
        r_targets = get_random_targets(idx, nrowE, ncolE, nrowE, ncolE,
                                       int(pEE * nE * (1 - alphaEE)))
        r_targets = np.setdiff1d(r_targets, targets)
        ran_AM[idx, r_targets] = 1.

        targets = []
        if (asymmetry == 'EI') and (landscape is not None):
            targets, delays = lcrn.lcrn_gauss_targets(idx, nrowE, ncolE, nrowI,
                                                      ncolI,
                                                      int(pEI * nI * alphaEI),
                                                      stdEI)
            targets = (targets + shift * move[landscape[idx] % len(move)]) % nI
            dir_AM[idx, targets + nE] = 1.
        r_targets = get_random_targets(idx, nrowE, ncolE, nrowI, ncolI,
                                       int(pEI * nI * (1 - alphaEI)))
        r_targets = np.setdiff1d(r_targets, targets)
        ran_AM[idx, r_targets + nE] = 1.

    for idx in range(nI):

        targets = []
        if (asymmetry == 'IE') and (landscape is not None):
            targets, delays = lcrn.lcrn_gauss_targets(idx, nrowI, ncolI, nrowE,
                                                      ncolE,
                                                      int(pIE * nE * alphaIE),
                                                      stdIE)
            targets = (targets + shift * move[landscape[idx] % len(move)]) % nI
            dir_AM[idx + nE, targets] = 1.
        r_targets = get_random_targets(idx, nrowI, ncolI, nrowE, ncolE,
                                       int(pIE * nE * (1 - alphaIE)))
        r_targets = np.setdiff1d(r_targets, targets)
        ran_AM[idx + nE, r_targets] = 1.

        targets = []
        if (asymmetry == 'II') and (landscape is not None):
            targets, delays = lcrn.lcrn_gauss_targets(idx, nrowI, ncolI, nrowI,
                                                      ncolI,
                                                      int(pII * nI * alphaII),
                                                      stdII)
            targets = (targets + shift * move[landscape[idx] % len(move)]) % nI
            targets = targets[targets != idx].astype(int)
            dir_AM[idx + nE, targets + nE] = 1.
        r_targets = get_random_targets(idx, nrowI, ncolI, nrowI, ncolI,
                                       int(pII * nI * (1 - alphaII)))
        r_targets = np.setdiff1d(r_targets, targets)
        ran_AM[idx + nE, r_targets + nE] = 1.

    print('Multiple connections')
    print(np.where(ran_AM + dir_AM > 1.))

    sparse.save_npz(AM_address + fname + 'random_rAM',
                    sparse.coo_matrix(ran_AM))
    sparse.save_npz(AM_address + fname + 'random_dAM',
                    sparse.coo_matrix(dir_AM))
    sparse.save_npz(AM_address + fname + 'landscape',
                    sparse.coo_matrix(landscape))

    return [ran_AM, dir_AM, landscape, nrowL]
Example #5
0
def create_connectivity_EI(neuron_parameters, connectivity_parameters,
                           save_AM_parameters):
    [
        nrowE, ncolE, nrowI, ncolI, nE, nI, nN, neuron_type, neuron_paramsE,
        neuron_paramsI
    ] = neuron_parameters
    [landscape_type, landscape_size, asymmetry, p, std, shift,
     seed] = connectivity_parameters
    [pEE, pEI, pIE, pII] = p
    [stdEE, stdEI, stdIE, stdII] = std
    [AM_address, fname] = save_AM_parameters

    if asymmetry[0] == 'E':
        nrowL = nrowE
    else:
        nrowL = nrowI

    if asymmetry[-1] == 'E':
        nrowM = nrowE
    else:
        nrowM = nrowI

    move = cl.move(nrowM)

    if landscape_type == 'symmetric':
        landscape = None
    elif landscape_type == 'random':
        landscape = cl.random(nrowL, {'seed': 0})
    elif landscape_type == 'homogenous':
        landscape = cl.homogeneous(nrowL, {'phi': 3})
    elif landscape_type == 'perlin':
        landscape = cl.Perlin(nrowL, {'size': int(landscape_size)})
    elif landscape_type == 'perlinuniform':
        landscape = cl.Perlin_uniform(nrowL, {
            'size': int(landscape_size),
            'base': seed
        })

    AM = np.zeros((nN, nN))

    for idx in range(nE):

        targets, delays = lcrn.lcrn_gauss_targets(idx, nrowE, ncolE, nrowE,
                                                  ncolE, int(pEE * nE), stdEE)
        if asymmetry == 'EE':
            if landscape is not None:
                targets = (targets +
                           shift * move[landscape[idx] % len(move)]) % nE
        targets = targets[targets != idx].astype(int)
        AM[idx, targets] = 1.

        targets, delays = lcrn.lcrn_gauss_targets(idx, nrowE, ncolE, nrowI,
                                                  ncolI, int(pEI * nI), stdEI)
        if asymmetry == 'EI':
            if landscape is not None:
                targets = (
                    (targets + shift * move[landscape[idx] % len(move)]) %
                    nI).astype(int)
        AM[idx, targets + nE] = 1.

    for idx in range(nI):

        targets, delays = lcrn.lcrn_gauss_targets(idx, nrowI, ncolI, nrowE,
                                                  ncolE, int(pIE * nE), stdIE)
        if asymmetry == 'IE':
            if landscape is not None:
                targets = (
                    (targets + shift * move[landscape[idx] % len(move)]) %
                    nE).astype(int)
        AM[idx + nE, targets] = 1.

        targets, delays = lcrn.lcrn_gauss_targets(idx, nrowI, ncolI, nrowI,
                                                  ncolI, int(pII * nI), stdII)
        if asymmetry == 'II':
            if landscape is not None:
                targets = (targets +
                           shift * move[landscape[idx] % len(move)]) % nI
        targets = targets[targets != idx].astype(int)
        AM[idx + nE, targets + nE] = 1.

    sparse.save_npz(AM_address + fname + 'normalAM', sparse.coo_matrix(AM))
    sparse.save_npz(AM_address + fname + 'landscape',
                    sparse.coo_matrix(landscape))

    return [AM, landscape, nrowL]