forked from moeinkh88/Ebola_modelling
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Allplots_Models280.jl
322 lines (270 loc) · 12.5 KB
/
Allplots_Models280.jl
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
# plots ODE + FDE, variable and constant N, heatmaps
using CSV, DataFrames, DelimitedFiles
using FdeSolver, Plots,SpecialFunctions, Optim, StatsBase, Random
using Interpolations, LinearAlgebra
using LaTeXStrings
# Dataset
Data=CSV.read("datoswho.csv", DataFrame)
data=(Matrix(Float64.(Data)))
Data2=LinearInterpolation(data[:,1], data[:,2]) #Interpolate the data
#initial conditons and parameters
x0=[18000,0,15,0,0,0,0,0]# initial conditons S0,E0,I0,R0,L0,H0,B0,C0
α1=3.537e-2 # Density independent part of the birth rate for individuals.
α2=8.334570273681649e-8# Density dependent part of the birth rate for individuals.
σ=1/11.4 # Per capita rate at which exposed individuals become infectious.
γ1=0.1 # Per capita rate of progression of individuals from the infectious class to the asymptomatic class.
γ2=1/5 # Per capita rate of progression of individuals from the hospitalized class to the asymptomatic class.
γ3=1/30 # Per capita recovery rate of individuals from the asymptomatic class to the complete recovered class.
ϵ=1/9.6 # Fatality rate.
δ1=1/2 # Per capita rate of progression of individuals from the dead class to the buried class.
δ2=1/4.6 # Per capita rate of progression of individuals from the hospitalized class to the buried class.
τ=1/5 # Per capita rate of progression of individuals from the infectious class to the hospitalized class.
βi=0.14 # Contact rate of infective individuals and susceptible.
βd=0.4 # Contact rate of infective individuals and dead.
βh=0.29 # Contact rate of infective individuals and hospitalized.
βr=0.2174851498937417 # Contact rate of infective individuals and asymptomatic.
μ=14e-3
μ1=10.17e-3 # Density independent part of the death rate for individuals.
μ2=4.859965522407347e-7 # Density dependent part of the death rate for individuals.
ξ=14e-3 # Incineration rate
par=[α1,σ,γ1,γ2,γ3,ϵ,δ1,δ2,τ,βi,βd,βh,βr,μ1,ξ,α2,μ2]
#Define the equation with variable N
function F(t, x, par)
α1,σ,γ1,γ2,γ3,ϵ,δ1,δ2,τ,βi,βd,βh,βr,μ1,ξ,α2,μ2=par
S, E, I1, R, L, H, B, C=x
N=sum(x)
dS=(α1-α2*N)*N - βi/N*S*I1 - βh/N*S*H - βd/N*S*L - βr/N*S*R - (μ1+μ2*N)*S
dE=βi/N*S*I1 + βh/N*S*H + βd/N*S*L + βr/N*S*R - σ*E - (μ1+μ2*N)*E
dI=σ*E - (γ1 + ϵ + τ + μ1 + μ2*N)*I1
dR=γ1*I1 + γ2*H - (γ3 + μ1 + μ2*N)*R
dL=ϵ*I1 - (δ1+ξ)*L
dH=τ*I1 - (γ2 + δ2 + μ1 + μ2*N)*H
dB=δ1*L + δ2*H - ξ*B
dC=γ3*R - (μ1 + μ2*N)*C
return [dS, dE, dI, dR, dL, dH, dB, dC]
end
#eq with constant N
parC=[α1,σ,γ1,γ2,γ3,ϵ,δ1,δ2,τ,βi,βd,βh,βr,μ1,ξ,sum(x0)]
function Fc(t, x, par)
α1,σ,γ1,γ2,γ3,ϵ,δ1,δ2,τ,βi,βd,βh,βr,μ1,ξ,N=parC
S, E, I, R, L, H, B, C=x
βr=0.7265002737432911
μ=0.06918229886616623
dS=μ*N - βi/N*S*I - βh/N*S*H - βd/N*S*L - βr/N*S*R - μ*S
dE=βi/N*S*I + βh/N*S*H + βd/N*S*L + βr/N*S*R - σ*E - μ*E
dI=σ*E - (γ1 + ϵ + τ + μ)*I
dR=γ1*I + γ2*H - (γ3 + μ)*R
dL=ϵ*I - (δ1+ξ)*L
dH=τ*I - (γ2 + δ2 + μ)*H
dB=δ1*L + δ2*H - ξ*B
dC=γ3*R - μ*C
return [dS, dE, dI, dR, dL, dH, dB, dC]
end
##
T1=280
T2=438
tSpan=[4,T2]
tSpan1=[4,T1]
tSpan2=[T1,T2]
#solve model 1: ODE
_, x= FDEsolver(F, [4,T2], x0, ones(8), par, nc=4,h=.01)
S=x[:,1]; E=x[:,2]; I=x[:,3]; R=x[:,4];
L=x[:,5]; H=x[:,6]; B=x[:,7]; C=x[:,8];
N=sum(x,dims=2)
μ3=mean([μ1 .+ μ2 .* N, α1 .- α2 .*N])
Appx1=@.I+R+L+H+B+C-μ3*(N-S-E)
Err1=rmsd(Appx1[1:10:end,:], Data2(4:.1:T2)) # Root-mean-square error
print("RMSD(Model 1)=$Err1")
#solve Eq constant N: model 2
_, x = FDEsolver(Fc, tSpan, x0, ones(8), parC,h=.01,nc=4)
Sc=x[:,1]; Ec=x[:,2]; Ic=x[:,3]; Rc=x[:,4];
Lc=x[:,5]; Hc=x[:,6]; Bc=x[:,7]; Cc=x[:,8];
Nc=sum(x0)
AppxC=@.Ic+Rc+Lc+Hc+Bc+Cc-μ*(Nc-Sc-Ec)
ErrC=rmsd(AppxC[1:10:end,:], Data2(4:.1:T2))
print("RMSD(Model 2)=$ErrC")
# Model 3: all time fractional
αf=[0.9414876354377308, 0.9999999999997804, 0.999999999999543, 0.9999999999998147, 0.9999999999806818, 0.9999999999981127, 0.9430213976522912, 0.7932329945305198]
_, x= FDEsolver(F, tSpan, x0, αf, par, nc=4,h=.01)
Sf=x[:,1]; Ef=x[:,2]; If=x[:,3]; Rf=x[:,4];
Lf=x[:,5]; Hf=x[:,6]; Bf=x[:,7]; Cf=x[:,8];
Nf=sum(x,dims=2)
μ3=mean([μ1 .+ μ2 .* Nf, α1 .- α2 .*Nf])
AppxF=@.If+Rf+Lf+Hf+Bf+Cf-μ3*(Nf-Sf-Ef)
ErrF=rmsd(AppxF[1:10:end,:], Data2(4:.1:T2)) #
print("RMSD(Model 3)=$ErrF")
# Model 4 using 2 sections: first integer until 250 then fractional
#optimized order of derivatives
# α=[0.9999826367080396, 0.583200182055744, 0.9999997090382831, 0.9999552779111426, 0.9999931233485699, 0.999931061595331, 0.9999999960137106, 0.9999997372162407]
# α=ones(8);α[2]=0.583200182055744
α=[0.5000000002428997,0.6734861099275703,0.5563512458535832,0.6759832954065609 ,0.5000000043012366,0.5502587715278799,0.8839529214763222,0.5000000000260537]
t1, x1= FDEsolver(F, tSpan1, x0, ones(8), par, nc=4,h=.01)
x02=x1[end,:]
t2, x2= FDEsolver(F, tSpan2, x02, α, par, nc=4,h=.01)
xf=vcat(x1,x2[2:end,:])
t=vcat(t1,t2[2:end,:])
Sf2=xf[:,1]; Ef2=xf[:,2]; If2=xf[:,3]; Rf2=xf[:,4];
Lf2=xf[:,5]; Hf2=xf[:,6]; Bf2=xf[:,7]; Cf2=xf[:,8];
Nf2=sum(xf,dims=2)
μ3=mean([μ1 .+ μ2 .* Nf2, α1 .- α2 .*Nf2])
AppxF2=@.If2+Rf2+Lf2+Hf2+Bf2+Cf2-μ3*(Nf2-Sf2-Ef2)
ErrF2=rmsd(AppxF2[1:10:end,:], Data2(4:.1:T2)) # root-mean-square error
print("RMSD(Model 4)=$ErrF2")
# Norm/abs
# Mf8=@.abs(Appx[1:10:end,:] - Data2(4:.1:T2))
# M1=@.abs(Appx1[1:10:end,:] - Data2(4:.1:T2))
#solutions
_, x = FDEsolver(Fc, [4,450], x0, ones(8), parC,h=.01,nc=4)
Sc=x[:,1]; Ec=x[:,2]; Ic=x[:,3]; Rc=x[:,4];
Lc=x[:,5]; Hc=x[:,6]; Bc=x[:,7]; Cc=x[:,8];
Nc=sum(x0)
AppxC=@.Ic+Rc+Lc+Hc+Bc+Cc-μ*(Nc-Sc-Ec)
t, x= FDEsolver(F, [4,450], x0, ones(8), par, nc=4,h=.01)
S=x[:,1]; E=x[:,2]; I=x[:,3]; R=x[:,4];
L=x[:,5]; H=x[:,6]; B=x[:,7]; C=x[:,8];
N=sum(x,dims=2)
μ3=mean([μ1 .+ μ2 .* N, α1 .- α2 .*N])
Appx1=@.I+R+L+H+B+C-μ3*(N-S-E)
t, x= FDEsolver(F, [4,450], x0, αf, par, nc=4,h=.01)
Sf=x[:,1]; Ef=x[:,2]; If=x[:,3]; Rf=x[:,4];
Lf=x[:,5]; Hf=x[:,6]; Bf=x[:,7]; Cf=x[:,8];
Nf=sum(x,dims=2)
μ3=mean([μ1 .+ μ2 .* Nf, α1 .- α2 .*Nf])
AppxF=@.If+Rf+Lf+Hf+Bf+Cf-μ3*(Nf-Sf-Ef)
_, x1_2= FDEsolver(F, tSpan1, x0, ones(8), par, nc=4,h=.01)
x02=x1[end,:]
_, x2_2= FDEsolver(F, [T1,450], x02, α, par, nc=4,h=.01)
xf=vcat(x1_2,x2_2[2:end,:])
Sf2=xf[:,1]; Ef2=xf[:,2]; If2=xf[:,3]; Rf2=xf[:,4];
Lf2=xf[:,5]; Hf2=xf[:,6]; Bf2=xf[:,7]; Cf2=xf[:,8];
Nf2=sum(xf,dims=2)
μ3=mean([μ1 .+ μ2 .* Nf2, α1 .- α2 .*Nf2])
AppxF2=@.If2+Rf2+Lf2+Hf2+Bf2+Cf2-μ3*(Nf2-Sf2-Ef2)''
##plot dynamics
gr()
# pyplot()
plot_font="Computer Modern"
# plotfonts = Plots.font(16, "Helvetica")
scatter(data[:,1],data[:,2], label="Real data", c="khaki3",markerstrokewidth=0)
plot!(t,AppxC,ylabel=L"\textrm{Cumulative\;\;cases} \; (\mathrm{10^3})",lw=2, label="Model 1, RMSD=2085", c="darkorange3", linestyle=:dashdot)
plot!(t,Appx1,lw=2, label="Model 2, RMSD=276.5", c="deepskyblue1",guidefont=font(12,plot_font),
yticks = ([0,5000,10000,15000],string.([0,5,10,15])),fontfamily= plot_font)
plot!(t,AppxF,lw=2, label="Model 3, RMSD=245.9", c="deeppink", linestyle=:dash)
plotModels=plot!(t,AppxF2,xlabel="Days", legendposition=:bottomright, lw=2, label="Model 4, RMSD=170.9", linestyle=:dot, c="blue1",
title = "(a)", titleloc = :left, titlefont = font(10))
#plot population
plot(t,Nc*ones(length(t)),c="darkorange3",lw=2,legendposition=:right,label="Model 1", linestyle=:dashdot)
plot!(t,N,lw=2,legendposition=:right,label="Model 2", c="deepskyblue1")
plot!(t,Nf,lw=2,legendposition=:right,label="Model 3",linestyle=:dash,c="deeppink")
plotN=plot!(t,Nf2,label="Model 4",linestyle=:dot, lw=2, xlabel="Days",guidefont=font(12,plot_font),
ylabel=L"\textrm{Population} \;\; (\mathrm{10^4})", c="blue1", fontfamily="computer modern" ,
yticks = ([20000,30000,40000,50000],string.([2,3,4,5])),
title = "(b)", titleloc = :left, titlefont = font(10))
##plot optimized initial time for FDE
input_file = "Output_Err_time_216_300.txt"
ErrvsTime = readdlm(input_file)
# EvsT= sort(ErrvsTime[:,2])
EvsT=ErrvsTime[sortperm(ErrvsTime[:, 2]), :]
EvsT2=LinearInterpolation(EvsT[:,2] .+ 215, EvsT[:,1])
InitialFDE=scatter(216:300,EvsT2(216:300),
xlabel="Initial time for FDE in Model 4",
ylabel="RMSD",c="black",markerstrokewidth=0,label=:false,
title = "(c) ", titleloc = :left, titlefont = font(10))
# min_val, min_idx = findmin(EvsT[:,2]) # 64 is the min -> 64+216=280
##plot heatmaps
#optimized order of derivatives
Err=zeros(8,40)
Errr=zeros(8,40)
#FDE: model 3
for i=1:8
print(i)# to check in which order is counting
for j=1:40
# print(j)# to check in which itteration is counting
α=ones(8)
α[i]=1-j*.01
t, x= FDEsolver(F, [4,438], x0, α, par, nc=2,h=.01)
S1=x[:,1]; E1=x[:,2]; I1=x[:,3]; R1=x[:,4];
L1=x[:,5]; H1=x[:,6]; B1=x[:,7]; C1=x[:,8];
N1=sum(x,dims=2)
μ3=mean([μ1 .+ μ2 .* N1, α1 .- α2 .*N1])
Appx1=@.I1+R1+L1+H1+B1+C1-μ3*(N1-S1-E1)
Err[i,j]=rmsd(Appx1[1:10:end,:], Data2(4:.1:438)) # Normalized root-mean-square error
end
end
#ODE+FDE: model 4
for i=1:8
print(i)# to check in which order is counting
for j=1:40
# print(j)# to check in which itteration is counting
α=ones(8)
t1, x1= FDEsolver(F, [4,280], x0, α, par, nc=2,h=.01)
x02=x1[end,:]
α[i]=1-j*.01
t2, x2= FDEsolver(F, [280,438], x02, α, par, nc=2,h=.01)
x=vcat(x1,x2[2:end,:])
t=vcat(t1,t2[2:end,:])
S1=x[:,1]; E1=x[:,2]; I1=x[:,3]; R1=x[:,4];
L1=x[:,5]; H1=x[:,6]; B1=x[:,7]; C1=x[:,8];
N1=sum(x,dims=2)
μ3=mean([μ1 .+ μ2 .* N1, α1 .- α2 .*N1])
Appx1=@.I1+R1+L1+H1+B1+C1-μ3*(N1-S1-E1)
Errr[i,j]=rmsd(Appx1[1:10:end,:], Data2(4:.1:438)) # Normalized root-mean-square error
end
end
RMSD1= log10(Err1) #error for integer order
# plot heatmap model 4
CoLor = cgrad([:darkblue,:blue, :lightblue,:orange], [.4,.5]) # define color
heatmap(["S","E","I","R","L","H","B","C"],0.6:.01:.99,log10.(Errr[:,end:-1:1]'),
color=CoLor,colorbar_title="log10(RMSD)",clim=(RMSD1-.18,RMSD1+.21),
xlabel="Individual classes", ylabel="Order of derivative",fontfamily= plot_font,
title = "(f) Model 4", titleloc = :left, titlefont = font(10))
pltheat=plot!(Shape(0 .+ [1,2,2,1], 0 .+ [.595,.595,.995,.995]), fillcolor=:false, linecolor=:red,linestyle=:dot, legend=:false, w=3)
# plot heatmap model 3
pltheat1=heatmap(["S","E","I","R","L","H","B","C"],0.6:.01:.99,log10.(Err[:,end:-1:1]'),
color=CoLor,colorbar_title="log10(RMSD)",clim=(RMSD1-.18,RMSD1+.21),
xlabel="Individual classes", ylabel="Order of derivative",fontfamily= plot_font,
title = "(e) Model 3 ", titleloc = :left, titlefont = font(10), colorbar=:false)
# savefig(pltheat,"pltheat.svg")
# savefig(pltheat1,"pltheat1.svg")
tt, x= FDEsolver(F, [4,438], x0, ones(8), par, nc=2,h=.01)
S1=x[:,1]; E1=x[:,2]; I1=x[:,3]; R1=x[:,4];
L1=x[:,5]; H1=x[:,6]; B1=x[:,7]; C1=x[:,8];
N1=sum(x,dims=2)
μ3=mean([μ1 .+ μ2 .* N1, α1 .- α2 .*N1])
Appx11=@.I1+R1+L1+H1+B1+C1-μ3*(N1-S1-E1)
# rmsd(Appx1[1:10:end,:], Data2(4:.1:438))
#plot
plot()
Nn=30
err=zeros(Nn)
for i=1:Nn
α=ones(8)
t1, x1= FDEsolver(F, [4,280], x0, α, par, nc=2,h=.01)
x02=x1[end,:]
α[2]=1-i*.02
t2, x2= FDEsolver(F, [280,438], x02, α, par, nc=2,h=.01)
x=vcat(x1,x2[2:end,:])
ttt=vcat(t1,t2[2:end,:])
S1=x[:,1]; E1=x[:,2]; I1=x[:,3]; R1=x[:,4];
L1=x[:,5]; H1=x[:,6]; B1=x[:,7]; C1=x[:,8];
N1=sum(x,dims=2)
μ3=mean([μ1 .+ μ2 .* N1, α1 .- α2 .*N1])
Appx=@.I1+R1+L1+H1+B1+C1-μ3*(N1-S1-E1)
# err[i]=copy(rmsd(Appx[1:10:end,:], Data2(4:.1:438)))
plot!(ttt[28000:100:end],Appx[28000:100:end,:],lw=2; color="blue1")
end
scatter!(data[85:end,1],data[85:end,2], label="Real data", c="khaki3",markerstrokewidth=0)
pltFtry=plot!(tt[27000:50:end],Appx11[27000:50:end,:],xlabel="Days",
lw=2, c="deepskyblue1",label="Integer model",legend=:false,
ylabel=L"\textrm{Cumulative\;\;cases} \; (\mathrm{10^3})",fontfamily= plot_font,
yticks = (1000 .*[13,14,15],string.([13,14,15])),
title = "(d)", titleloc = :left, titlefont = font(10))
lab = @layout [a{0.7w, .4h} b; _ _ ; _ _]
lcd = @layout [_ _ ;a{.25h} b; _ _]
lef = @layout [_ _ ; _ _ ;a{.25h, .4w} b]
plot_ab=plot(plotModels, plotN, layout= lab, size = (900, 900))
plot_cd=plot(InitialFDE, pltFtry, layout= lcd, size = (900, 900))
plot_ef=plot(pltheat1, pltheat, layout= lef, size = (900, 900))
savefig(plot_ab,"plot_ab.svg")
savefig(plot_cd,"plot_cd.svg")
savefig(plot_ef,"plot_ef.svg")