t_run_total = 500.0 tmax = 1000.0 seed = 7925 infection_rate = 1.0 recovery_rate = 0.1 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) fwP_el = tc.convert(fwP_ec) start = time.time() SIS = tc.node_based_SIS(N, t_run_total * 2, infection_rate, recovery_rate, N // 2, seed=seed, verbose=True) tc.gillespie_node_based_SIS(fwP_ec, SIS, verbose=True) end = time.time() print("node-based simulation on edge_changes took", end - start, "seconds") pl.plot(SIS.time, SIS.I)
import tacoma as tc ec = tc.convert(tc.dynamic_RGG(3, 3, mean_link_duration=1.)) C = tc.edge_changes() C.N = 3 C.edges_initial = [(0, 1)] C.t0 = 0.0 C.tmax = 3.0 C.t = [1.0, 2.0] C.edges_in = [ [(1, 2), (0, 2)], [ (0, 1), ], ] C.edges_out = [ [(0, 1)], [(1, 2), (0, 2)], ] fw_args = tc.get_flockwork_P_args(C, dt=1.) print fw_args.rewiring_rate print fw_args.P print fw_args.__dict__
[(2, 5), (1, 7)], [(2, 5)], [(0, 1), (2, 5)], [(0, 1)]] temporal_network.time_unit = 's' temporal_network.notes = 'This experiment was conducted as a test.' temporal_network.int_to_node = { 0: 'Alice', 1: 'Bob', 2: 'Clara', 4: 'Darren', 5: 'Elle', 5: 'Felicitas', 6: 'George', 7: 'Harriett', } C = tc.convert(temporal_network) traj = tc.convert_to_edge_trajectories(C) C2 = tc.convert_edge_trajectories(traj) import pprint pp = pprint.PrettyPrinter(indent=4) C.int_to_node[0] = 'sdasd' pp.pprint(C.N) pp.pprint(C.t0) pp.pprint(C.t) pp.pprint(C.tmax) pp.pprint(C.edges_initial) pp.pprint(C.edges_in)
import matplotlib.pyplot as pl import tacoma as tc from tacoma.drawing import draw_edges from tacoma.drawing import get_edge_order import numpy as np #tn = tc.load_sociopatterns_hypertext_2009() tn = tc.load_json_taco('~/.tacoma/dtu_1_weeks.taco') tn = tc.convert(tn) edge_traj = tc.get_edge_trajectories(tn, return_edge_similarities=True) print(edge_traj.edge_similarities[:10]) edge_order = get_edge_order(edge_traj, threshold=3600.) print(edge_order) print(np.all(edge_order == np.sort(edge_order))) draw_edges(edge_traj.trajectories, edge_order=edge_order) draw_edges(edge_traj.trajectories) pl.show()
import tacoma as tc orig = tc.convert(tc.load_json_taco('~/.tacoma/ht09.taco')) #orig = tc.convert( tc.load_json_taco('~/.tacoma/hs13.taco') ) #orig = tc.load_json_taco('~/.tacoma/dtu_1_weeks.taco') dt_for_inference = 120. dt_binning = 20. fetch_k_scaling = True if fetch_k_scaling: k_scaling = tc.estimate_k_scaling_gradient_descent( orig, dt_for_inference=dt_for_inference, dt_for_binning=dt_binning, measurements_per_configuration=20, learning_rate=0.5, relative_error=1e-2, ) else: k_scaling = 5 from tacoma.model_conversions import estimate_flockwork_P_args import matplotlib.pyplot as pl import numpy as np t_orig, k_orig = tc.mean_degree(tc.bin(orig, dt_binning)) fig, ax = pl.subplots(1, 2, sharex=True, sharey=True) ax[0].plot(t_orig, k_orig, label='original') ax[1].plot(t_orig, k_orig, label='original')
L = tc.edge_lists() L.N = 5 L.t = [0., 1., 2., 3. ] L.tmax = 4. L.edges = [ [], [ (0, 1), (2,3), (3, 4), (2, 4), ], [ (2,3), (3, 4), (2, 4), ], [], ] C = tc.convert(L) L_result = tc.measure_group_sizes_and_durations(L) C_result = tc.measure_group_sizes_and_durations(C) for res in [L_result, C_result]: contact_durations = res.contact_durations pair_durations = res.group_durations[2] print("contact durations =", contact_durations) print("(should be [ 1.0, 2.0, 2.0, 2.0])") print("pair durations =", pair_durations) print("(should be [ 1.0 ])") print()
import tacoma as tc print "===== edge_lists => edge_lists =====" L = tc.edge_lists() 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)], ] new = tc.convert(L) print "N =", new.N print "t0 =", new.t0 print "t =", new.t print "tmax =", new.tmax print "edges_in =", new.edges_in print "edges_out =", new.edges_out print "edges_initial =", new.edges_initial new = tc.convert(new) print print "N =", new.N print "t =", new.t print "tmax =", new.tmax
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)