Beispiel #1
0
def I_networks(landscape,
               nrow,
               ncol,
               ncon,
               kappa,
               theta,
               shift=0,
               seed=0,
               **kwargs):
    np.random.seed(seed)
    npop = nrow * ncol

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

    conmat = []
    for ii in range(npop):
        targets, delay = lcrn.lcrn_gamma_targets(ii, nrow, ncol, nrow, ncol,
                                                 ncon, kappa, theta)
        if landscape['mode'] != 'symmetric':  # asymmetry
            targets = (targets + shift * move[ll[ii] % len(move)]) % npop
        targets = targets[targets != ii]  # no selfconnections
        hist_targets = np.histogram(targets, bins=range(npop + 1))[0]
        conmat.append(hist_targets)

    return np.array(conmat)
Beispiel #2
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)
Beispiel #3
0
noise = nest.Create('noise_generator')

# Create recording devices
sd = nest.Create('spike_detector',
                 params={
                     'start': p.recstart,
                     'to_file': True,
                     'label': output_file,
                 })
"""
Connect nodes
"""

landscape = cl.__dict__[p.landscape['mode']](p.nrow,
                                             p.landscape.get('specs', {}))
move = cl.move(p.nrow)
offset = pop[0]

# Connect neurons to neurons
for ii in range(npop):
    source = ii, p.nrow, p.ncol, p.nrow, p.ncol, p.ncon, p.kappa, p.theta
    targets, delay = lcrn.lcrn_gamma_targets(*source)
    if landscape is not None:  # asymmetry
        targets = (targets + p.shift * move[landscape[ii] % len(move)]) % npop
    # no selfconnections
    targets = targets[targets != ii]
    nest.Connect([pop[ii]], (targets + offset).tolist(),
                 syn_spec={'weight': p.Ji})

# Connect noise input device to all neurons
nest.Connect(noise, pop)
"""
Get spatial connection landscape
"""

# landscape = None                                        # Symmetric
# landscape = cl.random(nrowE, {'seed': 0})             # Homogeneous
# landscape = cl.homogeneous(nrowE, {'phi': 3})           # Homogeneous
# landscape = cl.Perlin(nrowE, {'size': 4})             # Perlin
landscape = cl.Perlin_uniform(nrowE, {'size': 4, 'base': 0})  # Perlin uniform


"""
Connect neurons
"""

move = cl.move(nrowE)
offsetE = popE[0]
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
Beispiel #5
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]
Beispiel #6
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]