Skip to content

Commit

Permalink
pull request fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
WillHWThompson committed Jan 30, 2024
1 parent 744dfae commit 4151fcf
Show file tree
Hide file tree
Showing 5 changed files with 1,103 additions and 63 deletions.
664 changes: 664 additions & 0 deletions Extra/plot_fig1.ipynb

Large diffs are not rendered by default.

436 changes: 436 additions & 0 deletions Extra/plot_fig2.ipynb

Large diffs are not rendered by default.

17 changes: 0 additions & 17 deletions fig_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,13 @@
"""

import os

import matplotlib.pylab as pylab
import matplotlib.pyplot as plt


import matplotlib as mpl
import matplotlib.colors as mcolors
from cycler import cycler
import cmasher as cmr




#color styling


def set_colors(n_colors = 2):
global cmap
global pallette
Expand All @@ -32,9 +23,6 @@ def set_colors(n_colors = 2):
mpl.rcParams['axes.prop_cycle'] = mpl.cycler(color= pallette)


# cmap = mcolors.LinearSegmentedColormap.from_list('my_cmap',[pallete[0],pallete[1]])
# cmap = cmr.ember

def set_fontsize():
plt.rcParams['axes.labelsize'] = 30
# Set the global default size of the tick labels
Expand Down Expand Up @@ -86,11 +74,6 @@ def fig_size(frac_width, frac_height, n_cols=1, n_rows=1):

return (width, height)






def get_formats():
return ["eps", "jpg", "pdf", "png", "tif"]

Expand Down
29 changes: 2 additions & 27 deletions plot_fig1.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,13 @@

import json

import arviz as az
import cmasher as cmr
import matplotlib.cm as cm
import matplotlib.pyplot as plt
import numpy as np
import seaborn as sns
import xgi

import fig_settings as fs
from lcs import *

import matplotlib as mpl
import matplotlib.colors as mcolors
from cycler import cycler



fs.set_fonts()
Expand Down Expand Up @@ -45,7 +37,7 @@

x = contagion_process(A, gamma, c, x0, tmin=0, tmax=100, random_seed=2)

infected_color = 'C1'
infected_color = 'C0'
susceptible_color = "white"
subgraph_color = "black"
graph_color = (0.1, 0.1, 0.1, 0.1)
Expand All @@ -59,7 +51,7 @@
pos = xgi.pca_transform(xgi.pairwise_spring_layout(H, seed=5, k=0.3))
node_fc = [infected_color if x[t, i] else susceptible_color for i in H.nodes]
node_ec = [subgraph_node_lc if n in nbrs else graph_node_lc for n in H.nodes]
node_fc[12] = 'C0'
node_fc[12] = 'C1'

dyad_color = [subgraph_color if e in sg else graph_color for e in H.edges]

Expand All @@ -76,9 +68,6 @@
ax = ax1
)

# plt.savefig("Figures/Fig1/zkc_network.svg", dpi=1000)
# plt.savefig("Figures/Fig1/zkc_network.png", dpi=1000)


"""
Panel 2:
Expand All @@ -101,9 +90,6 @@
l1 = np.array(data["l1"], dtype=float)
l2 = np.array(data["l2"], dtype=float)

# import cmasher as cmr
# cmap = cmr.ember

kmax = np.max(degrees(A))
n = A.shape[0]

Expand All @@ -112,7 +98,6 @@
# simple contagion
c1_mean = c1_samples.mean(axis=0)
ax2.plot(nus, c1, "-", color='C0', label="Simple contagion")
# ax2.scatter(nus, c1_mean, linewidth=0.5, color=colors[2])

err_c1 = np.zeros((2, n))
c1_mode = np.zeros(n)
Expand All @@ -126,7 +111,6 @@
# threshold contagion, tau=2
c2_mean = c2_samples.mean(axis=0)
ax2.plot(nus, c2, "-", color='C1', label="Complex contagion")
# ax2.scatter(nus, c2_mean, linewidth=0.5, color=colors[1])

err_c2 = np.zeros((2, n))
c2_mode = np.zeros(n)
Expand All @@ -150,10 +134,6 @@
sns.despine()


# # ax2.savefig("Figures/Fig1/zkc_infer_contagion_function.svg", dpi=1000)
# # ax2.savefig("Figures/Fig1/zkc_infer_contagion_function.png", dpi=1000)
# ax2.show()

with open("Data/zkc_infer_vs_tmax.json") as file:
data = json.load(file)

Expand All @@ -164,7 +144,6 @@
fce = np.array(data["fce"], dtype=float)


#ax3.semilogx(tmax, sps[0].mean(axis=1), color=colors[2], label="Simple contagion")
ax3.semilogx(tmax, sps[0].mean(axis=1), color='C0', label="Simple contagion")
ax3.semilogx(tmax, sps[1].mean(axis=1), color='C1', label="Complex contagion")
ax3.fill_between(
Expand Down Expand Up @@ -197,7 +176,6 @@
sps = np.array(data["sps"], dtype=float)
fce = np.array(data["fce"], dtype=float)

#cmap = cmr.gem
cmap = cmap

sps_summary = sps.mean(axis=2)
Expand All @@ -222,8 +200,5 @@
cbar = plt.colorbar(c, cax=cbar_ax)
cbar.set_label(r"F-Score", fontsize=12, rotation=270, labelpad=15)

#plt.tight_layout()


plt.savefig("Figures/Fig1/figure1_4panel.png", dpi=1000)
plt.savefig("Figures/Fig1/figure1_4_panel.pdf", dpi=1000)
20 changes: 1 addition & 19 deletions plot_fig2.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,17 @@

import json

import arviz as az
import cmasher as cmr
import matplotlib.cm as cm
import matplotlib.pyplot as plt
import numpy as np
import seaborn as sns
import xgi

import fig_settings as fs
from lcs import *

import matplotlib as mpl
import matplotlib.colors as mcolors
from cycler import cycler



fs.set_fonts()
fs.set_colors()
#fs.set_fontsize()
cmap = fs.cmap

fs.set_fonts({"font.family": "sans-serif"})
cmap = fs.cmap


models = ["Erdos-Renyi", "SBM", "Watts-Strogatz", "CM", "clustered_network"]
Expand Down Expand Up @@ -51,7 +39,6 @@
]
convert_to_log = [False, False, True, False, False]


def visualize_networks(i, ax):
n = 50
match i:
Expand Down Expand Up @@ -90,11 +77,6 @@ def visualize_networks(i, ax):
case 2:
pos = xgi.circular_layout(H)
case 3:
# sorted_nodes = [n for n, _ in sorted(H.nodes.degree.asdict().items(), key=lambda d: d[1])]
# Hnew = xgi.Hypergraph()
# Hnew.add_nodes_from(sorted_nodes)
# Hnew.add_edges_from(e)
# pos = xgi.circular_layout(Hnew)
pos = xgi.pairwise_spring_layout(H, seed=2)
case 4:
pos = xgi.pairwise_spring_layout(H, seed=2)
Expand Down

0 comments on commit 4151fcf

Please sign in to comment.