-
Notifications
You must be signed in to change notification settings - Fork 0
/
SIS_vs_epsilon2_epsilon3.py
79 lines (62 loc) · 1.91 KB
/
SIS_vs_epsilon2_epsilon3.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import json
import os
import numpy as np
import xgi
from src.HypergraphContagion import get_opinion_disparity_in_parallel
is_verbose = True
num_processes = len(os.sched_getaffinity(0))
# Epidemic parameters
gamma = 1
tmax = 100
fraction_to_average = 0.1
num_nodes = 10000
num_sims = 1
beta2tilde = 0.2
beta3tilde = 4
output_filename = "empirical_epsilon2_epsilon3_opinion_disparity.json"
with open("Data/SBM/hypergraphs/epsilon_values.json") as file:
data = json.loads(file.read())
epsilon2 = data["epsilon2"]
epsilon3 = data["epsilon3"]
n = len(epsilon2)
m = len(epsilon3)
data = dict()
arglist = list()
for e2 in epsilon2:
for e3 in epsilon3:
fname = f"Data/SBM/hypergraphs/{e2}-{e3}.json"
H = xgi.read_json(fname, nodetype=int)
community1 = set(list(H.nodes)[: int(H.num_nodes / 2)])
community2 = set(list(H.nodes)[int(H.num_nodes / 2) :])
mean_link_degree = H.nodes.degree(order=1).mean()
mean_triangle_degree = H.nodes.degree(order=2).mean()
beta2c = gamma / mean_link_degree
beta3c = gamma / mean_triangle_degree
beta2 = beta2tilde * beta2c
beta3 = beta3tilde * beta3c
beta = {2: beta2, 3: beta3}
arglist.append(
(
fname,
gamma,
beta,
community1,
community2,
tmax,
fraction_to_average,
num_sims,
is_verbose,
)
)
print("Simulations started!", flush=True)
psi = get_opinion_disparity_in_parallel(arglist, num_processes)
psi = np.reshape(psi, [n, m], order="C")
data["gamma"] = gamma
data["beta2"] = beta2tilde
data["beta3"] = beta3tilde
data["epsilon2"] = epsilon2
data["epsilon3"] = epsilon3
data["psi"] = psi.tolist()
datastring = json.dumps(data)
with open(f"Data/opiniondisparity/{output_filename}", "w") as output_file:
output_file.write(datastring)