-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMMCA.py
65 lines (55 loc) · 1.57 KB
/
MMCA.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
from email import header
# -*- encoding: utf-8 -*-
'''
@File : mmca.py
@Time : 2022/04/05 19:06:50
@Author : Fei Gao
@Contact : [email protected]
BNU, Beijing, China
'''
import numpy as np
from utils import convert2nb_dict, ifConverge
from numba import njit
@njit()
def update(N, I, beta, beta_D, gamma, node_neighbors_dict, tri_neighbors_dict):
Inew = I.copy()
for i in range(N):
qi = 1
try:
for j in node_neighbors_dict[i]:
qi *= 1 - beta * I[j]
except:
pass
try:
for (j, k) in tri_neighbors_dict[i]:
qi *= 1 - beta_D * I[j] * I[k]
except:
pass
Inew[i] = (1 - I[i]) * (1 - qi) + I[i] * (1 - gamma)
return Inew
def Hror_SIS_MMCA(beta,
beta_D,
gamma,
node_neighbors_dict,
tri_neighbors_dict,
tmax,
I0,
steady:bool=True):
node_neighbors_dict, tri_neighbors_dict = convert2nb_dict(node_neighbors_dict, tri_neighbors_dict)
N = len(node_neighbors_dict)
I = np.zeros(N)
for idx in I0:
I[idx] = 1
rho = np.zeros(tmax)
rho[0] = np.mean(I)
for t in range(1, tmax):
I = update(N, I, beta, beta_D, gamma, node_neighbors_dict, tri_neighbors_dict)
rho[t] = np.mean(I)
if ifConverge(rho[:t], N):
rho = rho[:t]
break
if steady:
out = np.mean(rho[-100:])
else:
out = rho
return beta, out