Skip to content

Commit

Permalink
Add epidemic threshold (#35)
Browse files Browse the repository at this point in the history
* add epidemic threshold lines

* fix label
  • Loading branch information
nwlandry authored Apr 24, 2024
1 parent a595934 commit 0138a30
Show file tree
Hide file tree
Showing 22 changed files with 73 additions and 26 deletions.
2 changes: 1 addition & 1 deletion Data/clustered_network.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Data/cm.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Data/erdos-renyi.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Data/sbm.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Data/watts-strogatz.json

Large diffs are not rendered by default.

Binary file modified Figures/Fig1/fig1.pdf
Binary file not shown.
Binary file modified Figures/Fig1/fig1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Figures/Fig2/fig2.pdf
Binary file not shown.
Binary file modified Figures/Fig2/fig2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Figures/Fig4/fig4.pdf
Binary file not shown.
Binary file modified Figures/Fig4/fig4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Figures/Fig5/fig5.pdf
Binary file not shown.
Binary file modified Figures/Fig5/fig5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions collect_clustered_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import numpy as np
from joblib import Parallel, delayed
from numpy.linalg import eigh

from lcs import *

Expand Down Expand Up @@ -58,6 +59,9 @@ def get_metrics(f, dir, c_dict, b_dict, s_dict, r_dict):
m = dict()
m["rho"] = density(A)
m["rho-samples"] = density(samples.mean(axis=0))
m["mean-degree"] = degrees(A).mean()
m["mean-squared-degree"] = (degrees(A) ** 2).mean()
m["pf-eigenvalue"] = eigh(A)[0][-1]
m["ps"] = posterior_similarity(samples, A)
m["sps"] = samplewise_posterior_similarity(samples, A)
m["fs"] = f_score(samples, A)
Expand Down Expand Up @@ -100,6 +104,9 @@ def get_metrics(f, dir, c_dict, b_dict, s_dict, r_dict):
data["size"] = list(s_dict)
data["rho"] = np.zeros((n_c, n_b, n_s, n_r))
data["rho-samples"] = np.zeros((n_c, n_b, n_s, n_r))
data["mean-degree"] = np.zeros((n_c, n_b, n_s, n_r))
data["mean-squared-degree"] = np.zeros((n_c, n_b, n_s, n_r))
data["pf-eigenvalue"] = np.zeros((n_c, n_b, n_s, n_r))
data["ps"] = np.zeros((n_c, n_b, n_s, n_r))
data["sps"] = np.zeros((n_c, n_b, n_s, n_r))
data["fs"] = np.zeros((n_c, n_b, n_s, n_r))
Expand Down
7 changes: 7 additions & 0 deletions collect_cm.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import numpy as np
from joblib import Parallel, delayed
from numpy.linalg import eigh

from lcs import *

Expand Down Expand Up @@ -58,6 +59,9 @@ def get_metrics(f, dir, c_dict, b_dict, a_dict, r_dict):
m = dict()
m["rho"] = density(A)
m["rho-samples"] = density(samples.mean(axis=0))
m["mean-degree"] = degrees(A).mean()
m["mean-squared-degree"] = (degrees(A) ** 2).mean()
m["pf-eigenvalue"] = eigh(A)[0][-1]
m["ps"] = posterior_similarity(samples, A)
m["sps"] = samplewise_posterior_similarity(samples, A)
m["fs"] = f_score(samples, A)
Expand Down Expand Up @@ -95,6 +99,9 @@ def get_metrics(f, dir, c_dict, b_dict, a_dict, r_dict):
data["alpha"] = list(a_dict)
data["rho"] = np.zeros((n_c, n_b, n_a, n_r))
data["rho-samples"] = np.zeros((n_c, n_b, n_a, n_r))
data["mean-degree"] = np.zeros((n_c, n_b, n_a, n_r))
data["mean-squared-degree"] = np.zeros((n_c, n_b, n_a, n_r))
data["pf-eigenvalue"] = np.zeros((n_c, n_b, n_a, n_r))
data["ps"] = np.zeros((n_c, n_b, n_a, n_r))
data["sps"] = np.zeros((n_c, n_b, n_a, n_r))
data["fs"] = np.zeros((n_c, n_b, n_a, n_r))
Expand Down
7 changes: 7 additions & 0 deletions collect_erdos-renyi.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import numpy as np
from joblib import Parallel, delayed
from numpy.linalg import eigh

from lcs import *

Expand Down Expand Up @@ -58,6 +59,9 @@ def get_metrics(f, dir, c_dict, b_dict, p_dict, r_dict):
m = dict()
m["rho"] = density(A)
m["rho-samples"] = density(samples.mean(axis=0))
m["mean-degree"] = degrees(A).mean()
m["mean-squared-degree"] = (degrees(A) ** 2).mean()
m["pf-eigenvalue"] = eigh(A)[0][-1]
m["ps"] = posterior_similarity(samples, A)
m["sps"] = samplewise_posterior_similarity(samples, A)
m["fs"] = f_score(samples, A)
Expand Down Expand Up @@ -95,6 +99,9 @@ def get_metrics(f, dir, c_dict, b_dict, p_dict, r_dict):
data["p"] = list(p_dict)
data["rho"] = np.zeros((n_c, n_b, n_p, n_r))
data["rho-samples"] = np.zeros((n_c, n_b, n_p, n_r))
data["mean-degree"] = np.zeros((n_c, n_b, n_p, n_r))
data["mean-squared-degree"] = np.zeros((n_c, n_b, n_p, n_r))
data["pf-eigenvalue"] = np.zeros((n_c, n_b, n_p, n_r))
data["ps"] = np.zeros((n_c, n_b, n_p, n_r))
data["sps"] = np.zeros((n_c, n_b, n_p, n_r))
data["fs"] = np.zeros((n_c, n_b, n_p, n_r))
Expand Down
7 changes: 7 additions & 0 deletions collect_sbm.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import numpy as np
from joblib import Parallel, delayed
from numpy.linalg import eigh

from lcs import *

Expand Down Expand Up @@ -58,6 +59,9 @@ def get_metrics(f, dir, c_dict, b_dict, e_dict, r_dict):
m = dict()
m["rho"] = density(A)
m["rho-samples"] = density(samples.mean(axis=0))
m["mean-degree"] = degrees(A).mean()
m["mean-squared-degree"] = (degrees(A) ** 2).mean()
m["pf-eigenvalue"] = eigh(A)[0][-1]
m["ps"] = posterior_similarity(samples, A)
m["sps"] = samplewise_posterior_similarity(samples, A)
m["fs"] = f_score(samples, A)
Expand Down Expand Up @@ -95,6 +99,9 @@ def get_metrics(f, dir, c_dict, b_dict, e_dict, r_dict):
data["epsilon"] = list(e_dict)
data["rho"] = np.zeros((n_c, n_b, n_e, n_r))
data["rho-samples"] = np.zeros((n_c, n_b, n_e, n_r))
data["mean-degree"] = np.zeros((n_c, n_b, n_e, n_r))
data["mean-squared-degree"] = np.zeros((n_c, n_b, n_e, n_r))
data["pf-eigenvalue"] = np.zeros((n_c, n_b, n_e, n_r))
data["ps"] = np.zeros((n_c, n_b, n_e, n_r))
data["sps"] = np.zeros((n_c, n_b, n_e, n_r))
data["fs"] = np.zeros((n_c, n_b, n_e, n_r))
Expand Down
7 changes: 7 additions & 0 deletions collect_watts-strogatz.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import numpy as np
from joblib import Parallel, delayed
from numpy.linalg import eigh

from lcs import *

Expand Down Expand Up @@ -58,6 +59,9 @@ def get_metrics(f, dir, c_dict, b_dict, p_dict, r_dict):
m = dict()
m["rho"] = density(A)
m["rho-samples"] = density(samples.mean(axis=0))
m["mean-degree"] = degrees(A).mean()
m["mean-squared-degree"] = (degrees(A) ** 2).mean()
m["pf-eigenvalue"] = eigh(A)[0][-1]
m["ps"] = posterior_similarity(samples, A)
m["sps"] = samplewise_posterior_similarity(samples, A)
m["fs"] = f_score(samples, A)
Expand Down Expand Up @@ -95,6 +99,9 @@ def get_metrics(f, dir, c_dict, b_dict, p_dict, r_dict):
data["p"] = list(p_dict)
data["rho"] = np.zeros((n_c, n_b, n_p, n_r))
data["rho-samples"] = np.zeros((n_c, n_b, n_p, n_r))
data["mean-degree"] = np.zeros((n_c, n_b, n_p, n_r))
data["mean-squared-degree"] = np.zeros((n_c, n_b, n_p, n_r))
data["pf-eigenvalue"] = np.zeros((n_c, n_b, n_p, n_r))
data["ps"] = np.zeros((n_c, n_b, n_p, n_r))
data["sps"] = np.zeros((n_c, n_b, n_p, n_r))
data["fs"] = np.zeros((n_c, n_b, n_p, n_r))
Expand Down
6 changes: 3 additions & 3 deletions plot_fig1.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@
va="top",
)

measure = "auprc"
measure = "auroc"

with open("Data/zkc_infer_vs_tmax.json") as file:
data = json.load(file)
Expand Down Expand Up @@ -241,7 +241,7 @@
hdi_b[i] = b

ax3.fill_between(tmax, hdi_a, hdi_b, alpha=0.3, color="C1", edgecolor="none")
ax3.set_ylabel("AUPRC")
ax3.set_ylabel(measure.upper())
ax3.set_xlabel(r"$t_{\mathregular{max}}$")
ax3.set_xlim([10, 10**4])
ax3.set_xticks(
Expand All @@ -258,7 +258,7 @@

ax3.legend(
loc="lower right",
bbox_to_anchor=(0.87, -0.05, 0.2, 0.2),
bbox_to_anchor=(0.87, -0.07, 0.2, 0.2),
markerfirst=False,
frameon=False,
handlelength=0.8,
Expand Down
24 changes: 15 additions & 9 deletions plot_fig2.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import json

import matplotlib.cm as cm
import matplotlib.pyplot as plt
import numpy as np
import xgi
Expand All @@ -8,10 +9,10 @@
import fig_settings as fs
from lcs import *

gamma = 0.1
measure = "auroc"
axis_limits = [0, 1]

measure = "auprc"

fs.set_fonts()
fs.set_colors()
cmap = fs.cmap
Expand Down Expand Up @@ -86,17 +87,18 @@ def visualize_networks(i, ax):
data = json.load(file)
var = np.array(data[keys[i]], dtype=float)
b = np.array(data["beta"], dtype=float)
l = np.array(data["pf-eigenvalue"], dtype=float)[0].mean(axis=0).mean(axis=1)

performance = np.array(data[measure], dtype=float)

# plot the difference in auprc
# plot the difference in auroc
mean_difference = performance[1].mean(axis=2).T - performance[0].mean(axis=2).T
ax = fig.add_subplot(gs[1, i])
im1 = ax.imshow(
to_imshow_orientation(mean_difference),
extent=(min(var), max(var), min(b), max(b)),
vmin=-0.5,
vmax=0.5,
vmin=-0.3,
vmax=0.3,
aspect="auto",
cmap=cmap,
)
Expand All @@ -105,6 +107,10 @@ def visualize_networks(i, ax):
ax.set_xticks(xticks[i], xticklabels[i])
ax.set_yticks([0, 0.5, 1], [0, 0.5, 1])

beta_c = gamma / l
for r0 in range(1, 10, 2):
ax.plot(var, r0 * beta_c, "r-", linewidth=0.5)

if i == 0:
ax.set_ylabel(r"$\beta$")
else:
Expand All @@ -122,8 +128,8 @@ def visualize_networks(i, ax):
im2 = ax.imshow(
to_imshow_orientation(mean_difference),
extent=(min(var), max(var), min(b), max(b)),
vmin=-0.5,
vmax=0.5,
vmin=-0.3,
vmax=0.3,
aspect="auto",
cmap=cmap,
)
Expand All @@ -142,12 +148,12 @@ def visualize_networks(i, ax):
cbar_ax1 = fig.add_axes([0.85, 0.4, 0.015, 0.25])
cbar = fig.colorbar(im1, cax=cbar_ax1)
cbar.set_label(rf"$\Delta$ {measure.upper()}", rotation=270, labelpad=10)
cbar_ax1.set_yticks([-0.5, 0, 0.5])
cbar_ax1.set_yticks([-0.3, 0, 0.3])

cbar_ax2 = fig.add_axes([0.86, 0.1, 0.015, 0.25])
cbar = fig.colorbar(im2, cax=cbar_ax2)
cbar.set_label(r"$\Delta\, \phi_{\rho}$", rotation=270, labelpad=10)
cbar_ax2.set_yticks([-0.5, 0, 0.5])
cbar_ax2.set_yticks([-0.3, 0, 0.3])

for i, m in enumerate(models):
ax = fig.add_subplot(gs[0, i])
Expand Down
2 changes: 1 addition & 1 deletion plot_fig4.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import fig_settings as fs
from lcs import *

measure = "auprc"
measure = "auroc"
axis_limits = [0, 1]

axislabel_fontsize = 20
Expand Down
22 changes: 14 additions & 8 deletions plot_fig5.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
import fig_settings as fs
from lcs import *

measure = "auprc"
gamma = 0.1
measure = "auroc"

axis_limits = [0, 1]

Expand Down Expand Up @@ -90,17 +91,18 @@ def visualize_networks(i, ax):
data = json.load(file)
var = np.array(data[keys[i]], dtype=float)
b = np.array(data["beta"], dtype=float)
l = np.array(data["pf-eigenvalue"], dtype=float)[0].mean(axis=0).mean(axis=1)

performance = np.array(data[measure], dtype=float)

# plot the difference in auprc
# plot the difference in auroc
mean_difference = performance[2].mean(axis=2).T - performance[0].mean(axis=2).T
ax = fig.add_subplot(gs[1, i])
im1 = ax.imshow(
to_imshow_orientation(mean_difference),
extent=(min(var), max(var), min(b), max(b)),
vmin=-0.5,
vmax=0.5,
vmin=-0.3,
vmax=0.3,
aspect="auto",
cmap=cmap,
)
Expand All @@ -109,6 +111,10 @@ def visualize_networks(i, ax):
ax.set_xticks(xticks[i], xticklabels[i])
ax.set_yticks([0, 0.5, 1], [0, 0.5, 1])

beta_c = gamma / l
for r0 in range(1, 10, 2):
ax.plot(var, r0 * beta_c, "r-", linewidth=0.5)

if i == 0:
ax.set_ylabel(r"$\beta$")
else:
Expand All @@ -126,8 +132,8 @@ def visualize_networks(i, ax):
im2 = ax.imshow(
to_imshow_orientation(mean_difference),
extent=(min(var), max(var), min(b), max(b)),
vmin=-0.5,
vmax=0.5,
vmin=-0.3,
vmax=0.3,
aspect="auto",
cmap=cmap,
)
Expand All @@ -146,12 +152,12 @@ def visualize_networks(i, ax):
cbar_ax1 = fig.add_axes([0.85, 0.4, 0.015, 0.25])
cbar = fig.colorbar(im1, cax=cbar_ax1)
cbar.set_label(rf"$\Delta$ {measure.upper()}", rotation=270, labelpad=10)
cbar_ax1.set_yticks([-0.5, 0, 0.5])
cbar_ax1.set_yticks([-0.3, 0, 0.3])

cbar_ax2 = fig.add_axes([0.85, 0.1, 0.015, 0.25])
cbar = fig.colorbar(im2, cax=cbar_ax2)
cbar.set_label(r"$\Delta\, \phi_{\rho}$", rotation=270, labelpad=10)
cbar_ax2.set_yticks([-0.5, 0, 0.5])
cbar_ax2.set_yticks([-0.3, 0, 0.3])

for i, m in enumerate(models):
ax = fig.add_subplot(gs[0, i])
Expand Down

0 comments on commit 0138a30

Please sign in to comment.