def main():
    n_networks = 100

    ps = np.linspace(0, 1, 25, endpoint=False)
    rs = np.linspace(0, 1, 25, endpoint=False)

    results_p = []
    results_r = []
    results_s = []
    results_l = []
    for r in rs:
        for p in ps:
            print(r, p)
            samples_l = []
            samples_s = []
            for i in range(n_networks):
                #print('-- NEW EPI --')
                g = bi_planted_partition(1000, 8, 0)
                epi = SIS(g, p=p, r=r)
                #epi = SI(g, p=p)

                epi.infect_random_node()
                epi.simulate()

                samples_l.append(epi.length)
                samples_s.append(epi.size)

            results_r.append(r)
            results_p.append(p)
            results_s.append(np.average(samples_s))
            results_l.append(np.average(samples_l))

    fig = plt.figure()
    ax = fig.gca(projection='3d')
    X, Y = results_r, results_p
    Z = results_l
    ax.scatter(X, Y, Z)

    ax.set_xlabel('Recovery Probability')
    ax.set_ylabel('Transmission Probability')
    ax.set_zlabel('Epidemic Length')

    plt.show()
    # TODO: Figure out the right way to save these plots
    plt.clf()

    fig = plt.figure()
    ax = fig.gca(projection='3d')
    X, Y = results_r, results_p
    Z = results_s
    ax.scatter(X, Y, Z)

    ax.set_xlabel('Recovery Probability')
    ax.set_ylabel('Transmission Probability')
    ax.set_zlabel('Epidemic Size')

    plt.show()
    # TODO: Figure out the right way to save these plots
    plt.clf()
Esempio n. 2
0
def main():
    # example
    n_networks = 500
    x = np.linspace(0, 1, 50, endpoint=False)
    results_b_length = []
    results_b_size = []
    for p in x:
        print(p)
        samples_length = []
        samples_size = []
        for i in range(n_networks):
            #print('-- NEW EPI --')
            g = bi_planted_partition(1000, 8, 0)
            epi = SIS(g, p=p, r=0.04)
            #epi = SI(g, p=p)
            epi.infect_random_node()
            epi.simulate()
            samples_length.append(epi.length)
            samples_size.append(epi.size)
        results_b_length.append((p, np.average(samples_length)))
        results_b_size.append((p, np.average(samples_size)))

    fig = plt.figure()
    ax = plt.gca()
    ax.scatter(*zip(*results_b_length))
    plt.xlabel('Transmission probability')
    plt.ylabel('Epidemic length')
    plt.axhline(y=np.log(1000), linewidth=1, color='red')
    plt.show()
    #plt.savefig('length.png')
    plt.clf()

    fig = plt.figure()
    ax = plt.gca()
    ax.scatter(*zip(*results_b_size))
    plt.xlabel('Transmission probability')
    plt.ylabel('Epidemic size')
    plt.show()