-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathepidemiological.html
220 lines (173 loc) · 7.88 KB
/
epidemiological.html
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
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Applet Epidemics SIR</title>
<!--MATHJAX typing maths like in latex-->
<script type="text/x-mathjax-config">
MathJax.Hub.Config({tex2jax: {inlineMath: [['$','$'], ['\\(','\\)']]}});
</script>
<script type="text/javascript" async
src="https://cdn.rawgit.com/mathjax/MathJax/2.7.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
</script>
<!-- MATHJAX-->
<!-- jQuery -->
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<!-- Bootstrap -->
<link href="css/bootstrap.min.css" rel="stylesheet">
<!-- JSXgraph -->
<script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/jsxgraph/0.99.3/jsxgraphcore.js"></script>
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<!-- style for JSXgraph -->
<style>
.jxgbox {
width:400px;
height:300px;
}
@media screen and (min-width: 800px) {
.jxgbox {
width:800px;
height:600px;
}
}
</style>
<!--<body style="padding-top: 50px;">-->
<body>
<nav class="navbar navbar-default navbar-static-top" role="navigation" style="margin-bottom: 0px;">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<div id="navbar" class="collapse navbar-collapse">
<ul class="nav navbar-nav">
<li><a href="index.html" class="active">Home</a></li>
</ul>
</div><!--/.nav-collapse -->
</div>
</nav>
<div class="container-fluid">
<div class="row">
<!--CONTENT HERE-->
<div class="col-xs-12 col-sm-12 col-md-12" id="applet">
<h3>Applet SIR model</h3>
<div id="epidemicsboxtime" class="jxgbox" ></div>
</div>
<div class="col-xs-12 col-sm-12 col-md-12">
<h2>SIR model</h2>
<p>The SIR (Susceptible-Infected-Removed) model is</p>
$$\dot S = - \frac{\beta I S}{N},$$
$$\dot I = \frac{\beta I S}{N} - \gamma I,$$
$$\dot R = \gamma I.$$
<p>Parameter $\beta$ is the infection rate, $\gamma$ is the recovery rate. The basic reproduction
number $R_0 = \beta/\gamma$.</p>
</div>
</div><!--row-->
</div><!--container-fluid-->
<script>
// Initialise boardtime
boardtime = JXG.JSXGraph.initBoard('epidemicsboxtime', {boundingbox: [-0.5, 1.5, 365.0, -0.5], axis: true, grid: false, showCopyright: false});
// Define sliders to dynamically change parameters of the equations and create text elements to describe them
betaslider = boardtime.createElement('slider', [[20.0,1.4],[120.0,1.4],[0.00,0.08,0.5]],{name:'beta',strokeColor:'black',fillColor:'black'});
betatext = boardtime.createElement('text', [20,1.32, "infection rate"], {fixed:true});
recoveryslider = boardtime.createElement('slider', [[20.0,1.2],[120.0,1.2],[0.0,0.03,0.2]],{name:'gamma',strokeColor:'black',fillColor:'black'});
recoverytext = boardtime.createElement('text', [20,1.12, "recovery rate"], {fixed:true});
onsetslider = boardtime.createElement('slider', [[200.0,1.4],[300.0,1.4],[0.00,14,100]],{name:'start',strokeColor:'black',fillColor:'black'});
onsettext = boardtime.createElement('text', [200,1.32, "start of measures"], {fixed:true});
durationslider = boardtime.createElement('slider', [[200.0,1.2],[300.0,1.2],[0.0,14,90]],{name:'duration',strokeColor:'black',fillColor:'black'});
durationtext = boardtime.createElement('text', [200,1.12, "duration of measures"], {fixed:true});
// Dynamic initial value as gliders on the y-axis
startI = boardtime.createElement('glider', [0, 0.01, boardtime.defaultAxes.y], {name:'I',strokeColor:'green',fillColor:'green'});
startR = boardtime.createElement('glider', [0, 0.00, boardtime.defaultAxes.y], {name:'R',strokeColor:'red',fillColor:'red'});
// Variables for the JXG.Curves
var g1 = null;
var g2 = null;
var gt1 = null;
// Initialise ODE and solve it with JXG.Math.Numerics.rungeKutta()
function ode() {
// evaluation interval
var tspan = [0, 365];
var N = 365; // number of steps
// Right hand side of the ODE dx/dt = f(t, x)
var f = function(t, xx) {
var measures_on = (t >= onsetslider.Value()) * (t < (onsetslider.Value() + durationslider.Value() ));
var beta = betaslider.Value() * ( 1 - 0.5 * measures_on);
var gamma = recoveryslider.Value();
var POP = 1;
var dxdt = [];
dxdt[0] = - beta * xx[1] * xx[0] / POP;
dxdt[1] = beta * xx[1] * xx[0] / POP - gamma * xx[1];
dxdt[2] = gamma * xx[1];
return dxdt;
}
// Initial value
var x0 = [1.0 - startI.Y() - startR.Y(), startI.Y(), startR.Y()];
// Solve ode
var data = JXG.Math.Numerics.rungeKutta('rk4', x0, tspan, N, f);
// to plot the data against time we need the times where the equations were solved
var t = [];
var q = tspan[0];
var h = (tspan[1]-tspan[0])/N;
for(var i=0; i<data.length; i++) {
data[i].push(q);
q += h;
}
return data;
}
// get data points
var data = ode();
// copy data to arrays so we can plot it using JXG.Curve
var t = data.map( function(d) { return d[3]; } );
var dataI = data.map( function(d) { return d[1]; } );
var dataR = data.map( function(d) { return d[2]; } );
// Plot I
g1 = boardtime.createElement('curve', [t,dataI], {strokeColor:'blue', strokeWidth:4, highlight:false});
g1.updateDataArray = function() {
var data = ode();
this.dataX = data.map( function(d) { return d[3]; } );
this.dataY = data.map( function(d) { return d[1];} );
}
gt1 = boardtime.createElement('text', [
300,
function() {
var data = ode();
return data[300][1];
},
"Infected"]);
// Plot R
g2 = boardtime.createElement('curve', [t,dataR], { strokeColor:'green', strokeWidth:4, highlight:false});
g2.updateDataArray = function() {
var data = ode();
this.dataX = data.map( function(d) { return d[3]; } );
this.dataY = data.map( function(d) { return d[2]; } );
}
gt1 = boardtime.createElement('text', [
300,
function() {
var data = ode();
return data[300][2];
},
"Removed"]);
</script>
<hr>
<footer>
<!--<p>© Company 2014</p>-->
</footer>
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="js/bootstrap.min.js"></script>
</body>
</html>