-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
310 lines (310 loc) · 17.5 KB
/
index.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
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
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Content-Style-Type" content="text/css" />
<meta name="generator" content="pandoc" />
<title>Infection delays</title>
<style type="text/css">code{white-space: pre;}</style>
<script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_CHTML-full" type="text/javascript"></script>
</head>
<body>
<div id="header">
<h1 class="title">Infection delays</h1>
</div>
<div class="standard">
<span id="magicparlabel-2"></span>In the current covid-19 pandemic, people are interested in projecting forward in time to assess the efficacy of various techniques to control, or even better eliminate, the infection. The simplest models tend to be dominated by exponential behaviour, where the infected population tomorrow is related to today's infection by (roughly) a constant factor. If the factor is greater than 1, the infection grows; less than 1, the infection is fading, and happiness breaks out across the land. We come out of our prison blocks, blinking and shading our eyes from the sun.
</div>
<div class="standard">
<span id="magicparlabel-3"></span>Of course, the infection numbers tomorrow aren't simply related to what is happening today: in the case of covid-19 the infection takes up to two weeks to manifest, if at all in some cases. How come a simple constant factor works?
</div>
<div class="standard">
<span id="magicparlabel-4"></span>A reasonably simple model for infection delay (i.e. what has crossed what passes for my mind) would have today's newly infected population to be a function of the newly infected populations on previous days. To make life extra simple, we also use a linear function - a sum of the previous populations multiplied by various constant factors:
</div>
<div class="standard">
<span id="magicparlabel-5"></span><span class="math display">\[I_{0} = g_{1}I_{- 1} + g_{2}I_{- 2} + g_{3}I_{- 3} + \ldots\]</span>
</div>
<div class="standard">
<span id="magicparlabel-6"></span>Using fancy maths notation, with the Greek capital sigma character (Σ) indicating a sum between limits, with D being the length of time the infection lasts in the average person (or at least stops creating new infections):
</div>
<div class="standard">
<span id="magicparlabel-7"></span><span class="math display">\[I_{0} = \sum\limits_{{}_{d = 1}}^{{}_{D}}g_{d}I_{- d}\]</span>
</div>
<div class="standard">
<span id="magicparlabel-8"></span>Tomorrow's new infections would then be expected to be:
</div>
<div class="standard">
<span id="magicparlabel-9"></span><span class="math display">\[I_{1} = g_{1}I_{0} + g_{2}I_{- 1} + g_{3}I_{- 2} + \ldots = \sum\limits_{{}_{d = 1}}^{{}_{D}}g_{d}I_{- d + 1}\]</span>
</div>
<div class="standard">
<span id="magicparlabel-10"></span>And on day n:
</div>
<div class="standard">
<span id="magicparlabel-11"></span><span class="math display">\[I_{n} = g_{1}I_{n - 1} + g_{2}I_{n - 2} + g_{3}I_{n - 3} + \ldots = \sum\limits_{{}_{d = 1}}^{{}_{D}}g_{d}I_{n - d}\]</span>
</div>
<div class="standard">
<span id="magicparlabel-12"></span>There are known to be a number of (characteristic) solutions of these equations that have a simple power form:
</div>
<div class="standard">
<span id="magicparlabel-13"></span><span class="math display">\[I_{n} = a^{n}\]</span>
</div>
<div class="standard">
<span id="magicparlabel-14"></span>This only works for specific values of <em>a</em>. To find these values we pop the proposed solution into one of the equations:
</div>
<div class="standard">
<span id="magicparlabel-15"></span><span class="math display">\[a^{n} = g_{1}a^{n - 1} + g_{2}a^{n - 2} + g_{3}a^{n - 3} + \ldots + g_{D}a^{n - D}\]</span>
</div>
<div class="standard">
<span id="magicparlabel-16"></span>If we divide through by <em><span class="math inline">\(a^{n - D}\)</span>:</em>
</div>
<div class="standard">
<span id="magicparlabel-17"></span><span class="math display">\[a^{D} = g_{1}a^{D - 1} + g_{2}a^{D - 2} + g_{3}a^{D - 3} + \ldots + g_{D}\]</span>
</div>
<div class="standard">
<span id="magicparlabel-18"></span>This is a <em>D</em>-order polynomial. Note that <em>n</em> has dropped out, since it is not really relevant (and shouldn't be, that's the point) to the value of <em>a</em>. In theory, this equation can have up to <em>D</em> solutions. Allowing complex number solutions, there are exactly D solutions, possibly including multiple roots.
</div>
<h2 id="examples" class="section_"><span id="magicparlabel-19"></span>Examples</h2>
<h3 id="two-day-infection" class="subsection_"><span id="magicparlabel-20"></span>Two-day infection</h3>
<div class="standard">
<span id="magicparlabel-21"></span>Let's imagine the simplest non-trivial example - a 2-day infection: you, M. Average, pick up a mild cold virus at the supermarket, go around for a couple of days unaware that you are sub-par, then sniffles strike and you stay home and hopefully beat off the virus in short order. On the first day after the supermarketing you infect 0.25 of a person (as M. Average); day two comes, and, with the virus settled in and happily reproducing wildly, you infect 1.5 people. This would give:
</div>
<div class="standard">
<span id="magicparlabel-22"></span><span class="math display">\[I_{n} = 0.25I_{n - 1} + 1.5I_{n - 2}\]</span>
</div>
<div class="standard">
<span id="magicparlabel-23"></span>The characteristic polynomial is then a quadratic:
</div>
<div class="standard">
<span id="magicparlabel-24"></span><span class="math display">\[a^{2} = 0.25a + 1.5\]</span>
</div>
<div class="standard">
<span id="magicparlabel-25"></span>This is satisfied by real <em>a</em> values of about 1.36 and -1.11 (more accurate values in spreadsheet):
</div>
<div class="standard">
<span id="magicparlabel-212"></span><img src="0_home_mike_Infection_delays_character.svg" alt="image: 0_home_mike_Infection_delays_character.svg" />
</div>
<div class="standard">
<span id="magicparlabel-26"></span>Let's imagine the cold virus initially infected one person on day 0, “patient zero”. Before that the infection was at zero (it didn't exist). On day 1, there is a quarter (0.25) of a person newly infected. On day 2, the newly infected are 0.25×0.25+1.5×1, or approximately 1.56. And so on. I have put this into a spreadsheet, and used the graph features to produce the following images with new infections plotted on linear and logarithmic scales:
</div>
<div class="standard">
<span id="magicparlabel-216"></span><img src="1_home_mike_Infection_delays_2dlin.png" alt="image: 1_home_mike_Infection_delays_2dlin.png" /> <img src="2_home_mike_Infection_delays_2dlog.svg" alt="image: 2_home_mike_Infection_delays_2dlog.svg" />
</div>
<div class="standard">
<span id="magicparlabel-27"></span>We note that the logarithmic image shows initial wobbling, but eventually tends to a straight line. In the spreadsheet there is an additional “Factor” column where I have taken the ratio of new infections for “today” and “yesterday”. I have created a graph of this too:
</div>
<div class="standard">
<span id="magicparlabel-317"></span><img src="3_home_mike_Infection_delays_2dfor.svg" alt="image: 3_home_mike_Infection_delays_2dfor.svg" />
</div>
<div class="standard">
<span id="magicparlabel-28"></span>If you look at the values in the spreadsheet, the factor tends to 1.36 approximately. Assuming that you aren't a proverbial goldfish, you may remember above that one of the solutions of the characteristic equation was 1.36. This not an accident - the solution with the largest absolute value tends to dominate, given sufficient time (after about 20 days, in this case). So once the infection has set in, one can model the behavior as a simple exponential.
</div>
<div class="standard">
<span id="magicparlabel-29"></span>What does the other solution represent? We will show that it gives the wobbles in the initial stages of the infection. In fact we try a solution:
</div>
<div class="standard">
<span id="magicparlabel-30"></span><span class="math display">\[I_{n} = A\left( 1.36)^{n} + B\left( - 1.11)^{n} \right. \right.\]</span>
</div>
<div class="standard">
<span id="magicparlabel-31"></span>On day 0, we have:
</div>
<div class="standard">
<span id="magicparlabel-32"></span><span class="math display">\[1 = A\left( 1.36)^{0} + B\left( - 1.11)^{0} = A + B \right. \right.\]</span>
</div>
<div class="standard">
<span id="magicparlabel-33"></span>Day 1:
</div>
<div class="standard">
<span id="magicparlabel-34"></span><span class="math display">\[0.25 = A\left( 1.36)^{1} + B\left( - 1.11)^{1} = 1.36A - 1.11B \right. \right.\]</span>
</div>
<div class="standard">
<span id="magicparlabel-35"></span>This is enough for us to solve for <em>A</em> and <em>B</em>, giving roughly 0.55 and 0.45, respectively. Since these are only accurate to two significant figures the deviation from the true solution is quite rapid:
</div>
<div class="standard">
<span id="magicparlabel-36"></span>
<table>
<colgroup>
<col width="33%" />
<col width="33%" />
<col width="33%" />
</colgroup>
<tbody>
<tr class="odd">
<td><div class="plain_layout">
<span id="magicparlabel-82"></span>Day
</div></td>
<td><div class="plain_layout">
<span id="magicparlabel-85"></span>New infections (I<sub>n</sub>)
</div></td>
<td><div class="plain_layout">
<span id="magicparlabel-92"></span>I<sub>n</sub> prediction
</div></td>
</tr>
<tr class="even">
<td><div class="plain_layout">
<span id="magicparlabel-99"></span>0
</div></td>
<td><div class="plain_layout">
<span id="magicparlabel-102"></span>1
</div></td>
<td><div class="plain_layout">
<span id="magicparlabel-105"></span>1
</div></td>
</tr>
<tr class="odd">
<td><div class="plain_layout">
<span id="magicparlabel-108"></span>1
</div></td>
<td><div class="plain_layout">
<span id="magicparlabel-111"></span>0.25
</div></td>
<td><div class="plain_layout">
<span id="magicparlabel-114"></span>0.2485
</div></td>
</tr>
<tr class="even">
<td><div class="plain_layout">
<span id="magicparlabel-117"></span>2
</div></td>
<td><div class="plain_layout">
<span id="magicparlabel-120"></span>1.5625
</div></td>
<td><div class="plain_layout">
<span id="magicparlabel-123"></span>1.571725
</div></td>
</tr>
<tr class="odd">
<td><div class="plain_layout">
<span id="magicparlabel-126"></span>3
</div></td>
<td><div class="plain_layout">
<span id="magicparlabel-129"></span>0.765625
</div></td>
<td><div class="plain_layout">
<span id="magicparlabel-132"></span>0.76806685
</div></td>
</tr>
<tr class="even">
<td><div class="plain_layout">
<span id="magicparlabel-135"></span>4
</div></td>
<td><div class="plain_layout">
<span id="magicparlabel-138"></span>2.53515625
</div></td>
<td><div class="plain_layout">
<span id="magicparlabel-141"></span>2.5646927725
</div></td>
</tr>
<tr class="odd">
<td><div class="plain_layout">
<span id="magicparlabel-144"></span>5
</div></td>
<td><div class="plain_layout">
<span id="magicparlabel-147"></span>1.7822265625
</div></td>
<td><div class="plain_layout">
<span id="magicparlabel-150"></span>1.800646909885
</div></td>
</tr>
<tr class="even">
<td><div class="plain_layout">
<span id="magicparlabel-153"></span>6
</div></td>
<td><div class="plain_layout">
<span id="magicparlabel-156"></span>4.248291015625
</div></td>
<td><div class="plain_layout">
<span id="magicparlabel-159"></span>4.32182193683725
</div></td>
</tr>
<tr class="odd">
<td><div class="plain_layout">
<span id="magicparlabel-162"></span>7
</div></td>
<td><div class="plain_layout">
<span id="magicparlabel-165"></span>3.73541259765625
</div></td>
<td><div class="plain_layout">
<span id="magicparlabel-168"></span>3.79871205937171
</div></td>
</tr>
<tr class="even">
<td><div class="plain_layout">
<span id="magicparlabel-171"></span>8
</div></td>
<td><div class="plain_layout">
<span id="magicparlabel-174"></span>7.30628967285156
</div></td>
<td><div class="plain_layout">
<span id="magicparlabel-177"></span>7.47390041069244
</div></td>
</tr>
<tr class="odd">
<td><div class="plain_layout">
<span id="magicparlabel-180"></span>9
</div></td>
<td><div class="plain_layout">
<span id="magicparlabel-183"></span>7.42969131469727
</div></td>
<td><div class="plain_layout">
<span id="magicparlabel-186"></span>7.60301082750063
</div></td>
</tr>
<tr class="even">
<td><div class="plain_layout">
<span id="magicparlabel-189"></span>10
</div></td>
<td><div class="plain_layout">
<span id="magicparlabel-192"></span>12.8168573379517
</div></td>
<td><div class="plain_layout">
<span id="magicparlabel-195"></span>13.1833527668565
</div></td>
</tr>
</tbody>
</table>
</div>
<div class="standard">
<span id="magicparlabel-196"></span>As the process repeats, the rounding errors become more and more severe. If one is minded, one can increase the precision of the arithmetic, and the solution of the sum of two powers multiplied by factors becomes exact in the limit of infinite precision. A better comparison is available in the spreadsheet.
</div>
<div class="standard">
<span id="magicparlabel-197"></span>With a more extended infection period, more solutions need to be added to give the initial wobbles. If there are D different roots of the characteristic equation, then you can again “solve” the progression with sums of powers that fits an initial infection pattern spread over D days. If some of the roots are multiple, the solution becomes more complicated, but not intractible. In real life, other factors come into play, such as the gathering of data being sporadic, hampered by political considerations, butt covering, and so on. One is then largely restricted to, hopefully intelligent, guesswork.
</div>
<div class="standard">
<span id="magicparlabel-198"></span>Being a bit bonkers, I decided to run the prediction backwards in time (<em>I</em><sub><em>-n</em></sub>) on the spreadsheet with the related factor column gives the reduction factor going backwards in time (-<em>n</em>). We note that this tends to -1.11, the other solution of the characteristic polynomial. As far as it can (the solution is effectively zero at this point), it “dominates” the negative time behaviour:
</div>
<div class="standard">
<span id="magicparlabel-323"></span><img src="4_home_mike_Infection_delays_2dback.svg" alt="image: 4_home_mike_Infection_delays_2dback.svg" />
</div>
<h3 id="three-day-infection" class="subsection_"><span id="magicparlabel-203"></span>Three-day infection</h3>
<div class="standard">
<span id="magicparlabel-204"></span>As the infection period extends, life gets more complicated since we don't have simple solutions like the quadratics we learned in school. For cubics and quartics (up to fourth power), there are non-obvious solutions, which seem to have been found more by luck than judgement during the Italian Renaissance, and kept secret for a time, giving advantage to the knowers in maths competitions. Quintics (fifth power) and beyond don't even have a general solution, as shown by Galois before dying in a duel. These equations can be treated numerically, which is how we will treat a three-day example, although in principle one could find a solution. I studied:
</div>
<div class="standard">
<span id="magicparlabel-205"></span><span class="math display">\[I_{n} = 0.25I_{n - 1} + 0.75I_{n - 2} + I_{n - 3}\]</span>
</div>
<div class="standard">
<span id="magicparlabel-206"></span>giving a characteristic:
</div>
<div class="standard">
<span id="magicparlabel-207"></span><span class="math display">\[a^{3} = 0.25a^{2} + 0.75a + 1\]</span>
</div>
<div class="standard">
<span id="magicparlabel-327"></span><img src="5_home_mike_Infection_delays_c3.svg" alt="image: 5_home_mike_Infection_delays_c3.svg" />
</div>
<div class="standard">
<span id="magicparlabel-208"></span>As it happens, the real solution is about 1.35. There are also two complex solutions, roughly -0.55±0.66i. The absolute value of the complex solutions is about 0.86, less than the real solution. Having absolute values less than 1, means the complex solutions are damped, tending to zero. I initially tried working wholly on a spreadsheet, but in this case a python 3 script (below, as a txt file, since this site prohibits py files) enabled me to match the sum of powers predicition to the recurrence calculation. The script references scipy/numpy modules that you might need to install using pip3 or whatever. The script is also adaptable to work out the characteristic solutions for longer infection periods. The output is a csv file with the brute force calculation and a “patient zero” fit to the characteristic solutions:
</div>
<div class="standard">
<span id="magicparlabel-331"></span><img src="6_home_mike_Infection_delays_3dfor.svg" alt="image: 6_home_mike_Infection_delays_3dfor.svg" />
</div>
<div class="standard">
<span id="magicparlabel-209"></span>The backwards behaviour (retrodiction), also included, is even more bonkers since the two complex solutions play off each other, giving oscillations with a growing amplitude.
</div>
<div class="standard">
<span id="magicparlabel-335"></span><img src="7_home_mike_Infection_delays_3dback.svg" alt="image: 7_home_mike_Infection_delays_3dback.svg" />
</div>
<div class="standard">
<span id="magicparlabel-337"></span>This is better understood by putting the various complex bits in polar form. The real characteristic solution is damped in the backward direction. A simple-minded yesterday/today ratio comparison is not much use for relating the behavior to the these roots. In the context of infections, the negative time solution is of little practical interest, since it didn't exist before “patient zero”, who is assumed to come from nothing (or <em>ex nihilo</em>, as Boris Johnson would say).
</div>
</body>
</html>