infection_rate, recovery_rate, N // 2, seed=seed) tc.gillespie_node_based_SIS(fwP_el, SIS) end = time.time() print("node-based simulation on edge_lists took", end - start, "seconds") pl.plot(SIS.time, SIS.I) start = time.time() SIS = tc.SIS(N, t_run_total * 2, infection_rate, recovery_rate, N // 2, seed=seed, verbose=True) tc.gillespie_SIS(fwP_ec, SIS, verbose=True) end = time.time() print("edge-based simulation on edge_changes took", end - start, "seconds") pl.plot(SIS.time, SIS.I) start = time.time() SIS = tc.SIS(N, t_run_total * 2, infection_rate, recovery_rate,
if __name__ == "__main__": N = 100 k = 10 omega = 1.6 recovery_rate = 0.1 R0 = 10 t_run_total = 1000 AM = tc.EdgeActivityModel(N, k/(N-1.), omega, t0 = 2000 ) infection_rate = R0 / k * recovery_rate SIS = tc.SIS(N,t_run_total,infection_rate,recovery_rate, number_of_initially_infected=N, sampling_dt=0.0, ) print(simulate_and_measure_i_inf(AM, SIS,t_equilibrate=900))
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) tc.gillespie_SIS(tn, sis) t = np.array(sis.time) i = np.array(sis.I, dtype=float) / N this_sample = tc.sample_a_function(t, i, t_sample) if this_sample[-1] > 0.0: successful += 1 i_sample += this_sample ax[2].plot(t_sample, this_sample, c=line.get_color(), alpha=0.1)
tmax = 10 seed = 7925 infection_rate = 1.0 recovery_rate = 0.001 E = flockwork_P_equilibrium_configuration(N, P[0]) fwP_ec = tc.flockwork_P_varying_rates(E, N, P, t_run_total, rewiring_rate, tmax, seed=seed) SIS = tc.SIS(N, t_run_total * 2, infection_rate, recovery_rate, seed=seed) SIS.set_node_status([1] + [0 for i in range(1, N)]) tc.gillespie_SIS(fwP_ec, SIS) t0, I0 = list(SIS.time), list(SIS.I) node_status = SIS.get_node_status() pl.plot(t0, I0) start = time.time() SIS = tc.SIS(N, t_run_total * 2, infection_rate, recovery_rate, seed=seed) SIS.set_node_status(node_status) tc.gillespie_SIS(fwP_ec, SIS) t1, I1 = list(SIS.time), list(SIS.I) t1 = [_ + t0[-1] for _ in t1]
L.N = 3 L.t = [0.0,1.0,2.0] L.tmax = 3.0 L.edges = [ [ (0,1) ], [ (1,2), (0,2) ], [ (0,1) ], ] L_sis = tc.SIS(L.N, 100, 1.0, 0.1,3,0,12234235,True) tc.gillespie_SIS_on_edge_lists(L,L_sis,verbose=True) pl.plot(L_sis.time,L_sis.I) pl.plot(L_sis.time,L_sis.SI) pl.plot(L_sis.time,L_sis.R0) print("===== edge_changes => edge_lists =====") C = tc.edge_changes() C.N = 3 C.edges_initial = [ (0,1) ] C.t0 = 0.0 C.tmax = 3.0
etas = R0 * rho / (N - 1.) #R0 = etas * (N-1.)/rho tc_vals = np.zeros((len(etas), N_meas)) dyn_vals = np.zeros((len(etas), N_meas)) seed = 12 import time for ieta, eta in enumerate(etas): for meas in range(N_meas): start = time.time() L_sis = tc.SIS(L.N, 100, eta, rho, number_of_initially_infected=25, seed=seed) tc.gillespie_SIS_on_edge_lists(L, L_sis) end = time.time() #print "tacoma needed", end-start, "seconds" t = np.array(L_sis.time) dt = t[1:] - t[:-1] I_mean = np.array(dt).dot(L_sis.I[:-1]) / sum(dt) if L_sis.I[-1] == 0: I_mean = 0 start = time.time() result = gill.SIS_Poisson_homogeneous(L.N,
print("initial edge list", E) FW = tc.FlockworkPModel( E, # initial edge list (list of tuple of ints) N, # number of nodes gamma, # rate with which anything happens P, # probability to reconnect save_temporal_network=True, save_aggregated_network=True, verbose=True, ) SIS = tc.SIS( N, #number of nodes tmax, # maximum time of the simulation infection_rate, recovery_rate, number_of_initially_infected=I0, # optional, default: 1 verbose=True, ) tc.gillespie_epidemics(FW, SIS, verbose=True) tsim = SIS.time[-1] ec = FW.edge_changes ec.tmax = tsim print("ec.N) ,", ec.N) print("ec.t0) ,", ec.t0) print("ec.t) ,", ec.t) print("ec.tmax) ,", ec.tmax) print("ec.edges_in) ,", ec.edges_in)
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)