-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsiqvd_stochastic_geometric_brownian.py
116 lines (102 loc) · 2.9 KB
/
siqvd_stochastic_geometric_brownian.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# Imports
from numpy import zeros, linspace
import numpy as np
import matplotlib.pyplot as plt
import math
# --------------------------------------------------------------------------------------
# Parameters/Variables
b = .8 # MALWARE INITAL POPOGATION RATE
e = 1
y = .5 # infected
ol = .46 # vaccination rate
w = .05 # loss of immunity
o = .6 # quarantined
g = .2
r = 5
# --------------------------------------------------------------------------------------
# Define the time vector
t_max = 30
dt = 1/30
sd_list = [0, .1, .2, .3]
# --------------------------------------------------------------------------------------
# Susceptible (S), infected (I), quarantined (Q), vaccinated (V), and delay hosts (D)
t = np.arange(0, t_max, dt)
S = zeros(len(t))
I = zeros(len(t))
Q = zeros(len(t))
V = zeros(len(t))
D = zeros(len(t))
# --------------------------------------------------------------------------------------
# Initial conditions
S0 = 30
I0 = 3
Q0 = 0
V0 = 0
D0 = 0
S[0] = S0
I[0] = I0
Q[0] = Q0
V[0] = V0
D[0] = D0
paths = []
np.random.seed(8)
# --------------------------------------------------------------------------------------
# Eulers
for sd in sd_list:
S = np.zeros(len(t))
I = np.zeros(len(t))
Q = np.zeros(len(t))
V = np.zeros(len(t))
D = np.zeros(len(t))
S[0] = S0
I[0] = I0
Q[0] = Q0
V[0] = V0
D[0] = D0
for i in range(1, len(t)):
# Beta Fxn
bf = b/(1+e*I[i-1])
# S
sdt = (-bf*I[i-1]*S[i-1]-ol*S[i-1]+w*V[((i-1)-r*30)]) * \
dt + sd*np.sqrt(dt)*np.random.normal(0, 1)*S[i-1]
# I
idt = (bf*I[i-1]*S[i-1]-(y+g)*I[i-1])*dt + sd * \
np.sqrt(dt)*np.random.normal(0, 1)*I[i-1]
# Q
qdt = (g*I[i-1]-o*Q[i-1])*dt + sd * \
np.sqrt(dt)*np.random.normal(0, 1)*Q[i-1]
# V
vdt = (ol*S[i-1]+y*I[i-1]+o*Q[i-1]-w*V[i-1])*dt + \
sd*np.sqrt(dt)*np.random.normal(0, 1)*V[i-1]
# D
ddt = (w*V[i-1]-w*V[((i-1)-r*30)])*dt + sd * \
np.sqrt(dt)*np.random.normal(0, 1)*D[i-1]
S[i] = S[i-1] + sdt
I[i] = I[i-1] + idt
Q[i] = Q[i-1] + qdt
V[i] = V[i-1] + vdt
D[i] = D[i-1] + ddt
paths.append(V)
# --------------------------------------------------------------------------------------
count = -1
# for path in paths:
# count += 1
# sigma = "Sigma = " + str(sd_list[count])
# plt.plot(t, path, label=sigma)
# plt.xlabel("Time Units")
# plt.ylabel("Number of Nodes")
# plt.legend()
# plt.title("Modeling Vaccinated Nodes")
# plt.show()
# Plot the results
fig, ax = plt.subplots()
ax.plot(t, S, label='Susceptible')
ax.plot(t, I, label='Infected')
ax.plot(t, Q, label='Quarantined')
ax.plot(t, V, label='Vaccinated')
ax.plot(t, D, label='Delay Hosts')
ax.set_xlabel('Time Units')
ax.set_ylabel('Number of Nodes')
ax.set_title('Modeling Malware Stages with Stochasticity')
ax.legend()
plt.show()