예제 #1
0
                t_run_total,
                infection_rate,
                recovery_rate,
                number_of_initially_infected=N,
                verbose=False,
                seed=seed,
                sampling_dt=1,
            )

            _tc.gillespie_SIS_on_EdgeActivityModel(AM, SIS, verbose=False)

            t = np.array(SIS.time)
            I = np.array(SIS.I)

            this_pl, = pl.plot(t, I, '-s', ms=2, alpha=0.5, mfc='None')
            mean_I_1 = tc.time_average(t, I, tmax=t_run_total)

            AM = _tc.EdgeActivityModel(
                N,
                k / (N - 1.),
                omega,
                verbose=False,
            )

            SIS = _tc.MARKOV_SIS(
                N,
                t_run_total,
                infection_rate,
                recovery_rate,
                minimum_I=0.01,
                number_of_initially_infected=N,
예제 #2
0
def simulate_and_measure_i_inf(temporal_network_or_model,epidemic_object,t_equilibrate,is_static=False,verbose=False):
    """Get the equilibrium ratio of infected. 

    Parameters
    ----------
    temporal_network_or_model : :class:`_tacoma.edge_changes`, :class:`_tacoma.edge_lists`, :class:`_tacoma.edge_changes_with_histograms`, :class:`_tacoma.edge_lists_with_histograms`, or :class:`_tacoma.EdgeActivityModel`.
        An instance of a temporal network or network model.
    epidemic_object : :class:`_tacoma.SI`, :class:`_tacoma.SIS`, :class:`_tacoma.SIR`, :class:`_tacoma.SIRS`, :class:`_tacoma.node_based_SIS`
        An initialized epidemic object.
    t_equilibrate: float
        Time passed after t0 after which to start measuring.
    is_static : bool, default : False
        The algorithm works a bit differently if it knows that the network is actually static.
        It works only with instances of :class:`_tacoma.edge_lists`.
    verbose: bool, optional
        Be chatty.


    Returns
    -------
    i_inf: float
        Temporal average over the ratio of infected after equilibration.
    i_inf_std: float
        RMSE of the ratio of infected.
    R0: float
        As measured after equilibration
    """

    tn = temporal_network_or_model
    eo = epidemic_object

    N = tn.N
    t_eq = t_equilibrate
    t_run = eo.t_simulation

    t_run_total = t_eq + t_run

    tc.gillespie_epidemics(tn,eo,is_static=is_static,verbose=verbose)

    t = np.array(eo.time)
    I = np.array(eo.I,dtype=float) / N
    r0 = np.array(eo.R0)
    t0 = t[0]

    if t[-1]>t0+t_eq:
        ndcs = np.where(t>=t_eq+t0)[0]
        ti, i = t[ndcs], I[ndcs]
        i_inf = tc.time_average(ti,i,tmax=t0+t_run_total)
        i_inf_std = np.sqrt(tc.time_average(ti,(i-i_inf)**2,tmax=t0+t_run_total))

        r0 = r0[t>=t_eq+t0]
        this_t = t[t>=t_eq+t0]
        R0 = tc.time_average(this_t,r0,tmax=t0+t_run_total)
    else:
        i_inf = 0
        i_inf_std = 0.
        R0 = r0[-1]

    result = ( i_inf, i_inf_std, R0 )

    return result
예제 #3
0
t_sample = np.arange(int(t_simulation / dt) + 1, dtype=float) * dt

N_meas = 30

fig, ax = pl.subplots(1, 3, figsize=(12, 4))

for tn in [socio, fwP, fwP_binned]:
    start = time.time()
    t, k = np.array(tc.mean_degree(tn))
    end = time.time()

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

    line, = ax[0].step(t, k, where='post', lw=1)

    mean_k = tc.time_average(t, k)
    print(mean_k)
    eta = R0 * rho / mean_k

    i_sample = np.zeros_like(t_sample)

    successful = 0

    for meas in range(N_meas):

        sis = tc.SIS(N,
                     t_simulation,
                     eta,
                     rho,
                     number_of_initially_infected=10)
예제 #4
0
import tacoma as tc
import epipack as epk

# load DTU data as edge_changes
dtu = tc.load_json_taco('~/.tacoma/dtu_1_weeks.taco')

# convert to edge_lists
dtu = tc.convert(dtu)

k = tc.time_average(*tc.mean_degree(dtu), tmax=dtu.tmax)

R0 = 3
recovery_rate = 1 / (24 * 3600)
infection_rate = R0 / k * recovery_rate

tmax = 7 * 24 * 3600
SIS = tc.SIS(dtu.N, dtu.tmax, infection_rate, recovery_rate)