def setUp(self): N = 10 self.beta = 0.99 self.gamma = 0.0001 dd = degree_distributions.power_law_degree_distrb() graph, pos = generate_graph(N, dd) graph = nx.generators.complete_graph(N) N = len(graph.nodes()) self.Lambda = np.full((N, N), self.beta) self.Gamma = np.full(N, self.gamma) self.graph = graph
def power_law_exp(file_root='plaw_T8_10k_q_1_gamma1_g_over_b',num_sims=50, num_nodes=10000, active_gen_sizes_on=False): ## Make power law network pl_degree_dist = degree_distributions.power_law_degree_distrb(400) power_law_q2 = degree_distributions.power_law_degree_distrb(400, mu=10) ## set up paramters beta = 0.004 gamma = 0.001 T = 0.8 ## quantities to track: ## dist of cmulative infections by gen, dist of cum infections by time (g/beta*q?), total and active gens, diff of waiting times # file_root = 'poiss_T8_1k_q_1_gamma1_g_over_b' print('Running power law experiment') ensemble.run_ensemble_with_time_distribution(power_law_q2, f'../data/testing/{file_root}', num_sims=num_sims, num_nodes=num_nodes, init_T=T, recover_rate=gamma, active_gen_sizes_on=active_gen_sizes_on, kill_by=16) print('Done')
def random_vax_exp(file_root, num_sims=50, num_nodes=10000): ## Make erdos renyi network k_mean_degree = 3.04 # k_mean_degree = 5 power_law_q2 = degree_distributions.power_law_degree_distrb(400, mu=10) ## set up paramters beta = 0.004 gamma = 0.001 T = 0.8 ## quantities to track: ## dist of cmulative infections by gen, dist of cum infections by time (g/beta*q?), total and active gens, diff of waiting times # file_root = 'poiss_T8_1k_q_1_gamma1_g_over_b' print('Running power law intervention experiment') s_time = time.time() ensemble.run_ensemble_intervention_effects(power_law_q2, f'../data/testing/{file_root}', num_sims=num_sims, num_nodes=num_nodes, init_T=T, gen_intervene=4, T_intervene=0.0, recover_rate=gamma, prop_reduced=0.5, intervention_type="random", run_regular=False) print('Done') print(f'time all was {time.time() - s_time}')
import matplotlib.pyplot as plt from analysis import ensemble from src import degree_distributions from src import figs_for_paper from src import pgf_formalism from src import plotting_util # ## CREATE A DEGREE DISTRIBUTION power_law_dd = degree_distributions.power_law_degree_distrb(400) power_law_q3 = degree_distributions.power_law_degree_distrb( 2000, mu=10) # q is 3, k is 1.7 poisson = degree_distributions.binomial_degree_distb(2000, 2.5) # ## COMPUTE AND SAVE THE PHASE SPACE MATRICES FOR SPECIFIED GENERATIONS pgf_formalism.compute_phase_space( num_gens=17, num_nodes=2000, degree_distribution=poisson, transmissibility=0.8, save_results=True, gens_to_save=[2, 3, 4, 5, 6, 7, 8, 10, 12, 15, 16], file_fmt_to_save='../data/paper/ER_q2.5_T8_ifft_g{0}', do_non_interv=True, do_interv=False) # ## PLOT SIMULATION RESULTS AGAINST THEORETICAL RESULTS, BOTH READ FROM FILES: (LOOK INSIDE FUNCTION FOR FILE FORMAT # AND LOCATION SPECIFICATION) plotting_util.plot_sims_vs_analytical_multigens( [3, 6, 10, 12], 400,
def plots_for_nerccs_talk(list_of_gens, x_lim, fname_sim_results, fname_predict_format, fname_sim_results_int=None, fname_predict_format_int=None, same_plot=False, normalize_axis_x=False, plot_distribution_inset=False, grayscale=False, inset_label=None): ## Plain axes: fig, ax1 = plt.subplots(figsize=(15, 7)) ax1.set_xlim(0, x_lim) plt.xticks(fontsize=20) plt.yticks(fontsize=20) x_vals = np.arange(1, x_lim) x_ticks = np.arange(2, x_lim, int((x_lim - 2) / 10)) ax1.set_xlim(0, max(x_vals)) ax1.set_xticks(x_ticks) ax1.semilogy() # ax1.set_ylim(.00005, .1) ax1.set_xlabel('Cumulative Infections', fontsize=20) ax1.set_ylabel('Probability', fontsize=20) plt.tight_layout() plt.show() ## Axes with theory and inset fig, ax1 = plt.subplots(figsize=(15, 7)) ax1.set_xlim(0, x_lim) plt.xticks(fontsize=20) plt.yticks(fontsize=20) x_vals = np.arange(1, x_lim) x_ticks = np.arange(2, x_lim, int((x_lim - 2) / 10)) ax1.set_xlim(0, max(x_vals)) ax1.set_xticks(x_ticks) ax1.semilogy() ax1.set_ylim(.00005, .1) ax1.set_xlabel('Cumulative Infections', fontsize=20) ax1.set_ylabel('Probability', fontsize=20) if plot_distribution_inset: right, bottom, width, height = [0.4, 0.5, 0.25, 0.3] ax2 = fig.add_axes([right, bottom, width, height]) power_law_dd = degree_distributions.power_law_degree_distrb(400) ax2.plot(power_law_dd[:15], color='black') ax2.set_xlim(0, 14) ax2.set_title('Network Degree Distribution', fontsize=20) ax2.set_xlabel('Degree $k$', fontsize=20) ax2.set_ylabel('Fraction of nodes', fontsize=20) # ax2.set_yticks(np.arange(0, 1, 0.25)) ax2.set_xticks([0, 1, 2, 3, 5, 10]) ax2.semilogy() plt.tight_layout() plt.show() ## Axes with just theory fig, ax1 = plt.subplots(figsize=(15, 7)) ax1.set_xlim(0, x_lim) plt.xticks(fontsize=20) plt.yticks(fontsize=20) x_vals = np.arange(1, x_lim) x_ticks = np.arange(2, x_lim, int((x_lim - 2) / 10)) ax1.set_xlim(0, max(x_vals)) ax1.set_xticks(x_ticks) ax1.semilogy() ax1.set_ylim(.00005, .1) ax1.set_xlabel('Cumulative Infections', fontsize=20) ax1.set_ylabel('Probability', fontsize=20) color_key = {} colors = ['blue', 'teal', 'orange', 'crimson', 'purple', 'teal', 'black', 'gold', 'chocolate', 'dodgerblue', 'darkslategray', 'mediumorchid', 'magenta', 'tomato', 'midnightblue', 'cadetblue', 'crimson'] colorcycle = sns.color_palette("mako_r", len(list_of_gens)) ## Color test: Uncomment to test plot # colorcycle = sns.color_palette("mako_r", 4) # plt.plot(np.arange(100), np.sin(np.arange(100)) + 0, color=colorcycle[0]) # plt.plot(np.arange(100), np.sin(np.arange(100)) + 1, color=colorcycle[1]) # plt.plot(np.arange(100), np.sin(np.arange(100)) + 2, color=colorcycle[2]) # plt.plot(np.arange(100), np.sin(np.arange(100)) + 3, color=colorcycle[3]) # plt.tight_layout() # plt.show() style_key = {} styles = [':', '-.', '--', '-'] for i in range(len(list_of_gens)): gen = list_of_gens[i] # color = colors[0] # colors.remove(color) color_key[gen] = colorcycle[i] style = styles[0] styles.remove(style) style_key[gen] = style for gen in list_of_gens: fname_predict = fname_predict_format.format(gen) fname_sims = fname_sim_results if fname_sim_results_int is not None and fname_predict_format_int is not None: fname_predict_interv = fname_predict_format_int.format(gen) fname_sims_interv = fname_sim_results_int else: fname_sims_interv = None fname_predict_interv = None nerccs_plot_sims_vs_analytical_outbreak_sizes(fig, ax1, gen, x_lim, None, fname_predict, None, None, color_key, style_key, same_plot, normalize_axis_x, grayscale) if plot_distribution_inset: right, bottom, width, height = [0.4, 0.5, 0.25, 0.3] ax2 = fig.add_axes([right, bottom, width, height]) power_law_dd = degree_distributions.power_law_degree_distrb(400) ax2.plot(power_law_dd[:15], color='black') ax2.set_xlim(0, 14) ax2.set_title('Network Degree Distribution', fontsize=20) ax2.set_xlabel('Degree $k$', fontsize=20) ax2.set_ylabel('Fraction of nodes', fontsize=20) # ax2.set_yticks(np.arange(0, 1, 0.25)) ax2.set_xticks([0, 1, 2, 3, 5, 10]) ax2.semilogy() plt.tight_layout() plt.show() ## Axes with theory and sims fig, ax1 = plt.subplots(figsize=(15, 7)) ax1.set_xlim(0, x_lim) plt.xticks(fontsize=20) plt.yticks(fontsize=20) x_vals = np.arange(1, x_lim) x_ticks = np.arange(2, x_lim, int((x_lim - 2) / 10)) ax1.set_xlim(0, max(x_vals)) ax1.set_xticks(x_ticks) ax1.semilogy() ax1.set_ylim(.00005, .1) ax1.set_xlabel('Cumulative Infections', fontsize=20) ax1.set_ylabel('Probability', fontsize=20) for gen in list_of_gens: fname_predict = fname_predict_format.format(gen) fname_sims = fname_sim_results if fname_sim_results_int is not None and fname_predict_format_int is not None: fname_predict_interv = fname_predict_format_int.format(gen) fname_sims_interv = fname_sim_results_int else: fname_sims_interv = None fname_predict_interv = None nerccs_plot_sims_vs_analytical_outbreak_sizes(fig, ax1, gen, x_lim, fname_sims, fname_predict, None, None, color_key, style_key, same_plot, normalize_axis_x, grayscale) plt.tight_layout() plt.show() ## Axes with theory and intervention theory fig, ax1 = plt.subplots(figsize=(15, 7)) ax1.set_xlim(0, x_lim) plt.xticks(fontsize=20) plt.yticks(fontsize=20) x_vals = np.arange(1, x_lim) x_ticks = np.arange(2, x_lim, int((x_lim - 2) / 10)) ax1.set_xlim(0, max(x_vals)) ax1.set_xticks(x_ticks) ax1.semilogy() ax1.set_ylim(.00005, .1) ax1.set_xlabel('Cumulative Infections', fontsize=20) ax1.set_ylabel('Probability', fontsize=20) for gen in list_of_gens: fname_predict = fname_predict_format.format(gen) fname_sims = fname_sim_results if fname_sim_results_int is not None and fname_predict_format_int is not None: fname_predict_interv = fname_predict_format_int.format(gen) fname_sims_interv = fname_sim_results_int else: fname_sims_interv = None fname_predict_interv = None nerccs_plot_sims_vs_analytical_outbreak_sizes(fig, ax1, gen, x_lim, None, fname_predict, None, fname_predict_interv, color_key, style_key, same_plot, normalize_axis_x, grayscale) right, bottom, width, height = [0.4, 0.75, 0.25, 0.003] ax2 = fig.add_axes([right, bottom, width, height], frameon=False) ax2.set_xlabel(inset_label, fontsize=25) ax2.set_xticks([]) ax2.set_yticks([]) # power_law_dd = degree_distributions.power_law_degree_distrb(400) # ax2.plot(power_law_dd[:15], color='black') # ax2.set_xlim(0, 14) # ax2.set_xlabel('Degree $k$', fontsize=20) # ax2.set_ylabel('Fraction of nodes', fontsize=20) # ax2.set_yticks(np.arange(0, 1, 0.25)) # ax2.set_xticks([0, 1, 2, 3, 5, 10]) # ax2.semilogy() plt.tight_layout() plt.show() ## Axes with theory and intervention theory and intervention sims fig, ax1 = plt.subplots(figsize=(15, 7)) ax1.set_xlim(0, x_lim) plt.xticks(fontsize=20) plt.yticks(fontsize=20) x_vals = np.arange(1, x_lim) x_ticks = np.arange(2, x_lim, int((x_lim - 2) / 10)) ax1.set_xlim(0, max(x_vals)) ax1.set_xticks(x_ticks) ax1.semilogy() ax1.set_ylim(.00005, .1) ax1.set_xlabel('Cumulative Infections', fontsize=20) ax1.set_ylabel('Probability', fontsize=20) for gen in list_of_gens: fname_predict = fname_predict_format.format(gen) fname_sims = fname_sim_results if fname_sim_results_int is not None and fname_predict_format_int is not None: fname_predict_interv = fname_predict_format_int.format(gen) fname_sims_interv = fname_sim_results_int else: fname_sims_interv = None fname_predict_interv = None nerccs_plot_sims_vs_analytical_outbreak_sizes(fig, ax1, gen, x_lim, None, fname_predict, fname_sims_interv, fname_predict_interv, color_key, style_key, same_plot, normalize_axis_x, grayscale) right, bottom, width, height = [0.4, 0.75, 0.25, 0.003] ax2 = fig.add_axes([right, bottom, width, height], frameon=False) ax2.set_xlabel(inset_label, fontsize=25) ax2.set_xticks([]) ax2.set_yticks([]) # power_law_dd = degree_distributions.power_law_degree_distrb(400) # ax2.plot(power_law_dd[:15], color='black') # ax2.set_xlim(0, 14) # ax2.set_xlabel('Degree $k$', fontsize=20) # ax2.set_ylabel('Fraction of nodes', fontsize=20) # ax2.set_yticks(np.arange(0, 1, 0.25)) # ax2.set_xticks([0, 1, 2, 3, 5, 10]) # ax2.semilogy() plt.tight_layout() plt.show()
import src.degree_distributions as degree_distributions import src.pgf_formalism as pgf_formalism import src.plotting_util as plotting_util size = 250 def exp_val_dd(dist): ev = 0 for k in range(len(dist)): ev += k * dist[k] return ev power_law_dd = degree_distributions.power_law_degree_distrb(size, mu=5) extnct_cake_PL_1, psi_1 = pgf_formalism.compute_extinct_prob_all(power_law_dd, T=0.8, n_gens=11, renorm=True) power_law_dd = degree_distributions.power_law_degree_distrb(size, mu=7.5) extnct_cake_PL_2, psi_2 = pgf_formalism.compute_extinct_prob_all(power_law_dd, T=0.8, n_gens=11, renorm=True) power_law_dd = degree_distributions.power_law_degree_distrb(size, mu=10) extnct_cake_PL_3, psi_3 = pgf_formalism.compute_extinct_prob_all(power_law_dd, T=0.8, n_gens=11,