SEIR Full Model Measles Chickenpox

using StockFlow
using StockFlow.Syntax

using Catlab
using Catlab.CategoricalAlgebra
using LabelledArrays
using OrdinaryDiffEq
using Plots

using Catlab.Graphics
using Catlab.Programs
using Catlab.Theories
using Catlab.WiringDiagrams

seir = @stock_and_flow begin
    :stocks
    S
    E
    I
    R

    :parameters
    μ
    β
    tlatent
    trecovery
    δ

    :flows
    CLOUD => fbirth(μ * N) => S
    S => fincid(β * S * I / N) => E
    S => fdeathS(S * δ) => CLOUD
    E => finf(E / tlatent) => I
    E => fdeathE(E * δ) => CLOUD
    I => frec(I / trecovery) => R
    I => fdeathI(I * δ) => CLOUD
    R => fdeathR(R * δ) => CLOUD

    :sums
    N = [S, E, I, R]

end



GraphF(seir)
Example block output

define parameter values and initial values of stocks define constant parameters

p_measles = LVector(
    β=49.598, μ=0.03/12, δ=0.03/12, tlatent=8.0/30, trecovery=5.0/30
)
5-element LabelledArrays.LArray{Float64, 1, Vector{Float64}, (:β, :μ, :δ, :tlatent, :trecovery)}:
         :β => 49.598
         :μ => 0.0025
         :δ => 0.0025
   :tlatent => 0.26666666666666666
 :trecovery => 0.16666666666666666

define initial values for stocks

u0_measles = LVector(
    S=90000.0-930.0, E=0.0, I=930.0, R=773545.0
)
4-element LabelledArrays.LArray{Float64, 1, Vector{Float64}, (:S, :E, :I, :R)}:
 :S => 89070.0
 :E => 0.0
 :I => 930.0
 :R => 773545.0

solve the ODEs The model results are compared with the same model built by Anylogic, and the resules are the same!

prob_measles = ODEProblem(vectorfield(seir),u0_measles,(0.0,120.0),p_measles);
sol_measles = solve(prob_measles,Tsit5(),abstol=1e-8);
plot(sol_measles)
Example block output

define parameter values and initial values of stocks define constant parameters

p_chickenpox = LVector(
    β=18.0, μ=0.03/12.0, δ=0.03/12.0, tlatent=14.0/30.0, trecovery=5.0/30.0
)
5-element LabelledArrays.LArray{Float64, 1, Vector{Float64}, (:β, :μ, :δ, :tlatent, :trecovery)}:
         :β => 18.0
         :μ => 0.0025
         :δ => 0.0025
   :tlatent => 0.4666666666666667
 :trecovery => 0.16666666666666666

define initial values for stocks

u0_chickenpox = LVector(
    S=295354.0, E=0.0, I=1000.0, R=567191.0
)
4-element LabelledArrays.LArray{Float64, 1, Vector{Float64}, (:S, :E, :I, :R)}:
 :S => 295354.0
 :E => 0.0
 :I => 1000.0
 :R => 567191.0

solve the ODEs The model results are compared with the same model built by Anylogic, and the resules are the same!

prob_chickenpox = ODEProblem(vectorfield(seir),u0_chickenpox,(0.0,120.0),p_chickenpox);
sol_chickenpox = solve(prob_chickenpox,Tsit5(),abstol=1e-8);
plot(sol_chickenpox)

sol_chickenpox
retcode: Success
Interpolation: specialized 4th order "free" interpolation
t: 298-element Vector{Float64}:
   0.0
   2.8133919327141074e-9
   3.0947311259855185e-8
   3.122865045312659e-7
   3.125678437245373e-6
   3.1259597764386445e-5
   0.00031259879103579717
   0.003125990723749904
   0.015721220859647802
   0.0402686382370387
   ⋮
 116.95057564373138
 117.38101313036569
 117.8114308040953
 118.24182868879613
 118.67220674930125
 119.10256504883901
 119.53290362111201
 119.96322253589013
 120.0
u: 298-element Vector{LabelledArrays.LArray{Float64, 1, Vector{Float64}, (:S, :E, :I, :R)}}:
 4-element LabelledArrays.LArray{Float64, 1, Vector{Float64}, (:S, :E, :I, :R)}:
 :S => 295354.0
 :E => 0.0
 :I => 1000.0
 :R => 567191.0
 4-element LabelledArrays.LArray{Float64, 1, Vector{Float64}, (:S, :E, :I, :R)}:
 :S => 295353.99998667586
 :E => 1.7320507818745795e-5
 :I => 999.9999831126152
 :R => 567191.000012891
 4-element LabelledArrays.LArray{Float64, 1, Vector{Float64}, (:S, :E, :I, :R)}:
 :S => 295353.9998534344
 :E => 0.00019052556412603002
 :I => 999.9998142387877
 :R => 567191.0001418012
 4-element LabelledArrays.LArray{Float64, 1, Vector{Float64}, (:S, :E, :I, :R)}:
 :S => 295353.9985210214
 :E => 0.001922573939183367
 :I => 999.9981255026566
 :R => 567191.0014309019
 4-element LabelledArrays.LArray{Float64, 1, Vector{Float64}, (:S, :E, :I, :R)}:
 :S => 295353.9851970526
 :E => 0.01924283889007708
 :I => 999.9812383556265
 :R => 567191.0143217528
 4-element LabelledArrays.LArray{Float64, 1, Vector{Float64}, (:S, :E, :I, :R)}:
 :S => 295353.8519734983
 :E => 0.19242361030166427
 :I => 999.8123883115076
 :R => 567191.1432145798
 4-element LabelledArrays.LArray{Float64, 1, Vector{Float64}, (:S, :E, :I, :R)}:
 :S => 295352.5213499726
 :E => 1.9220453840944718
 :I => 998.126028662952
 :R => 567192.4305759802
 4-element LabelledArrays.LArray{Float64, 1, Vector{Float64}, (:S, :E, :I, :R)}:
 :S => 295339.3749437633
 :E => 19.00152652208452
 :I => 981.4746974066799
 :R => 567205.1488323078
 4-element LabelledArrays.LArray{Float64, 1, Vector{Float64}, (:S, :E, :I, :R)}:
 :S => 295283.93378379947
 :E => 90.83469669925346
 :I => 911.4633094359704
 :R => 567258.7682100652
 4-element LabelledArrays.LArray{Float64, 1, Vector{Float64}, (:S, :E, :I, :R)}:
 :S => 295190.27825876465
 :E => 211.30502471125422
 :I => 794.1479123400997
 :R => 567349.2688041839
 ⋮
 4-element LabelledArrays.LArray{Float64, 1, Vector{Float64}, (:S, :E, :I, :R)}:
 :S => 287359.58047330513
 :E => 501.7078206056262
 :I => 179.38966265603602
 :R => 575504.3220434324
 4-element LabelledArrays.LArray{Float64, 1, Vector{Float64}, (:S, :E, :I, :R)}:
 :S => 287517.62915460387
 :E => 500.7023967333541
 :I => 179.00426282424908
 :R => 575347.6641858377
 4-element LabelledArrays.LArray{Float64, 1, Vector{Float64}, (:S, :E, :I, :R)}:
 :S => 287676.1525227449
 :E => 499.88597370302176
 :I => 178.6864532181454
 :R => 575190.2750503331
 4-element LabelledArrays.LArray{Float64, 1, Vector{Float64}, (:S, :E, :I, :R)}:
 :S => 287834.9763514102
 :E => 499.2580115202814
 :I => 178.43604046487437
 :R => 575032.3295966039
 4-element LabelledArrays.LArray{Float64, 1, Vector{Float64}, (:S, :E, :I, :R)}:
 :S => 287993.9270936052
 :E => 498.81797639206746
 :I => 178.2528329473465
 :R => 574874.0020970546
 4-element LabelledArrays.LArray{Float64, 1, Vector{Float64}, (:S, :E, :I, :R)}:
 :S => 288152.83193100855
 :E => 498.5653419832703
 :I => 178.13664163032323
 :R => 574715.4660853771
 4-element LabelledArrays.LArray{Float64, 1, Vector{Float64}, (:S, :E, :I, :R)}:
 :S => 288311.5187172552
 :E => 498.49959066292024
 :I => 178.08728039493982
 :R => 574556.8944116862
 4-element LabelledArrays.LArray{Float64, 1, Vector{Float64}, (:S, :E, :I, :R)}:
 :S => 288469.8159930441
 :E => 498.62021349996184
 :I => 178.1045662542325
 :R => 574398.459227201
 4-element LabelledArrays.LArray{Float64, 1, Vector{Float64}, (:S, :E, :I, :R)}:
 :S => 288483.30486352724
 :E => 498.66202337213224
 :I => 178.0863051025161
 :R => 574384.9468079974

to have the figures plotted fix to the wider of the cells

HTML("""
<style>
.output_svg div{
  width: 100% !important;
  height: 100% !important;
}
</style>
""")