-
Notifications
You must be signed in to change notification settings - Fork 0
/
zkc_frac_vs_beta.py
63 lines (51 loc) · 1.37 KB
/
zkc_frac_vs_beta.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
import os
import numpy as np
from joblib import Parallel, delayed
from lcs import *
data_dir = "Data/zkc_frac_vs_beta"
os.makedirs(data_dir, exist_ok=True)
for f in os.listdir(data_dir):
os.remove(os.path.join(data_dir, f))
A = zkc()
n = A.shape[0]
n_processes = len(os.sched_getaffinity(0))
realizations = 10
nf = 33
nb = 33
# MCMC parameters
burn_in = 100000
nsamples = 1000
skip = 10000
p_c = np.ones((2, n))
p_rho = np.array([1, 1])
# contagion functions and parameters
sc = lambda nu, beta: 1 - (1 - beta) ** nu # simple contagion
cc = lambda nu, tau, beta: beta * (nu >= tau) # complex contagion
rho0 = 1.0
gamma = 0.1
tau = 2
beta = np.linspace(0, 1.0, nb)
frac = np.linspace(0, 1.0, nf)
tmax = 1000
arglist = []
for f in frac:
for b in beta:
for r in range(realizations):
c = f * sc(np.arange(n), b) + (1 - f) * cc(np.arange(n), tau, b)
arglist.append(
(
f"{data_dir}/{f}_{b}_{r}",
gamma,
c,
b,
rho0,
A.copy(),
tmax,
p_c.copy(),
p_rho.copy(),
nsamples,
burn_in,
skip,
)
)
Parallel(n_jobs=n_processes)(delayed(single_inference)(*arg) for arg in arglist)