Making Graphs over System Dynamics Models
Introduction
Introduction
In this document we give usage examples for the functions of the package, "SystemDynamicsModelGraph.m", [AAp1]. The package provides functions for making dependency graphs for the stocks in System Dynamics (SD) models. The primary motivation for creating the functions in this package is to have the ability to introspect, proofread, and verify the (typical) ODE models made in SD.
A more detailed explanation is:
◼
For a given SD system of Ordinary Differential Equations (ODEs) we make Mathematica graph objects that represent the interaction of variable dependent functions in .
S
S
◼
Those graph objects give alternative (and hopefully convenient) way of visualizing the model of .
S
Load packages
Load packages
The following commands load the packages [AAp1, AAp2, AAp3]:
In[]:=
Import["https://raw.githubusercontent.com/antononcube/SystemModeling/master/WL/SystemDynamicsModelGraph.m"]Import["https://raw.githubusercontent.com/antononcube/SystemModeling/master/Projects/Coronavirus-propagation-dynamics/WL/EpidemiologyModels.m"]Import["https://raw.githubusercontent.com/antononcube/MathematicaForPrediction/master/Misc/CallGraph.m"]
Usage examples
Usage examples
Equations
Equations
In[]:=
lsEqs={Derivative[1][SP][t]-((IP[t]SP[t]β[IP])/TP[t])-SP[t]μ[TP],Derivative[1][EP][t](IP[t]SP[t]β[IP])/TP[t]-EP[t](1/aincp+μ[TP]),Derivative[1][IP][t]EP[t]/aincp-IP[t]/aip-IP[t]μ[IP],Derivative[1][RP][t]IP[t]/aip-RP[t]μ[TP],TP[t]Max[0,EP[t]+IP[t]+RP[t]+SP[t]]};ResourceFunction["GridTableForm"][List/@lsEqs,TableHeadings{"Equations"}]
Out[]=
# | Equations |
1 | ′ SP IP[t]SP[t]β[IP] TP[t] |
2 | ′ EP IP[t]SP[t]β[IP] TP[t] 1 aincp |
3 | ′ IP EP[t] aincp IP[t] aip |
4 | ′ RP IP[t] aip |
5 | TP[t]Max[0,EP[t]+IP[t]+RP[t]+SP[t]] |
Model graph
Model graph
Here is a graph of the dependencies between the populations:
In[]:=
ModelDependencyGraph[lsEqs,{EP,IP,RP,SP,TP},t]
Out[]=
When the second argument given to ModelDependencyGraph is Automatic the stocks in the equations are heuristically found with the function ModelHeuristicStocks:
In[]:=
ModelHeuristicStocks[lsEqs,t]
Out[]=
{EP,IP,RP,SP,TP}
Also, the function ModelDependencyGraph takes all options of Graph:
In[]:=
ModelDependencyGraph[lsEqs,Automatic,t,GraphLayout"GravityEmbedding",VertexLabels"Name",VertexLabelStyleDirective[Red,Bold,16],EdgeLabelStyleDirective[Blue,16],ImageSizeLarge]
Out[]=
Dependencies only
Dependencies only
The dependencies in the model can be found with the function ModelDependencyGraphEdges:
In[]:=
lsEdges=ModelDependencyGraphEdges[lsEqs,Automatic,t]
Out[]=
EPEP,IPEP,SPEP,EPIP,IPIP,IPIP,IPRP,RPRP,IPSP,SPSP,SPSP,EPTP,IPTP,RPTP,SPTP
--μ[TP]
1
aincp
SP[t]β[IP]
TP[t]
IP[t]β[IP]
TP[t]
1
aincp
-
1
aip
-μ[IP]
1
aip
-μ[TP]
-
SP[t]β[IP]
TP[t]
-
IP[t]β[IP]
TP[t]
-μ[TP]
1
1
1
1
In[]:=
lsEdges〚4〛//FullForm
Out[]//FullForm=
DirectedEdge[EP,IP,Power[aincp,-1]]
Focus stocks
Focus stocks
Here is a graph for a set of “focus” stocks-sources to a set of “focus” stocks-destinations:
In[]:=
gr=ModelDependencyGraph[lsEqs,{IP,SP},{EP},t]
Out[]=
Compare with the graph in which the argument positions of sources and destinations of the previous command are swapped:
In[]:=
ModelDependencyGraph[lsEqs,{EP},{IP,SP},t]
Out[]=
Additional interfacing
Additional interfacing
Here is a model from [AAp2]:
Here we make the corresponding graph:
Generating equations from graph specifications
Generating equations from graph specifications
A related, dual, or inverse task to the generation of graphs from systems of ODEs is the generation of system of ODEs from graphs.
Here is a model specifications through graph edges (using DirectedEdge):
Here is the corresponding graph:
Here we generate the system of ODEs using the function ModelGraphEquations:
Remark: ModelGraphEquations works with both graph and list of edges as a first argument.
Here we replace the symbolically represented rates with concrete values:
Here we solve the system of ODEs:
Here we plot the results:
Call graph
Call graph
The functionalities provided by the presented package "SystemDynamicsModelGraph.m", [AAp1], resemble in spirit those of the package "CallGraph.m”, [AAp3].
Here is call graph for the functions in the package [AAp1] made with the function CallGraph from the package [AAp3]:
References
References
Packages
Packages
[AAp1] Anton Antonov, "System Dynamics Model Graph Mathematica package", (2020), SystemsModeling at GitHub/antononcube.
[AAp2] Anton Antonov, "Epidemiology models Mathematica package", (2020), SystemsModeling at GitHub/antononcube.
[AAp3] Anton Antonov, "Call graph generation for context functions Mathematica package", (2018), MathematicaForPrediction at GitHub/antononcube.
Articles
Articles
[AA1] Anton Antonov, "Call graph generation for context functions", (2019), MathematicaForPrediction at WordPress.