Example #1
0
def fire_area_analysis(fireRange, numberOfNodes, numberOfIterations):

    coverageList = []
    for f in fireRange:
        small = SmallWorldBrain(numberOfNodes=numberOfNodes,
                                averageDegree=5,
                                rewireProbability=0.15,
                                neuronThreshold=1,
                                refractoryPeriod=1,
                                numberOfIterations=numberOfIterations,
                                fractionToFire=f,
                                inhibitoryEdgeMultiplier=12,
                                fireRate=0.01,
                                directed=False)
        small.execute(makeRandom=False)
        coverageList.append(
            check_coverage(brain=small, numberOfNodes=numberOfNodes))
    plt.figure()
    plt.plot(
        np.linspace(0, numberOfIterations, len(coverageList)),
        coverageList,
        '.',
        label='Nodes=%d, ref=%d, threshold=%d, rewire=%.2f, time=%d' %
        (small.numberOfNodes, small.refractoryPeriod, small.neuronThreshold,
         small.rewireProbability, small.numberOfIterations))
    plt.xlabel('Fraction of Nodes Fired Selectively')
    plt.ylabel('Coverage of Network')
    plt.legend()
Example #2
0
def fire_rate_analysis(drivingRates, numberOfNodes, numberOfIterations):

    coverageList = []
    for r in drivingRates:
        small = SmallWorldBrain(numberOfNodes=numberOfNodes,
                                averageDegree=5,
                                rewireProbability=0.15,
                                neuronThreshold=1,
                                refractoryPeriod=1,
                                numberOfIterations=numberOfIterations,
                                fractionToFire=0.05,
                                inhibitoryEdgeMultiplier=12,
                                fireRate=r,
                                directed=False)
        small.execute()
        coverageList.append(
            check_coverage(brain=small, numberOfNodes=numberOfNodes))

    plt.figure()
    plt.plot(
        drivingRates,
        coverageList,
        '.',
        label='Nodes=%d, ref=%d, threshold=%d, rewire=%.2f, time=%d' %
        (small.numberOfNodes, small.refractoryPeriod, small.neuronThreshold,
         small.rewireProbability, small.numberOfIterations))
    plt.xlabel('Driving Rate')
    plt.ylabel('Coverage of Network')
    plt.legend()
def run_c_l_p_k_variation(k, seed, plot=True):
    np.random.seed(seed)
    random.seed(seed)
    print('Running for seed=', seed)
    ps = np.logspace(-3, -1, 15)
    ps = np.append(ps, np.linspace(0.15, 1, 15))
    #kList = [5, 7, 10, 15]
    if plot:
        plt.figure(figsize=(8,6))
        #colors = ['black', 'yellow', 'purple', 'green']

    pathlength = []
    ccoeff = []

    for p in ps:
        print(p)
        brain = SmallWorldBrain(numberOfNodes=10000, numberOfIterations=1000, rewireProbability=p, refractoryPeriod=1, fractionToFire=1/10000, neuronThreshold=1,
        fireRate=0.1, inhibitoryEdgeMultiplier=0, averageDegree=k, directed=False)
    
        pathlength.append(nx.average_shortest_path_length(brain.network))
        ccoeff.append(nx.average_clustering(brain.network))

    np.save('results/cpk_repeats/pathslengths_'+str(k)+'_'+str(seed), np.array(pathlength))
    np.save('results/cpk_repeats/clustercoeffs_'+str(k)+'_'+str(seed), np.array(ccoeff))

    if plot:
        frac = np.array(ccoeff)/np.array(pathlength)
        cubicspline = CubicSpline(ps, frac)
        ps_smooth = np.linspace(0.0005, 1, 100)
        plt.plot(ps, frac, '.', color='black')
        plt.plot(ps_smooth, cubicspline(ps_smooth), '-', color='black', label='$<k>$=%d' % k)
        plt.xlabel('$p_r$', size=16)
        plt.legend()
        plt.tick_params(labelsize=16)
        plt.ylabel('$C/L$', size=16)
def calculate_omega():
    ps = np.linspace(0.15, 1, 15)
    ps = np.append(ps, np.logspace(-3, -1, 15))
    omegas = []

    for p in ps:
        print('calculating omega for...', p)
        brain = SmallWorldBrain(numberOfNodes=10000, inhibitoryEdgeProbability=0, numberOfIterations=1000, 
            rewireProbability=p, averageDegree=8, neuronThreshold=1, refractoryPeriod=1, fractionToFire=0.01, probabilityOfFiring=0.2, directed=False)
        
        omegas.append(nx.algorithms.smallworld.omega(brain.network))

    np.save('results/omega_small_world', np.array(omegas))
Example #5
0
def plot_transmissions_k():
    charge = np.linspace(-4, 5, 100)
    colors = ['black', 'darkgreen', 'blue', 'red']
    labels = ['$1e^{-4}$', '$1e^{-3}$', '$1e^{-2}$', '$1e^{-1}$']
    ks = [1e-4, 1e-3, 1e-2, 1e-1]
    #goodk = 8.6e-3
    #t = 50

    brain = SmallWorldBrain(numberOfNodes=100000,
                            numberOfIterations=100,
                            rewireProbability=0.1,
                            refractoryPeriod=1,
                            fractionToFire=1 / 100000,
                            neuronThreshold=1,
                            fireRate=0.1,
                            averageDegree=5,
                            directed=False)

    for idx, k in enumerate(ks):
        #probTransmit = 1-1/(np.exp((charge-2)/(k*t))+1)
        probTransmit = brain.transmissionProb(charge, k)
        if idx == 0:
            plt.plot(charge,
                     probTransmit,
                     '--',
                     label='k=' + labels[idx],
                     color=colors[idx])
        else:
            plt.plot(charge,
                     probTransmit,
                     label='k=' + labels[idx],
                     color=colors[idx])

    plt.xlabel('Q', size=16)
    plt.tick_params(labelsize=16)
    plt.ylabel('$P_{transmit}$', size=16)
    plt.legend(prop={'size': 16})
Example #6
0
def plot_multipler_vs_static_prob(multiplierRange, N):
    """
    Calculates the static fraction of inhibitory edges added for a given multiplier
    """
    averagei_e = []
    mean_i = []
    for m in multiplierRange:
        print(m)

        small = SmallWorldBrain(numberOfNodes=N,
                                averageDegree=5,
                                rewireProbability=0.1,
                                neuronThreshold=1,
                                refractoryPeriod=1,
                                numberOfIterations=1000,
                                fractionToFire=0.05,
                                inhibitoryEdgeMultiplier=m,
                                fireRate=0.01,
                                directed=False)

        # Calculate the mean frac of inhibitory per node (static)
        frac = []
        i_list = []
        for n in np.arange(N):
            i = np.argwhere(small.edgeMatrix[n] == -1).shape[0]
            i_list.append(i)
            e = np.argwhere(small.edgeMatrix[n] == 1).shape[0]
            frac.append(i / (e + i))

        averagei_e.append(np.mean(np.array(frac)))
        mean_i.append(np.mean(np.array(i_list)))

    _, ax = plt.subplots(1, 1)
    ax.plot(multiplierRange, averagei_e, '+', color='black', label='Frac')
    ax.set_xlabel('Multiplier')
    ax.set_ylabel('Actual mean inhibitory fraction per node')

    ax2 = ax.twinx()
    ax2.plot(multiplierRange, mean_i, '^', color='black', label='#')
    ax2.set_ylabel('Mean number of inhibitory edges added per node')
    h1, l1 = ax.get_legend_handles_labels()
    h2, l2 = ax2.get_legend_handles_labels()
    ax.legend(h1 + h2, l1 + l2, loc='upper left')
def run_network_size_comparison():
    Ns = np.logspace(1, 3, 10)

    pathLengthArray = [[]]*4

    for size in Ns:
        N = int(size)
        print('Running size %d' % N)

        print('Random Brain...')
        randomBrain = RandomBrain(numberOfNodes = N, inhibitoryEdgeProbability=0, numberOfIterations=1000,
        averageDegree=8, neuronThreshold=0, refractoryPeriod=2, fractionToFire=0.005, probabilityOfFiring=0.2, directed=False)

        print('Small World...')
        smallworld = SmallWorldBrain(numberOfNodes = N, inhibitoryEdgeProbability=0, numberOfIterations=1000, 
                rewireProbability=0, averageDegree=8, neuronThreshold=0, refractoryPeriod=2, fractionToFire=0.005, probabilityOfFiring=0.2, directed=False)

        print('BA...')
        baBrain = BarabasiAlbertBrain(numberOfNodes = N, inhibitoryEdgeProbability=0, numberOfIterations=1000, 
                rewireProbability=0, averageDegree=8, neuronThreshold=0, refractoryPeriod=2, fractionToFire=0.005, probabilityOfFiring=0.2, directed=False)
        
        print('Growing Brain...')
        prefattach = GrowPrefAttachmentBrain(numberOfNodes = N, mu=0.5, inhibitoryEdgeProbability=0, numberOfIterations=1000, 
                rewireProbability=0, m=8, vertexNumber = 8, neuronThreshold=0, refractoryPeriod=2, fractionToFire=0.005, probabilityOfFiring=0.2, directed=False)

        pathLengthArray[0] = np.append(nx.average_shortest_path_length(randomBrain.network), pathLengthArray[0])
        pathLengthArray[1] = np.append(nx.average_shortest_path_length(smallworld.network), pathLengthArray[1])
        pathLengthArray[2] = np.append(nx.average_shortest_path_length(baBrain.network), pathLengthArray[2])
        pathLengthArray[3] = np.append(nx.average_shortest_path_length(prefattach.network), pathLengthArray[3])

    #np.save('results/path_lengths', np.array(clusterArray))
    plt.figure()
    for data, name in zip(pathLengthArray, ['Erdos-Renyi', 'Small World', 'Barabasi-Albert', 'Clustering Model']):  
        plt.scatter(Ns, data, label=name)

    plt.legend()
    plt.ylabel('Average Shortest Path Length')
    plt.xlabel('$N$')
def plot_topology_EEGs(N, t, save=False, load=False, filepath=None):

    if load:
        res = np.load(filepath)

    elif not load:
        small = SmallWorldBrain(numberOfNodes=N, averageDegree=5, rewireProbability=0, neuronThreshold=1, refractoryPeriod=1, 
        numberOfIterations=t, fractionToFire=0.05, inhibitoryEdgeMultiplier=0, fireRate=0.01, directed=False)
        small.execute()
        lattice = small.get_number_of_excited_neurons()

        small = SmallWorldBrain(numberOfNodes=N, averageDegree=5, rewireProbability=0.1, neuronThreshold=1, refractoryPeriod=1, 
        numberOfIterations=t, fractionToFire=0.05, inhibitoryEdgeMultiplier=0, fireRate=0.01, directed=False)
        small.execute()
        smallworld = small.get_number_of_excited_neurons()

        small = SmallWorldBrain(numberOfNodes=N, averageDegree=5, rewireProbability=0.8, neuronThreshold=1, refractoryPeriod=1, 
        numberOfIterations=t, fractionToFire=0.05, inhibitoryEdgeMultiplier=0, fireRate=0.01, directed=False)
        small.execute()
        random = small.get_number_of_excited_neurons()
        
        if save:
            np.save(filepath, np.array([lattice, smallworld, random]))

        res = np.array([lattice, smallworld, random])

    lattice = []
    for _, ye in zip(np.arange(t), [list(i) for i in res[0]]):
                lattice.append(len(ye))
    small = []
    for _, ye in zip(np.arange(t), [list(i) for i in res[1]]):
                small.append(len(ye))

    rand = []
    for _, ye in zip(np.arange(t), [list(i) for i in res[2]]):
                rand.append(len(ye))

    plt.figure()
    plt.plot(np.arange(t), np.array(lattice)/10000, label='Lattice', color='black')
    plt.plot(np.arange(t), np.array(small)/10000, label='Small-World', color='blue')
    plt.plot(np.arange(t), np.array(rand)/10000, label='Random', color='green')
    plt.xlabel('Timestep', size=16)
    plt.tick_params(labelsize=16)
    plt.ylabel('$N_{excited}/N_{total}$', size=16)
    plt.legend(prop={'size': 16}, loc='best')
Example #9
0
def plot_coverage_variation(N, t, multiplierRegimes=[0, 35, 60]):

    small1 = SmallWorldBrain(numberOfNodes=N,
                             averageDegree=5,
                             rewireProbability=0.1,
                             neuronThreshold=1,
                             refractoryPeriod=1,
                             numberOfIterations=t,
                             fractionToFire=0.05,
                             inhibitoryEdgeMultiplier=multiplierRegimes[0],
                             fireRate=0.01,
                             directed=False)
    small1.execute(movie=False)
    small1Array = [
        len(
            np.unique(
                np.concatenate(small1.get_number_of_excited_neurons()[:i],
                               axis=0))) / 1000 for i in np.arange(1, t)
    ]

    small2 = SmallWorldBrain(numberOfNodes=N,
                             averageDegree=5,
                             rewireProbability=0.1,
                             neuronThreshold=1,
                             refractoryPeriod=1,
                             numberOfIterations=t,
                             fractionToFire=0.05,
                             inhibitoryEdgeMultiplier=multiplierRegimes[1],
                             fireRate=0.01,
                             directed=False)
    small2.execute(movie=False)
    small2Array = [
        len(
            np.unique(
                np.concatenate(small2.get_number_of_excited_neurons()[:i],
                               axis=0))) / 1000 for i in np.arange(1, t)
    ]

    small3 = SmallWorldBrain(numberOfNodes=N,
                             averageDegree=5,
                             rewireProbability=0.1,
                             neuronThreshold=1,
                             refractoryPeriod=1,
                             numberOfIterations=t,
                             fractionToFire=0.05,
                             inhibitoryEdgeMultiplier=multiplierRegimes[2],
                             fireRate=0.01,
                             directed=False)
    small3.execute(movie=False)
    small3Array = [
        len(
            np.unique(
                np.concatenate(small3.get_number_of_excited_neurons()[:i],
                               axis=0))) / 1000 for i in np.arange(1, t)
    ]

    plt.figure()
    plt.plot(np.arange(1, t),
             np.array(small1Array),
             label='Supercritical',
             color='blue')
    plt.plot(np.arange(1, t),
             np.array(small2Array),
             label='Critical',
             color='red')
    plt.plot(np.arange(1, t),
             np.array(small3Array),
             label='Subcritical',
             color='black')

    #plt.title('Nodes: %d, <k>:%d, Refractory: %d, Threshold: %d' % (small1.numberOfNodes, small1.averageDegree, small1.refractoryPeriod, small1.neuronThreshold))
    plt.xlabel('Timestep', size=16)
    plt.tick_params(labelsize=16)
    plt.ylabel('Coverage', size=16)
    plt.xlim([0, t])
    plt.legend()
Example #10
0
def plot_critical_regimes(N, t, multiplerRegimes=[0, 35, 60]):

    small1 = SmallWorldBrain(numberOfNodes=N,
                             averageDegree=5,
                             rewireProbability=0.1,
                             neuronThreshold=1,
                             refractoryPeriod=1,
                             numberOfIterations=t,
                             fractionToFire=0.05,
                             inhibitoryEdgeMultiplier=multiplerRegimes[0],
                             fireRate=0.01,
                             directed=False)
    small1.execute(movie=False)

    small1Array = []
    for _, ye in zip(np.arange(small1.numberOfIterations),
                     [list(i) for i in small1.numberOfExcitedNeurons]):
        small1Array.append(len(ye))
    ex, inhib, q1 = small1.get_effective_charge()
    #np.save('results/meanQ/subcritical', [ex, inhib, q1])
    print('m=%d, <Q>=%.3f:' %
          (multiplerRegimes[0], np.mean(np.array(ex) - np.array(inhib))))

    small2 = SmallWorldBrain(numberOfNodes=N,
                             averageDegree=5,
                             rewireProbability=0.1,
                             neuronThreshold=1,
                             refractoryPeriod=1,
                             numberOfIterations=t,
                             fractionToFire=0.05,
                             inhibitoryEdgeMultiplier=multiplerRegimes[1],
                             fireRate=0.01,
                             directed=False)
    small2.execute(movie=False)
    small2Array = []
    for _, ye in zip(np.arange(small2.numberOfIterations),
                     [list(i) for i in small2.numberOfExcitedNeurons]):
        small2Array.append(len(ye))
    ex2, inhib2, q2 = small2.get_effective_charge()
    #np.save('results/meanQ/critical', [ex2, inhib2, q2])
    print('m=%d, <Q>=%.3f:' %
          (multiplerRegimes[1], np.mean(np.array(ex2) - np.array(inhib2))))

    small3 = SmallWorldBrain(numberOfNodes=N,
                             averageDegree=5,
                             rewireProbability=0.1,
                             neuronThreshold=1,
                             refractoryPeriod=1,
                             numberOfIterations=t,
                             fractionToFire=0.05,
                             inhibitoryEdgeMultiplier=multiplerRegimes[2],
                             fireRate=0.01,
                             directed=False)
    small3.execute(movie=False)
    small3Array = []
    for _, ye in zip(np.arange(small3.numberOfIterations),
                     [list(i) for i in small3.numberOfExcitedNeurons]):
        small3Array.append(len(ye))
    ex3, inhib3, q3 = small3.get_effective_charge()
    #np.save('results/meanQ/supercritical', [ex3, inhib3, q3])
    print('m=%d, <Q>=%.3f:' %
          (multiplerRegimes[2], np.mean(np.array(ex3) - np.array(inhib3))))

    plt.figure()
    plt.plot(np.arange(t),
             np.array(small1Array) / small1.numberOfNodes,
             label='Supercritical',
             color='blue')
    plt.plot(np.arange(t),
             np.array(small2Array) / small1.numberOfNodes,
             label='Critical',
             color='red')
    plt.plot(np.arange(t),
             np.array(small3Array) / small1.numberOfNodes,
             label='Subcritical',
             color='black')

    #plt.title('Nodes: %d, <k>:%d, Refractory: %d, Threshold: %d' % (small1.numberOfNodes, small1.averageDegree, small1.refractoryPeriod, small1.neuronThreshold))
    plt.xlabel('Timestep', size=16)
    plt.tick_params(labelsize=16)
    plt.ylabel('$N_{excited}/N_{total}$', size=16)
    plt.legend(prop={'size': 16})