COVID-19 Composition Model
using StockFlow
using Catlab
using Catlab.CategoricalAlgebra
using LabelledArrays
using OrdinaryDiffEq
using Plots
using Catlab.Graphics
using Catlab.Programs
using Catlab.WiringDiagrams
display_uwd(ex) = to_graphviz(ex, box_labels=:name, junction_labels=:variable, edge_attrs=Dict(:len=>"1"));
Define functions ϕ of flows in the SEIRH model
fNewIncidence(u,p,t)=p.β*u.S*u.I/p.N
fNewInfectious(u,p,t)=u.E*p.ri
fNewRecovery(u,p,t)=u.I/p.tr * (1.0-p.fH )
fWaningImmunityR(u,p,t)=u.R/p.tw
fHICUAdmission(u,p,t) = u.I/p.tr * p.fH * p.fICU
fHNICUAdmission(u,p,t) = u.I/p.tr * p.fH * (1.0-p.fICU)
fOutICU(u,p,t) = u.HICU/p.tICU
fRecoveryH(u,p,t)= u.HNICU/p.tH
fRecoveryH (generic function with 1 method)
StockAndFlowp(stocks, (flow=>function, upstream=>downstream) => stocks linked)
seirh = StockAndFlowp((:S, :E, :I, :R, :HICU, :HNICU),
((:NewIncidence=>fNewIncidence, :S=>:E) => (:S, :I),
(:NewInfectious=>fNewInfectious, :E=>:I) => :E,
(:NewRecovery=>fNewRecovery, :I=>:R) => :I,
(:WaningImmunityR=>fWaningImmunityR, :R=>:S) => :R,
(:HICUAdmission=>fHICUAdmission, :I=>:HICU) => :I,
(:HNICUAdmission=>fHNICUAdmission, :I=>:HNICU) => :I,
(:OutICU=>fOutICU, :HICU=>:HNICU) => :HICU,
(:RecoveryH=>fRecoveryH, :HNICU=>:R) => :HNICU))
Flow | u | d | fname | ϕf |
---|---|---|---|---|
1 | 1 | 2 | NewIncidence | fNewIncidence |
2 | 2 | 3 | NewInfectious | fNewInfectious |
3 | 3 | 4 | NewRecovery | fNewRecovery |
4 | 4 | 1 | WaningImmunityR | fWaningImmunityR |
5 | 3 | 5 | HICUAdmission | fHICUAdmission |
6 | 3 | 6 | HNICUAdmission | fHNICUAdmission |
7 | 5 | 6 | OutICU | fOutICU |
8 | 6 | 4 | RecoveryH | fRecoveryH |
Stock | sname |
---|---|
1 | S |
2 | E |
3 | I |
4 | R |
5 | HICU |
6 | HNICU |
Link | s | t |
---|---|---|
1 | 1 | 1 |
2 | 3 | 1 |
3 | 2 | 2 |
4 | 3 | 3 |
5 | 4 | 4 |
6 | 3 | 5 |
7 | 3 | 6 |
8 | 5 | 7 |
9 | 6 | 8 |
Graph(primitive stock-flow model, direction of the diagram - the default value is "LR" from left to right; users could also use "TB" from top to bottom) Graph(seirh)
Define functions ϕ of flows in the Vaccine model
fFirstdoseVaccine(u,p,t) = u.S * p.rv
fSeconddoseVaccine(u,p,t) = u.VP * p.rv
fWaningImmunityVP(u,p,t) = u.VP / p.tw
fWaningImmunityVF(u,p,t) = u.VF / p.tw
fNewIncidenceVP(u,p,t) = p.β*u.VP*u.I*(1.0-p.eP)/p.N
fNewIncidenceVF(u,p,t) = p.β*u.VF*u.I*(1.0-p.eF)/p.N
fNewIncidenceVF (generic function with 1 method)
Stock and flow diagram of Vaccine model
v = StockAndFlowp((:S, :E, :I, :VP, :VF),
((:FirstdoseVaccine=>fFirstdoseVaccine, :S=>:VP) => :S,
(:SeconddoseVaccine=>fSeconddoseVaccine, :VP=>:VF) => :VP,
(:WaningImmunityVP=>fWaningImmunityVP, :VP=>:S) => :VP,
(:WaningImmunityVF=>fWaningImmunityVF, :VF=>:VP) => :VF,
(:NewIncidenceVP=>fNewIncidenceVP, :VP=>:E) => (:VP, :I),
(:NewIncidenceVF=>fNewIncidenceVF, :VF=>:E) => (:VF, :I)))
Flow | u | d | fname | ϕf |
---|---|---|---|---|
1 | 1 | 4 | FirstdoseVaccine | fFirstdoseVaccine |
2 | 4 | 5 | SeconddoseVaccine | fSeconddoseVaccine |
3 | 4 | 1 | WaningImmunityVP | fWaningImmunityVP |
4 | 5 | 4 | WaningImmunityVF | fWaningImmunityVF |
5 | 4 | 2 | NewIncidenceVP | fNewIncidenceVP |
6 | 5 | 2 | NewIncidenceVF | fNewIncidenceVF |
Stock | sname |
---|---|
1 | S |
2 | E |
3 | I |
4 | VP |
5 | VF |
Link | s | t |
---|---|---|
1 | 1 | 1 |
2 | 4 | 2 |
3 | 4 | 3 |
4 | 5 | 4 |
5 | 4 | 5 |
6 | 3 | 5 |
7 | 5 | 6 |
8 | 3 | 6 |
Graph(v,"TB")
Define functions ϕ of flows in the Persist Asymptomaticity model
fNewPersistentAsymptomaticity(u,p,t) = u.E * p.ria
fNewRecoveryIA(u,p,t) = u.IA / p.tr
fNewRecoveryIA (generic function with 1 method)
Stock and flow diagram of Persistent Asymptomaticity Model
ia = StockAndFlowp((:E, :IA, :R),
((:NewPersistentAsymptomaticity=>fNewPersistentAsymptomaticity, :E=>:IA) => :E,
(:NewRecoveryIA=>fNewRecoveryIA, :IA=>:R) => :IA))
Flow | u | d | fname | ϕf |
---|---|---|---|---|
1 | 1 | 2 | NewPersistentAsymptomaticity | fNewPersistentAsymptomaticity |
2 | 2 | 3 | NewRecoveryIA | fNewRecoveryIA |
Stock | sname |
---|---|
1 | E |
2 | IA |
3 | R |
Link | s | t |
---|---|---|
1 | 1 | 1 |
2 | 2 | 2 |
Graph(ia)
covid = @relation (S, E, I, R) begin
modelA(S,E,I,R)
modelB(S,E,I)
modelC(E,R)
end;
display_uwd(covid)
Open three Stock and Flow Diagrams
openseirh = Open(seirh, [:S], [:E], [:I], [:R])
openv = Open(v, [:S], [:E], [:I])
openia = Open(ia, [:E], [:R])
Catlab.CategoricalAlgebra.StructuredCospans.StructuredCospan{Catlab.CategoricalAlgebra.StructuredCospans.DiscreteACSet{ACSets.DenseACSets.AnonACSet{ACSets.Schemas.TypeLevelBasicSchema{Symbol, Tuple{:Stock}, Tuple{}, Tuple{:Name, :FuncFlow}, Tuple{(:sname, :Stock, :Name)}, Tuple{}}, Tuple{Symbol, Function}, @NamedTuple{Stock::ACSets.DenseACSets.IntParts, Name::ACSets.DenseACSets.IntParts, FuncFlow::ACSets.DenseACSets.IntParts}, @NamedTuple{sname::ACSets.ColumnImplementations.DenseColumn{Union{ACSets.ColumnImplementations.AttrVar, Symbol}, Vector{Union{ACSets.ColumnImplementations.AttrVar, Symbol}}}}, ACSets.DenseACSets.IntParts}, StockAndFlowp}, Catlab.CategoricalAlgebra.FreeDiagrams.Multicospan{StockAndFlowp, Catlab.CategoricalAlgebra.CSets.StructTightACSetTransformation{ACSets.Schemas.TypeLevelBasicSchema{Symbol, Tuple{:Flow, :Stock, :Link}, Tuple{(:u, :Flow, :Stock), (:d, :Flow, :Stock), (:s, :Link, :Stock), (:t, :Link, :Flow)}, Tuple{:Name, :FuncFlow}, Tuple{(:sname, :Stock, :Name), (:fname, :Flow, :Name), (:ϕf, :Flow, :FuncFlow)}, Tuple{}}, @NamedTuple{Flow::Catlab.CategoricalAlgebra.FinSets.FinDomFunctionVector{Int64, Vector{Int64}, Catlab.CategoricalAlgebra.FinSets.FinSetInt}, Stock::Catlab.CategoricalAlgebra.FinSets.FinDomFunctionVector{Int64, Vector{Int64}, Catlab.CategoricalAlgebra.FinSets.FinSetInt}, Link::Catlab.CategoricalAlgebra.FinSets.FinDomFunctionVector{Int64, Vector{Int64}, Catlab.CategoricalAlgebra.FinSets.FinSetInt}, Name::Catlab.CategoricalAlgebra.FinSets.VarFunction{Symbol}, FuncFlow::Catlab.CategoricalAlgebra.FinSets.VarFunction{Function}}, StockAndFlowp, StockAndFlowp}, StaticArraysCore.SVector{2, Catlab.CategoricalAlgebra.CSets.StructTightACSetTransformation{ACSets.Schemas.TypeLevelBasicSchema{Symbol, Tuple{:Flow, :Stock, :Link}, Tuple{(:u, :Flow, :Stock), (:d, :Flow, :Stock), (:s, :Link, :Stock), (:t, :Link, :Flow)}, Tuple{:Name, :FuncFlow}, Tuple{(:sname, :Stock, :Name), (:fname, :Flow, :Name), (:ϕf, :Flow, :FuncFlow)}, Tuple{}}, @NamedTuple{Flow::Catlab.CategoricalAlgebra.FinSets.FinDomFunctionVector{Int64, Vector{Int64}, Catlab.CategoricalAlgebra.FinSets.FinSetInt}, Stock::Catlab.CategoricalAlgebra.FinSets.FinDomFunctionVector{Int64, Vector{Int64}, Catlab.CategoricalAlgebra.FinSets.FinSetInt}, Link::Catlab.CategoricalAlgebra.FinSets.FinDomFunctionVector{Int64, Vector{Int64}, Catlab.CategoricalAlgebra.FinSets.FinSetInt}, Name::Catlab.CategoricalAlgebra.FinSets.VarFunction{Symbol}, FuncFlow::Catlab.CategoricalAlgebra.FinSets.VarFunction{Function}}, StockAndFlowp, StockAndFlowp}}}, StaticArraysCore.SVector{2, ACSets.DenseACSets.AnonACSet{ACSets.Schemas.TypeLevelBasicSchema{Symbol, Tuple{:Stock}, Tuple{}, Tuple{:Name, :FuncFlow}, Tuple{(:sname, :Stock, :Name)}, Tuple{}}, Tuple{Symbol, Function}, @NamedTuple{Stock::ACSets.DenseACSets.IntParts, Name::ACSets.DenseACSets.IntParts, FuncFlow::ACSets.DenseACSets.IntParts}, @NamedTuple{sname::ACSets.ColumnImplementations.DenseColumn{Union{ACSets.ColumnImplementations.AttrVar, Symbol}, Vector{Union{ACSets.ColumnImplementations.AttrVar, Symbol}}}}, ACSets.DenseACSets.IntParts}}}(Catlab.CategoricalAlgebra.FreeDiagrams.Multicospan{StockAndFlowp, Catlab.CategoricalAlgebra.CSets.StructTightACSetTransformation{ACSets.Schemas.TypeLevelBasicSchema{Symbol, Tuple{:Flow, :Stock, :Link}, Tuple{(:u, :Flow, :Stock), (:d, :Flow, :Stock), (:s, :Link, :Stock), (:t, :Link, :Flow)}, Tuple{:Name, :FuncFlow}, Tuple{(:sname, :Stock, :Name), (:fname, :Flow, :Name), (:ϕf, :Flow, :FuncFlow)}, Tuple{}}, @NamedTuple{Flow::Catlab.CategoricalAlgebra.FinSets.FinDomFunctionVector{Int64, Vector{Int64}, Catlab.CategoricalAlgebra.FinSets.FinSetInt}, Stock::Catlab.CategoricalAlgebra.FinSets.FinDomFunctionVector{Int64, Vector{Int64}, Catlab.CategoricalAlgebra.FinSets.FinSetInt}, Link::Catlab.CategoricalAlgebra.FinSets.FinDomFunctionVector{Int64, Vector{Int64}, Catlab.CategoricalAlgebra.FinSets.FinSetInt}, Name::Catlab.CategoricalAlgebra.FinSets.VarFunction{Symbol}, FuncFlow::Catlab.CategoricalAlgebra.FinSets.VarFunction{Function}}, StockAndFlowp, StockAndFlowp}, StaticArraysCore.SVector{2, Catlab.CategoricalAlgebra.CSets.StructTightACSetTransformation{ACSets.Schemas.TypeLevelBasicSchema{Symbol, Tuple{:Flow, :Stock, :Link}, Tuple{(:u, :Flow, :Stock), (:d, :Flow, :Stock), (:s, :Link, :Stock), (:t, :Link, :Flow)}, Tuple{:Name, :FuncFlow}, Tuple{(:sname, :Stock, :Name), (:fname, :Flow, :Name), (:ϕf, :Flow, :FuncFlow)}, Tuple{}}, @NamedTuple{Flow::Catlab.CategoricalAlgebra.FinSets.FinDomFunctionVector{Int64, Vector{Int64}, Catlab.CategoricalAlgebra.FinSets.FinSetInt}, Stock::Catlab.CategoricalAlgebra.FinSets.FinDomFunctionVector{Int64, Vector{Int64}, Catlab.CategoricalAlgebra.FinSets.FinSetInt}, Link::Catlab.CategoricalAlgebra.FinSets.FinDomFunctionVector{Int64, Vector{Int64}, Catlab.CategoricalAlgebra.FinSets.FinSetInt}, Name::Catlab.CategoricalAlgebra.FinSets.VarFunction{Symbol}, FuncFlow::Catlab.CategoricalAlgebra.FinSets.VarFunction{Function}}, StockAndFlowp, StockAndFlowp}}}(StockAndFlowp:
Flow = 1:2
Stock = 1:3
Link = 1:2
Name = 1:0
FuncFlow = 1:0
u : Flow → Stock = [1, 2]
d : Flow → Stock = [2, 3]
s : Link → Stock = [1, 2]
t : Link → Flow = [1, 2]
sname : Stock → Name = [:E, :IA, :R]
fname : Flow → Name = [:NewPersistentAsymptomaticity, :NewRecoveryIA]
ϕf : Flow → FuncFlow = Function[Main.fNewPersistentAsymptomaticity, Main.fNewRecoveryIA], Catlab.CategoricalAlgebra.CSets.StructTightACSetTransformation{ACSets.Schemas.TypeLevelBasicSchema{Symbol, Tuple{:Flow, :Stock, :Link}, Tuple{(:u, :Flow, :Stock), (:d, :Flow, :Stock), (:s, :Link, :Stock), (:t, :Link, :Flow)}, Tuple{:Name, :FuncFlow}, Tuple{(:sname, :Stock, :Name), (:fname, :Flow, :Name), (:ϕf, :Flow, :FuncFlow)}, Tuple{}}, @NamedTuple{Flow::Catlab.CategoricalAlgebra.FinSets.FinDomFunctionVector{Int64, Vector{Int64}, Catlab.CategoricalAlgebra.FinSets.FinSetInt}, Stock::Catlab.CategoricalAlgebra.FinSets.FinDomFunctionVector{Int64, Vector{Int64}, Catlab.CategoricalAlgebra.FinSets.FinSetInt}, Link::Catlab.CategoricalAlgebra.FinSets.FinDomFunctionVector{Int64, Vector{Int64}, Catlab.CategoricalAlgebra.FinSets.FinSetInt}, Name::Catlab.CategoricalAlgebra.FinSets.VarFunction{Symbol}, FuncFlow::Catlab.CategoricalAlgebra.FinSets.VarFunction{Function}}, StockAndFlowp, StockAndFlowp}[ACSetTransformation((Flow = FinFunction(Int64[], 0, 2), Stock = FinFunction([1], 1, 3), Link = FinFunction(Int64[], 0, 2), Name = Catlab.CategoricalAlgebra.FinSets.VarFunction{Symbol}(FinDomFunction(Union{ACSets.ColumnImplementations.AttrVar, Symbol}[], FinSet(0), TypeSet(Union{ACSets.ColumnImplementations.AttrVar, Symbol})), FinSet(0)), FuncFlow = Catlab.CategoricalAlgebra.FinSets.VarFunction{Function}(FinDomFunction(Union{ACSets.ColumnImplementations.AttrVar, Function}[], FinSet(0), TypeSet(Union{ACSets.ColumnImplementations.AttrVar, Function})), FinSet(0))), StockAndFlowp {Flow:0, Stock:1, Link:0, Name:0, FuncFlow:0}, StockAndFlowp {Flow:2, Stock:3, Link:2, Name:0, FuncFlow:0}), ACSetTransformation((Flow = FinFunction(Int64[], 0, 2), Stock = FinFunction([3], 1, 3), Link = FinFunction(Int64[], 0, 2), Name = Catlab.CategoricalAlgebra.FinSets.VarFunction{Symbol}(FinDomFunction(Union{ACSets.ColumnImplementations.AttrVar, Symbol}[], FinSet(0), TypeSet(Union{ACSets.ColumnImplementations.AttrVar, Symbol})), FinSet(0)), FuncFlow = Catlab.CategoricalAlgebra.FinSets.VarFunction{Function}(FinDomFunction(Union{ACSets.ColumnImplementations.AttrVar, Function}[], FinSet(0), TypeSet(Union{ACSets.ColumnImplementations.AttrVar, Function})), FinSet(0))), StockAndFlowp {Flow:0, Stock:1, Link:0, Name:0, FuncFlow:0}, StockAndFlowp {Flow:2, Stock:3, Link:2, Name:0, FuncFlow:0})]), ACSets.DenseACSets.AnonACSet{ACSets.Schemas.TypeLevelBasicSchema{Symbol, Tuple{:Stock}, Tuple{}, Tuple{:Name, :FuncFlow}, Tuple{(:sname, :Stock, :Name)}, Tuple{}}, Tuple{Symbol, Function}, @NamedTuple{Stock::ACSets.DenseACSets.IntParts, Name::ACSets.DenseACSets.IntParts, FuncFlow::ACSets.DenseACSets.IntParts}, @NamedTuple{sname::ACSets.ColumnImplementations.DenseColumn{Union{ACSets.ColumnImplementations.AttrVar, Symbol}, Vector{Union{ACSets.ColumnImplementations.AttrVar, Symbol}}}}, ACSets.DenseACSets.IntParts}[ACSets.DenseACSets.AnonACSet{ACSets.Schemas.TypeLevelBasicSchema{Symbol, Tuple{:Stock}, Tuple{}, Tuple{:Name, :FuncFlow}, Tuple{(:sname, :Stock, :Name)}, Tuple{}}, Tuple{Symbol, Function}, @NamedTuple{Stock::ACSets.DenseACSets.IntParts, Name::ACSets.DenseACSets.IntParts, FuncFlow::ACSets.DenseACSets.IntParts}, @NamedTuple{sname::ACSets.ColumnImplementations.DenseColumn{Union{ACSets.ColumnImplementations.AttrVar, Symbol}, Vector{Union{ACSets.ColumnImplementations.AttrVar, Symbol}}}}, ACSets.DenseACSets.IntParts}:
Stock = 1:1
Name = 1:0
FuncFlow = 1:0
sname : Stock → Name = [:E], ACSets.DenseACSets.AnonACSet{ACSets.Schemas.TypeLevelBasicSchema{Symbol, Tuple{:Stock}, Tuple{}, Tuple{:Name, :FuncFlow}, Tuple{(:sname, :Stock, :Name)}, Tuple{}}, Tuple{Symbol, Function}, @NamedTuple{Stock::ACSets.DenseACSets.IntParts, Name::ACSets.DenseACSets.IntParts, FuncFlow::ACSets.DenseACSets.IntParts}, @NamedTuple{sname::ACSets.ColumnImplementations.DenseColumn{Union{ACSets.ColumnImplementations.AttrVar, Symbol}, Vector{Union{ACSets.ColumnImplementations.AttrVar, Symbol}}}}, ACSets.DenseACSets.IntParts}:
Stock = 1:1
Name = 1:0
FuncFlow = 1:0
sname : Stock → Name = [:R]])
Compose those three models according the UWD-algebra
openCOVID19 = oapply(covid, [openseirh, openv, openia])
Catlab.CategoricalAlgebra.StructuredCospans.StructuredMulticospan{Catlab.CategoricalAlgebra.StructuredCospans.DiscreteACSet{ACSets.DenseACSets.AnonACSet{ACSets.Schemas.TypeLevelBasicSchema{Symbol, Tuple{:Stock}, Tuple{}, Tuple{:Name, :FuncFlow}, Tuple{(:sname, :Stock, :Name)}, Tuple{}}, Tuple{Symbol, Function}, @NamedTuple{Stock::ACSets.DenseACSets.IntParts, Name::ACSets.DenseACSets.IntParts, FuncFlow::ACSets.DenseACSets.IntParts}, @NamedTuple{sname::ACSets.ColumnImplementations.DenseColumn{Union{ACSets.ColumnImplementations.AttrVar, Symbol}, Vector{Union{ACSets.ColumnImplementations.AttrVar, Symbol}}}}, ACSets.DenseACSets.IntParts}, StockAndFlowp}, Catlab.CategoricalAlgebra.FreeDiagrams.Multicospan{StockAndFlowp, Catlab.CategoricalAlgebra.CSets.StructTightACSetTransformation{ACSets.Schemas.TypeLevelBasicSchema{Symbol, Tuple{:Flow, :Stock, :Link}, Tuple{(:u, :Flow, :Stock), (:d, :Flow, :Stock), (:s, :Link, :Stock), (:t, :Link, :Flow)}, Tuple{:Name, :FuncFlow}, Tuple{(:sname, :Stock, :Name), (:fname, :Flow, :Name), (:ϕf, :Flow, :FuncFlow)}, Tuple{}}, @NamedTuple{Flow::Catlab.CategoricalAlgebra.FinSets.FinDomFunctionVector{Int64, Vector{Int64}, Catlab.CategoricalAlgebra.FinSets.FinSetInt}, Stock::Catlab.CategoricalAlgebra.FinSets.FinDomFunctionVector{Int64, Vector{Int64}, Catlab.CategoricalAlgebra.FinSets.FinSetInt}, Link::Catlab.CategoricalAlgebra.FinSets.FinDomFunctionVector{Int64, Vector{Int64}, Catlab.CategoricalAlgebra.FinSets.FinSetInt}, Name::Catlab.CategoricalAlgebra.FinSets.VarFunction{Symbol}, FuncFlow::Catlab.CategoricalAlgebra.FinSets.VarFunction{Function}}, StockAndFlowp, StockAndFlowp}, Vector{Catlab.CategoricalAlgebra.CSets.StructTightACSetTransformation{ACSets.Schemas.TypeLevelBasicSchema{Symbol, Tuple{:Flow, :Stock, :Link}, Tuple{(:u, :Flow, :Stock), (:d, :Flow, :Stock), (:s, :Link, :Stock), (:t, :Link, :Flow)}, Tuple{:Name, :FuncFlow}, Tuple{(:sname, :Stock, :Name), (:fname, :Flow, :Name), (:ϕf, :Flow, :FuncFlow)}, Tuple{}}, @NamedTuple{Flow::Catlab.CategoricalAlgebra.FinSets.FinDomFunctionVector{Int64, Vector{Int64}, Catlab.CategoricalAlgebra.FinSets.FinSetInt}, Stock::Catlab.CategoricalAlgebra.FinSets.FinDomFunctionVector{Int64, Vector{Int64}, Catlab.CategoricalAlgebra.FinSets.FinSetInt}, Link::Catlab.CategoricalAlgebra.FinSets.FinDomFunctionVector{Int64, Vector{Int64}, Catlab.CategoricalAlgebra.FinSets.FinSetInt}, Name::Catlab.CategoricalAlgebra.FinSets.VarFunction{Symbol}, FuncFlow::Catlab.CategoricalAlgebra.FinSets.VarFunction{Function}}, StockAndFlowp, StockAndFlowp}}}, Vector{Union{Nothing, ACSets.DenseACSets.AnonACSet{ACSets.Schemas.TypeLevelBasicSchema{Symbol, Tuple{:Stock}, Tuple{}, Tuple{:Name, :FuncFlow}, Tuple{(:sname, :Stock, :Name)}, Tuple{}}, Tuple{Symbol, Function}, @NamedTuple{Stock::ACSets.DenseACSets.IntParts, Name::ACSets.DenseACSets.IntParts, FuncFlow::ACSets.DenseACSets.IntParts}, @NamedTuple{sname::ACSets.ColumnImplementations.DenseColumn{Union{ACSets.ColumnImplementations.AttrVar, Symbol}, Vector{Union{ACSets.ColumnImplementations.AttrVar, Symbol}}}}, ACSets.DenseACSets.IntParts}}}}(Catlab.CategoricalAlgebra.FreeDiagrams.Multicospan{StockAndFlowp, Catlab.CategoricalAlgebra.CSets.StructTightACSetTransformation{ACSets.Schemas.TypeLevelBasicSchema{Symbol, Tuple{:Flow, :Stock, :Link}, Tuple{(:u, :Flow, :Stock), (:d, :Flow, :Stock), (:s, :Link, :Stock), (:t, :Link, :Flow)}, Tuple{:Name, :FuncFlow}, Tuple{(:sname, :Stock, :Name), (:fname, :Flow, :Name), (:ϕf, :Flow, :FuncFlow)}, Tuple{}}, @NamedTuple{Flow::Catlab.CategoricalAlgebra.FinSets.FinDomFunctionVector{Int64, Vector{Int64}, Catlab.CategoricalAlgebra.FinSets.FinSetInt}, Stock::Catlab.CategoricalAlgebra.FinSets.FinDomFunctionVector{Int64, Vector{Int64}, Catlab.CategoricalAlgebra.FinSets.FinSetInt}, Link::Catlab.CategoricalAlgebra.FinSets.FinDomFunctionVector{Int64, Vector{Int64}, Catlab.CategoricalAlgebra.FinSets.FinSetInt}, Name::Catlab.CategoricalAlgebra.FinSets.VarFunction{Symbol}, FuncFlow::Catlab.CategoricalAlgebra.FinSets.VarFunction{Function}}, StockAndFlowp, StockAndFlowp}, Vector{Catlab.CategoricalAlgebra.CSets.StructTightACSetTransformation{ACSets.Schemas.TypeLevelBasicSchema{Symbol, Tuple{:Flow, :Stock, :Link}, Tuple{(:u, :Flow, :Stock), (:d, :Flow, :Stock), (:s, :Link, :Stock), (:t, :Link, :Flow)}, Tuple{:Name, :FuncFlow}, Tuple{(:sname, :Stock, :Name), (:fname, :Flow, :Name), (:ϕf, :Flow, :FuncFlow)}, Tuple{}}, @NamedTuple{Flow::Catlab.CategoricalAlgebra.FinSets.FinDomFunctionVector{Int64, Vector{Int64}, Catlab.CategoricalAlgebra.FinSets.FinSetInt}, Stock::Catlab.CategoricalAlgebra.FinSets.FinDomFunctionVector{Int64, Vector{Int64}, Catlab.CategoricalAlgebra.FinSets.FinSetInt}, Link::Catlab.CategoricalAlgebra.FinSets.FinDomFunctionVector{Int64, Vector{Int64}, Catlab.CategoricalAlgebra.FinSets.FinSetInt}, Name::Catlab.CategoricalAlgebra.FinSets.VarFunction{Symbol}, FuncFlow::Catlab.CategoricalAlgebra.FinSets.VarFunction{Function}}, StockAndFlowp, StockAndFlowp}}}(StockAndFlowp:
Flow = 1:16
Stock = 1:9
Link = 1:19
Name = 1:0
FuncFlow = 1:0
u : Flow → Stock = [1, 2, 3, 4, 3, 3, 5, 6, 1, 7, 7, 8, 7, 8, 2, 9]
d : Flow → Stock = [2, 3, 4, 1, 5, 6, 6, 4, 7, 8, 1, 7, 2, 2, 9, 4]
s : Link → Stock = [1, 3, 2, 3, 4, 3, 3, 5, 6, 1, 7, 7, 8, 7, 3, 8, 3, 2, 9]
t : Link → Flow = [1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 13, 14, 14, 15, 16]
sname : Stock → Name = [:S, :E, :I, :R, :HICU, :HNICU, :VP, :VF, :IA]
fname : Flow → Name = [:NewIncidence, :NewInfectious, :NewRecovery, :WaningImmunityR, :HICUAdmission, :HNICUAdmission, :OutICU, :RecoveryH, :FirstdoseVaccine, :SeconddoseVaccine, :WaningImmunityVP, :WaningImmunityVF, :NewIncidenceVP, :NewIncidenceVF, :NewPersistentAsymptomaticity, :NewRecoveryIA]
ϕf : Flow → FuncFlow = Function[Main.fNewIncidence, Main.fNewInfectious, Main.fNewRecovery, Main.fWaningImmunityR, Main.fHICUAdmission, Main.fHNICUAdmission, Main.fOutICU, Main.fRecoveryH, Main.fFirstdoseVaccine, Main.fSeconddoseVaccine, Main.fWaningImmunityVP, Main.fWaningImmunityVF, Main.fNewIncidenceVP, Main.fNewIncidenceVF, Main.fNewPersistentAsymptomaticity, Main.fNewRecoveryIA], Catlab.CategoricalAlgebra.CSets.StructTightACSetTransformation{ACSets.Schemas.TypeLevelBasicSchema{Symbol, Tuple{:Flow, :Stock, :Link}, Tuple{(:u, :Flow, :Stock), (:d, :Flow, :Stock), (:s, :Link, :Stock), (:t, :Link, :Flow)}, Tuple{:Name, :FuncFlow}, Tuple{(:sname, :Stock, :Name), (:fname, :Flow, :Name), (:ϕf, :Flow, :FuncFlow)}, Tuple{}}, @NamedTuple{Flow::Catlab.CategoricalAlgebra.FinSets.FinDomFunctionVector{Int64, Vector{Int64}, Catlab.CategoricalAlgebra.FinSets.FinSetInt}, Stock::Catlab.CategoricalAlgebra.FinSets.FinDomFunctionVector{Int64, Vector{Int64}, Catlab.CategoricalAlgebra.FinSets.FinSetInt}, Link::Catlab.CategoricalAlgebra.FinSets.FinDomFunctionVector{Int64, Vector{Int64}, Catlab.CategoricalAlgebra.FinSets.FinSetInt}, Name::Catlab.CategoricalAlgebra.FinSets.VarFunction{Symbol}, FuncFlow::Catlab.CategoricalAlgebra.FinSets.VarFunction{Function}}, StockAndFlowp, StockAndFlowp}[ACSetTransformation((Flow = FinFunction(Int64[], 0, 16), Stock = FinFunction([1], 1, 9), Link = FinFunction(Int64[], 0, 19), Name = Catlab.CategoricalAlgebra.FinSets.VarFunction{Symbol}(FinDomFunction(Union{ACSets.ColumnImplementations.AttrVar, Symbol}[], FinSet(0), TypeSet(Union{ACSets.ColumnImplementations.AttrVar, Symbol})), FinSet(0)), FuncFlow = Catlab.CategoricalAlgebra.FinSets.VarFunction{Function}(FinDomFunction(Union{ACSets.ColumnImplementations.AttrVar, Function}[], FinSet(0), TypeSet(Union{ACSets.ColumnImplementations.AttrVar, Function})), FinSet(0))), StockAndFlowp {Flow:0, Stock:1, Link:0, Name:0, FuncFlow:0}, StockAndFlowp {Flow:16, Stock:9, Link:19, Name:0, FuncFlow:0}), ACSetTransformation((Flow = FinFunction(Int64[], 0, 16), Stock = FinFunction([2], 1, 9), Link = FinFunction(Int64[], 0, 19), Name = Catlab.CategoricalAlgebra.FinSets.VarFunction{Symbol}(FinDomFunction(Union{ACSets.ColumnImplementations.AttrVar, Symbol}[], FinSet(0), TypeSet(Union{ACSets.ColumnImplementations.AttrVar, Symbol})), FinSet(0)), FuncFlow = Catlab.CategoricalAlgebra.FinSets.VarFunction{Function}(FinDomFunction(Union{ACSets.ColumnImplementations.AttrVar, Function}[], FinSet(0), TypeSet(Union{ACSets.ColumnImplementations.AttrVar, Function})), FinSet(0))), StockAndFlowp {Flow:0, Stock:1, Link:0, Name:0, FuncFlow:0}, StockAndFlowp {Flow:16, Stock:9, Link:19, Name:0, FuncFlow:0}), ACSetTransformation((Flow = FinFunction(Int64[], 0, 16), Stock = FinFunction([3], 1, 9), Link = FinFunction(Int64[], 0, 19), Name = Catlab.CategoricalAlgebra.FinSets.VarFunction{Symbol}(FinDomFunction(Union{ACSets.ColumnImplementations.AttrVar, Symbol}[], FinSet(0), TypeSet(Union{ACSets.ColumnImplementations.AttrVar, Symbol})), FinSet(0)), FuncFlow = Catlab.CategoricalAlgebra.FinSets.VarFunction{Function}(FinDomFunction(Union{ACSets.ColumnImplementations.AttrVar, Function}[], FinSet(0), TypeSet(Union{ACSets.ColumnImplementations.AttrVar, Function})), FinSet(0))), StockAndFlowp {Flow:0, Stock:1, Link:0, Name:0, FuncFlow:0}, StockAndFlowp {Flow:16, Stock:9, Link:19, Name:0, FuncFlow:0}), ACSetTransformation((Flow = FinFunction(Int64[], 0, 16), Stock = FinFunction([4], 1, 9), Link = FinFunction(Int64[], 0, 19), Name = Catlab.CategoricalAlgebra.FinSets.VarFunction{Symbol}(FinDomFunction(Union{ACSets.ColumnImplementations.AttrVar, Symbol}[], FinSet(0), TypeSet(Union{ACSets.ColumnImplementations.AttrVar, Symbol})), FinSet(0)), FuncFlow = Catlab.CategoricalAlgebra.FinSets.VarFunction{Function}(FinDomFunction(Union{ACSets.ColumnImplementations.AttrVar, Function}[], FinSet(0), TypeSet(Union{ACSets.ColumnImplementations.AttrVar, Function})), FinSet(0))), StockAndFlowp {Flow:0, Stock:1, Link:0, Name:0, FuncFlow:0}, StockAndFlowp {Flow:16, Stock:9, Link:19, Name:0, FuncFlow:0})]), Union{Nothing, ACSets.DenseACSets.AnonACSet{ACSets.Schemas.TypeLevelBasicSchema{Symbol, Tuple{:Stock}, Tuple{}, Tuple{:Name, :FuncFlow}, Tuple{(:sname, :Stock, :Name)}, Tuple{}}, Tuple{Symbol, Function}, @NamedTuple{Stock::ACSets.DenseACSets.IntParts, Name::ACSets.DenseACSets.IntParts, FuncFlow::ACSets.DenseACSets.IntParts}, @NamedTuple{sname::ACSets.ColumnImplementations.DenseColumn{Union{ACSets.ColumnImplementations.AttrVar, Symbol}, Vector{Union{ACSets.ColumnImplementations.AttrVar, Symbol}}}}, ACSets.DenseACSets.IntParts}}[ACSets.DenseACSets.AnonACSet{ACSets.Schemas.TypeLevelBasicSchema{Symbol, Tuple{:Stock}, Tuple{}, Tuple{:Name, :FuncFlow}, Tuple{(:sname, :Stock, :Name)}, Tuple{}}, Tuple{Symbol, Function}, @NamedTuple{Stock::ACSets.DenseACSets.IntParts, Name::ACSets.DenseACSets.IntParts, FuncFlow::ACSets.DenseACSets.IntParts}, @NamedTuple{sname::ACSets.ColumnImplementations.DenseColumn{Union{ACSets.ColumnImplementations.AttrVar, Symbol}, Vector{Union{ACSets.ColumnImplementations.AttrVar, Symbol}}}}, ACSets.DenseACSets.IntParts}:
Stock = 1:1
Name = 1:0
FuncFlow = 1:0
sname : Stock → Name = [:S], ACSets.DenseACSets.AnonACSet{ACSets.Schemas.TypeLevelBasicSchema{Symbol, Tuple{:Stock}, Tuple{}, Tuple{:Name, :FuncFlow}, Tuple{(:sname, :Stock, :Name)}, Tuple{}}, Tuple{Symbol, Function}, @NamedTuple{Stock::ACSets.DenseACSets.IntParts, Name::ACSets.DenseACSets.IntParts, FuncFlow::ACSets.DenseACSets.IntParts}, @NamedTuple{sname::ACSets.ColumnImplementations.DenseColumn{Union{ACSets.ColumnImplementations.AttrVar, Symbol}, Vector{Union{ACSets.ColumnImplementations.AttrVar, Symbol}}}}, ACSets.DenseACSets.IntParts}:
Stock = 1:1
Name = 1:0
FuncFlow = 1:0
sname : Stock → Name = [:E], ACSets.DenseACSets.AnonACSet{ACSets.Schemas.TypeLevelBasicSchema{Symbol, Tuple{:Stock}, Tuple{}, Tuple{:Name, :FuncFlow}, Tuple{(:sname, :Stock, :Name)}, Tuple{}}, Tuple{Symbol, Function}, @NamedTuple{Stock::ACSets.DenseACSets.IntParts, Name::ACSets.DenseACSets.IntParts, FuncFlow::ACSets.DenseACSets.IntParts}, @NamedTuple{sname::ACSets.ColumnImplementations.DenseColumn{Union{ACSets.ColumnImplementations.AttrVar, Symbol}, Vector{Union{ACSets.ColumnImplementations.AttrVar, Symbol}}}}, ACSets.DenseACSets.IntParts}:
Stock = 1:1
Name = 1:0
FuncFlow = 1:0
sname : Stock → Name = [:I], ACSets.DenseACSets.AnonACSet{ACSets.Schemas.TypeLevelBasicSchema{Symbol, Tuple{:Stock}, Tuple{}, Tuple{:Name, :FuncFlow}, Tuple{(:sname, :Stock, :Name)}, Tuple{}}, Tuple{Symbol, Function}, @NamedTuple{Stock::ACSets.DenseACSets.IntParts, Name::ACSets.DenseACSets.IntParts, FuncFlow::ACSets.DenseACSets.IntParts}, @NamedTuple{sname::ACSets.ColumnImplementations.DenseColumn{Union{ACSets.ColumnImplementations.AttrVar, Symbol}, Vector{Union{ACSets.ColumnImplementations.AttrVar, Symbol}}}}, ACSets.DenseACSets.IntParts}:
Stock = 1:1
Name = 1:0
FuncFlow = 1:0
sname : Stock → Name = [:R]])
Generate the composed model (Stock and Flow Diagram)
COVID19 = apex(openCOVID19)
Flow | u | d | fname | ϕf |
---|---|---|---|---|
1 | 1 | 2 | NewIncidence | fNewIncidence |
2 | 2 | 3 | NewInfectious | fNewInfectious |
3 | 3 | 4 | NewRecovery | fNewRecovery |
4 | 4 | 1 | WaningImmunityR | fWaningImmunityR |
5 | 3 | 5 | HICUAdmission | fHICUAdmission |
6 | 3 | 6 | HNICUAdmission | fHNICUAdmission |
7 | 5 | 6 | OutICU | fOutICU |
8 | 6 | 4 | RecoveryH | fRecoveryH |
9 | 1 | 7 | FirstdoseVaccine | fFirstdoseVaccine |
10 | 7 | 8 | SeconddoseVaccine | fSeconddoseVaccine |
11 | 7 | 1 | WaningImmunityVP | fWaningImmunityVP |
12 | 8 | 7 | WaningImmunityVF | fWaningImmunityVF |
13 | 7 | 2 | NewIncidenceVP | fNewIncidenceVP |
14 | 8 | 2 | NewIncidenceVF | fNewIncidenceVF |
15 | 2 | 9 | NewPersistentAsymptomaticity | fNewPersistentAsymptomaticity |
16 | 9 | 4 | NewRecoveryIA | fNewRecoveryIA |
Stock | sname |
---|---|
1 | S |
2 | E |
3 | I |
4 | R |
5 | HICU |
6 | HNICU |
7 | VP |
8 | VF |
9 | IA |
Link | s | t |
---|---|---|
1 | 1 | 1 |
2 | 3 | 1 |
3 | 2 | 2 |
4 | 3 | 3 |
5 | 4 | 4 |
6 | 3 | 5 |
7 | 3 | 6 |
8 | 5 | 7 |
9 | 6 | 8 |
10 | 1 | 9 |
11 | 7 | 10 |
12 | 7 | 11 |
13 | 8 | 12 |
14 | 7 | 13 |
15 | 3 | 13 |
16 | 8 | 14 |
17 | 3 | 14 |
18 | 2 | 15 |
19 | 9 | 16 |
Graph(COVID19)
Define constant parameters
p_COVID19 = LVector(
β=0.8, N=38010001.0, tr=12.22, tw=2*365.0,
fH=0.002, fICU=0.23, tICU=6.0, tH = 12.0,
rv=0.01, eP=0.6, eF=0.85, ri=0.207, ria=0.138
)
13-element LabelledArrays.LArray{Float64, 1, Vector{Float64}, (:β, :N, :tr, :tw, :fH, :fICU, :tICU, :tH, :rv, :eP, :eF, :ri, :ria)}:
:β => 0.8
:N => 3.8010001e7
:tr => 12.22
:tw => 730.0
:fH => 0.002
:fICU => 0.23
⋮
:rv => 0.01
:eP => 0.6
:eF => 0.85
:ri => 0.207
:ria => 0.138
Define initial values for stocks
u0_COVID19 = LVector(
S=38010000.0, E=0.0, I=1.0, IA=0.0, R=0.0, HICU=0.0, HNICU=0.0, VP=0.0, VF=0.0
)
9-element LabelledArrays.LArray{Float64, 1, Vector{Float64}, (:S, :E, :I, :IA, :R, :HICU, :HNICU, :VP, :VF)}:
:S => 3.801e7
:E => 0.0
:I => 1.0
:IA => 0.0
:R => 0.0
:HICU => 0.0
:HNICU => 0.0
:VP => 0.0
:VF => 0.0
Check the dependencies of links of all flows' functions checkfls(COVID19, u0COVID19, pCOVID19)
Solve the ODEs
prob_COVID19 = ODEProblem(vectorfield(COVID19),u0_COVID19,(0.0,300.0),p_COVID19);
sol_COVID19 = solve(prob_COVID19,Tsit5(),abstol=1e-8);
plot(sol_COVID19)
Flow of FirstdoseVaccine
ϕFirstdoseVaccine = map(x->fFirstdoseVaccine(sol_COVID19.u[x],p_COVID19,sol_COVID19.t[x]),collect(1:length(sol_COVID19.t)))
73-element Vector{Float64}:
380100.0
380099.9999998586
380099.9999984444
380099.9999843023
380099.99984288134
380099.9984286719
380099.98428657756
380099.84286566736
380098.4286598555
380084.28693077463
⋮
24993.702422388375
25975.606336685047
26896.203059104606
27755.494973309615
28553.8809027126
29292.127379132937
29971.341951615042
30592.94630595571
30842.079132188224