-
Notifications
You must be signed in to change notification settings - Fork 0
/
erdos-renyi.py
68 lines (53 loc) · 1.53 KB
/
erdos-renyi.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
import os
import numpy as np
from joblib import Parallel, delayed
from lcs import *
data_dir = "Data/erdos-renyi"
os.makedirs(data_dir, exist_ok=True)
for f in os.listdir(data_dir):
os.remove(os.path.join(data_dir, f))
n_processes = len(os.sched_getaffinity(0))
# contagion functions and parameters
cf1 = lambda nu, b: 1 - (1 - b) ** nu # simple contagion
cf2 = lambda nu, b: b * (nu >= 2) # complex contagion, tau=2
cf3 = lambda nu, b: b * (nu >= 3) # complex contagion, tau=3
cfs = [cf1, cf2, cf3]
realizations = 10
n_p = 33
n_b = 33
n = 50
p_list = np.linspace(0.0, 1.0, n_p)
beta_list = np.linspace(0.0, 1.0, n_b)
rho0 = 1.0
gamma = 0.1
tmax = 2000
# MCMC parameters
burn_in = 100000
nsamples = 100
skip = 10000
p_c = np.ones((2, n))
p_rho = np.array([1, 1])
arglist = []
for i, cf in enumerate(cfs):
for b in beta_list:
for p in p_list:
for r in range(realizations):
c = cf(np.arange(n), b)
A = erdos_renyi(n, p)
arglist.append(
(
f"{data_dir}/{i}_{b}_{p}_{r}",
gamma,
c,
b,
rho0,
A,
tmax,
p_c.copy(),
p_rho.copy(),
nsamples,
burn_in,
skip,
)
)
Parallel(n_jobs=n_processes)(delayed(single_inference)(*arg) for arg in arglist)