Exemple #1
0
def sin_test(n=8,text_position='start'):
    """Test the stuff from the modules"""

    from bfmplot import pl
    import bfmplot as bp
    import numpy as np
    #bp.set_color_cycle(bp.cccs_colors)

    #pl.figure(figsize=bp.phys_rev_column())
    pl.figure(figsize=bp.golden_ratio(5))

    x = np.linspace(1,5*np.pi,100)

    for i in range(n):
        pl.plot(x, 1-np.sin(x[::-1]/np.sqrt(i+1)), marker=bp.markers[i],mfc='w',label='$i=%d$'%i)

    bp.strip_axis(pl.gca())

    leg = pl.legend()
    bp.align_legend_right(leg)

    bp.arrow(pl.gca(), r'$i$', 
             (3, 1.8), 
             (6, 0.8), 
             text_position=text_position)


    pl.xlabel('hello')
    pl.ylabel('hello')

    bp.set_n_ticks(pl.gca(), 3, 2)

    #pl.xscale('log')

    pl.gcf().tight_layout()
Exemple #2
0
def sin_test(n=8,text_position='start'):

    pl.figure(figsize=bp.golden_ratio(5))

    x = np.linspace(0,5*np.pi,100)

    for i in range(n):
        pl.plot(x, 1-np.sin(x[::-1]/np.sqrt(i+1)), marker=bp.markers[i],mfc='w',label='$i=%d$'%i)

    bp.strip_axis(pl.gca())

    leg = pl.legend()
    bp.align_legend_right(leg)

    bp.arrow(pl.gca(), r'$i$', (14, 0.8), (10, 0.15), text_position=text_position, rad=0.3)    

    pl.xlabel('this is the x-label')
    pl.ylabel('this is the y-label')

    pl.gcf().tight_layout()
Exemple #3
0
def sin_test(n=8, text_position='start', with_legend=True):

    pl.figure(figsize=bp.golden_ratio(5))

    x = np.linspace(0, 5 * np.pi, 100)

    for i in range(n):
        pl.plot(x,
                1 - np.sin(x[::-1] / np.sqrt(i + 1)),
                marker=bp.markers[i],
                mfc='w',
                label='$i=%d$' % i)

    bp.strip_axis(pl.gca())

    if with_legend:
        leg = pl.legend()
        bp.align_legend_right(leg)

    pl.xlabel('this is the x-label')
    pl.ylabel('this is the y-label')

    pl.gca().set_title(name)
    pl.gcf().tight_layout()
Exemple #4
0
    start = time()
    t, result = model.simulate(300, sampling_dt=1)
    end = time()

    print("simulation took", end - start, "seconds")

    from bfmplot import pl

    for comp, series in result.items():
        pl.plot(t, series, label=comp)

    kw = {
        'R0': R0,
        'Q0': Q0,
        'k0': k0,
        'I0': I0 / N,
        'waning_quarantine_rate': waning_quarantine_rate,
        'recovery_rate': recovery_rate,
        'infection_rate': infection_rate,
        'app_participation_ratio': 1.0,
        't': t,
    }

    t, result = mean_field_SIRX_tracing(kw)

    for comp, series in result.items():
        pl.plot(t, series * N, label=comp)

    pl.legend()
    pl.show()
Exemple #5
0
model.set_initial_conditions({S: 1 - I0, I: I0})

import numpy as np
from bfmplot import pl as plt
import bfmplot as bp

t = np.linspace(0, 100, 1000)
result = model.integrate(t)

plt.figure()
for compartment, incidence in result.items():
    plt.plot(t, incidence, label=compartment)

plt.xlabel('time [days]')
plt.ylabel('incidence')
plt.legend()

bp.strip_axis(plt.gca())

plt.gcf().tight_layout()
plt.savefig('SEIRQ.png', dpi=300)

N = 1000
I0 = 100
model = epk.EpiModel([S, E, I, R, Q], initial_population_size=N)
model.set_processes([
    (S, I, infection_rate, E, I),
    (E, symptomatic_rate, I),
    (I, recovery_rate, R),
    (I, quarantine_rate, Q),
])
Exemple #6
0
import bfmplot as bp

data = np.array([
    (0.0, 2.00),
    (0.75, 2.68),
    (1.5, 3.00),
    (2.25, 2.78),
    (3.0, 2.14),
    (3.75, 1.43),
    (4.5, 1.02),
    (5.25, 1.14),
    (6.0, 1.72),
])

times, rates = data[:, 0], data[:, 1]

x2 = np.linspace(times[0], times[-1], 1000)
interp_modes = ['zero', 'linear', 'nearest', 'quadratic']
pl.figure()
pl.plot(times, rates, 's', label='data')
for kind in interp_modes:
    f = interp1d(times, rates, kind=kind)
    pl.plot(x2, f(x2), label=kind)
pl.legend(frameon=False)
bp.strip_axis(pl.gca())
pl.xlabel('time')
pl.ylabel('value')
pl.gcf().tight_layout()
pl.gcf().savefig('interp1d.png', dpi=300)
pl.show()
for i in range(200):
    for j in range(5):
        t = solve_t(k[j], n)
        variances[i, j] = variance(t, rho[i], n, NMAX)

fig = plt.figure(2, figsize=(6, 6))
ax = fig.add_subplot(1, 1, 1)
plt.xlabel(r'$\rho$', size=16)
plt.ylabel(r'Var[k]', size=14)

for i in range(5):
    plt.plot(rho, variances[:, i], label=r'$k=$' + str(k[i]))

ax.set_yscale('log')
#ax.set_xscale('log')
plt.legend(loc=4)
plt.savefig('figures/variance.pdf')

### triangle plots

n = 10**5
NMAX = 20  # increase this if needed

k = 10**np.linspace(0, 4.99, 20)
rho = np.linspace(0, 0.5, 6)
triangle_density = np.zeros((20, 6))

for i in range(20):
    for j in range(6):
        t = solve_t(k[i], n)
        triangle_density[i, j] = triangles(t, rho[j], NMAX)
        density=True,
        alpha=1,
        align='left',
        color=bp.brewer_qualitative[1],
        label='data',
        histtype='step')
p = pk(n, t, rho, kmax, X, W)
pl.plot(np.arange(kmax),
        p,
        lw=1,
        c=bp.brewer_qualitative[2],
        label='model fit')
pl.xlim(0, 30)
ax.text(0.04, 0.95, '(a)', va='top', ha='left', transform=ax.transAxes)
bp.strip_axis(ax)
leg = pl.legend()
bp.align_legend_right(leg)

ax.set_ylabel('probability density $p_k$')
ax.set_xlabel('node degree $k$')

#pl.show()
#sys.exit(0)
### collab network
print("loading", 'degree_sequences/cond-mat.degree_sequence', '...')
k = np.loadtxt('degree_sequences/cond-mat.degree_sequence')
k = np.array(k, dtype=int)
kmax = np.max(k) + 1
n = len(k)
print("fitting...")
t = solve_t(np.mean(k), n)