{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Simple model of infection" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Each individual infects $c$ new people each day." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "$I_{n+1} = I_n + (c I_n) = I_n(1 + c)$" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "So" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "$I_{n+1} = \\lambda I_n$, where $\\lambda := 1 + c$ -- **growth rate**\n", "\n", "and $I_0 = 1$" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "1" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "I0 = 1" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "1" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "I_0 = 1" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "1" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "I₀ = 1 # \\_0 " ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0.01" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "c = 0.01 # average no. of people that each individual infects on each day" ] }, { "cell_type": "code", "execution_count": 8, "metadata": { "scrolled": true }, "outputs": [ { "data": { "text/plain": [ "1.01" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "λ = 1 + c # \\lambda " ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [], "source": [ "λ = 1 + c; " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "`;` suppresses output" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "1.01" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "I_1 = λ * I_0" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "1.0201" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "I_2 = λ * I_1" ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "1.030301" ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "I_3 = λ * I_2" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Arrays" ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "10-element Array{Float64,1}:\n", " 0.0\n", " 0.0\n", " 0.0\n", " 0.0\n", " 0.0\n", " 0.0\n", " 0.0\n", " 0.0\n", " 0.0\n", " 0.0" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "T = 10 # final time \n", "\n", "I = zeros(T) " ] }, { "cell_type": "code", "execution_count": 15, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "10-element Array{Float64,1}:\n", " 0.0\n", " 0.0\n", " 0.0\n", " 0.0\n", " 0.0\n", " 0.0\n", " 0.0\n", " 0.0\n", " 0.0\n", " 0.0" ] }, "execution_count": 15, "metadata": {}, "output_type": "execute_result" } ], "source": [ "I" ] }, { "cell_type": "code", "execution_count": 16, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0.0" ] }, "execution_count": 16, "metadata": {}, "output_type": "execute_result" } ], "source": [ "I[1]" ] }, { "cell_type": "code", "execution_count": 17, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "2-element Array{Float64,1}:\n", " 0.0\n", " 0.0" ] }, "execution_count": 17, "metadata": {}, "output_type": "execute_result" } ], "source": [ "I[1:2]" ] }, { "cell_type": "code", "execution_count": 19, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "10-element Array{Int64,1}:\n", " 0\n", " 0\n", " 0\n", " 0\n", " 0\n", " 0\n", " 0\n", " 0\n", " 0\n", " 0" ] }, "execution_count": 19, "metadata": {}, "output_type": "execute_result" } ], "source": [ "I = zeros(Int64, T)" ] }, { "cell_type": "code", "execution_count": 20, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "10-element Array{Float64,1}:\n", " 0.0\n", " 0.0\n", " 0.0\n", " 0.0\n", " 0.0\n", " 0.0\n", " 0.0\n", " 0.0\n", " 0.0\n", " 0.0" ] }, "execution_count": 20, "metadata": {}, "output_type": "execute_result" } ], "source": [ "I = zeros(T)" ] }, { "cell_type": "code", "execution_count": 21, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "1" ] }, "execution_count": 21, "metadata": {}, "output_type": "execute_result" } ], "source": [ "I[1] = I_0 # Could use OffsetArrays.jl -- enables arbitrary indexing" ] }, { "cell_type": "code", "execution_count": 25, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "(n, I[n]) = (1, 1.0)\n", "(n, I[n]) = (2, 1.01)\n", "(n, I[n]) = (3, 1.0201)\n", "(n, I[n]) = (4, 1.030301)\n", "(n, I[n]) = (5, 1.04060401)\n", "(n, I[n]) = (6, 1.0510100501)\n", "(n, I[n]) = (7, 1.061520150601)\n", "(n, I[n]) = (8, 1.0721353521070098)\n", "(n, I[n]) = (9, 1.08285670562808)\n" ] } ], "source": [ "for n in 1:T-1\n", " I[n+1] = λ * I[n]\n", " @show n, I[n]\n", "end\n", "\n", "# for loops do not return anything so running a for loop does not output" ] }, { "cell_type": "code", "execution_count": 26, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "10-element Array{Float64,1}:\n", " 1.0\n", " 1.01\n", " 1.0201\n", " 1.030301\n", " 1.04060401\n", " 1.0510100501\n", " 1.061520150601\n", " 1.0721353521070098\n", " 1.08285670562808\n", " 1.0936852726843609" ] }, "execution_count": 26, "metadata": {}, "output_type": "execute_result" } ], "source": [ "I" ] }, { "cell_type": "code", "execution_count": 27, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "┌ Info: Precompiling Plots [91a5bcdd-55d7-5caf-9e0b-520d859cae80]\n", "└ @ Base loading.jl:1260\n" ] } ], "source": [ "using Plots" ] }, { "cell_type": "code", "execution_count": 29, "metadata": {}, "outputs": [ { "data": { "image/svg+xml": [ "\n", "\n", "\n", " \n", " \n", " \n", "\n", "\n", "\n", " \n", " \n", " \n", "\n", "\n", "\n", " \n", " \n", " \n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "2\n", "\n", "\n", "4\n", "\n", "\n", "6\n", "\n", "\n", "8\n", "\n", "\n", "10\n", "\n", "\n", "1.00\n", "\n", "\n", "1.02\n", "\n", "\n", "1.04\n", "\n", "\n", "1.06\n", "\n", "\n", "1.08\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "I[n]\n", "\n", "\n" ] }, "execution_count": 29, "metadata": {}, "output_type": "execute_result" } ], "source": [ "plot(I, m=:o, label=\"I[n]\", legend=:topleft)" ] }, { "cell_type": "code", "execution_count": 30, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "(n, I[n]) = (1, 1.0)\n", "(n, I[n]) = (2, 1.01)\n", "(n, I[n]) = (3, 1.0201)\n", "(n, I[n]) = (4, 1.030301)\n", "(n, I[n]) = (5, 1.04060401)\n", "(n, I[n]) = (6, 1.0510100501)\n", "(n, I[n]) = (7, 1.061520150601)\n", "(n, I[n]) = (8, 1.0721353521070098)\n", "(n, I[n]) = (9, 1.08285670562808)\n" ] }, { "ename": "BoundsError", "evalue": "BoundsError: attempt to access 10-element Array{Float64,1} at index [11]", "output_type": "error", "traceback": [ "BoundsError: attempt to access 10-element Array{Float64,1} at index [11]", "", "Stacktrace:", " [1] setindex!(::Array{Float64,1}, ::Float64, ::Int64) at ./array.jl:825", " [2] top-level scope at ./In[30]:6" ] } ], "source": [ "T = 20\n", "\n", "I = zeros(I)\n", "I[1] = I_0\n", "\n", "for n in 1:T-1\n", " I[n+1] = λ * I[n]\n", " @show n, I[n]\n", "end\n", "\n", "plot(I)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Functions" ] }, { "cell_type": "code", "execution_count": 31, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "run_infection (generic function with 2 methods)" ] }, "execution_count": 31, "metadata": {}, "output_type": "execute_result" } ], "source": [ "function run_infection(T=20) # default\n", "\n", " I = zeros(T)\n", " I[1] = I_0\n", "\n", " for n in 1:T-1\n", " I[n+1] = λ * I[n]\n", " end\n", "\n", " return I\n", "end" ] }, { "cell_type": "code", "execution_count": 32, "metadata": {}, "outputs": [ { "data": { "text/html": [ "# 2 methods for generic function run_infection:" ], "text/plain": [ "# 2 methods for generic function \"run_infection\":\n", "[1] run_infection() in Main at In[31]:3\n", "[2] run_infection(T) in Main at In[31]:3" ] }, "execution_count": 32, "metadata": {}, "output_type": "execute_result" } ], "source": [ "methods(run_infection)" ] }, { "cell_type": "code", "execution_count": 33, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "10-element Array{Float64,1}:\n", " 1.0\n", " 1.01\n", " 1.0201\n", " 1.030301\n", " 1.04060401\n", " 1.0510100501\n", " 1.061520150601\n", " 1.0721353521070098\n", " 1.08285670562808\n", " 1.0936852726843609" ] }, "execution_count": 33, "metadata": {}, "output_type": "execute_result" } ], "source": [ "run_infection(10)" ] }, { "cell_type": "code", "execution_count": 34, "metadata": {}, "outputs": [], "source": [ "I_result = run_infection(10);" ] }, { "cell_type": "code", "execution_count": 35, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "10-element Array{Float64,1}:\n", " 1.0\n", " 1.01\n", " 1.0201\n", " 1.030301\n", " 1.04060401\n", " 1.0510100501\n", " 1.061520150601\n", " 1.0721353521070098\n", " 1.08285670562808\n", " 1.0936852726843609" ] }, "execution_count": 35, "metadata": {}, "output_type": "execute_result" } ], "source": [ "I_result" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**Always separate data generation from plotting!**" ] }, { "cell_type": "code", "execution_count": 38, "metadata": {}, "outputs": [ { "data": { "image/svg+xml": [ "\n", "\n", "\n", " \n", " \n", " \n", "\n", "\n", "\n", " \n", " \n", " \n", "\n", "\n", "\n", " \n", " \n", " \n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "5\n", "\n", "\n", "10\n", "\n", "\n", "15\n", "\n", "\n", "20\n", "\n", "\n", "1.00\n", "\n", "\n", "1.05\n", "\n", "\n", "1.10\n", "\n", "\n", "1.15\n", "\n", "\n", "1.20\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "y1\n", "\n", "\n" ] }, "execution_count": 38, "metadata": {}, "output_type": "execute_result" } ], "source": [ "I_result = run_infection(20)\n", "\n", "plot(I_result, m=:o)" ] }, { "cell_type": "code", "execution_count": 39, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "\n", " Unable to load WebIO. Please make sure WebIO works for your Jupyter client.\n", " For troubleshooting, please see \n", " the WebIO/IJulia documentation.\n", " \n", "

\n" ], "text/plain": [ "HTML{String}(\"\\n\\n Unable to load WebIO. Please make sure WebIO works for your Jupyter client.\\n For troubleshooting, please see \\n the WebIO/IJulia documentation.\\n \\n

\\n\")" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "using Interact" ] }, { "cell_type": "code", "execution_count": 44, "metadata": {}, "outputs": [ { "data": { "application/vnd.webio.node+json": { "children": [ { "children": [ { "children": [ { "children": [ { "children": [ { "children": [ "" ], "instanceArgs": { "namespace": "html", "tag": "label" }, "nodeType": "DOM", "props": { "className": "interact ", "style": { "padding": "5px 10px 0px 10px" } }, "type": "node" } ], "instanceArgs": { "namespace": "html", "tag": "div" }, "nodeType": "DOM", "props": { "className": "interact-flex-row-left" }, "type": "node" }, { "children": [ { "children": [], "instanceArgs": { "namespace": "html", "tag": "input" }, "nodeType": "DOM", "props": { "attributes": { "data-bind": "numericValue: index, valueUpdate: 'input', event: {change: function (){this.changes(this.changes()+1)}}", "orient": "horizontal", "type": "range" }, "className": "slider slider is-fullwidth", "max": 1000, "min": 1, "step": 1, "style": {} }, "type": "node" } ], "instanceArgs": { "namespace": "html", "tag": "div" }, "nodeType": "DOM", "props": { "className": "interact-flex-row-center" }, "type": "node" }, { "children": [ { "children": [], "instanceArgs": { "namespace": "html", "tag": "p" }, "nodeType": "DOM", "props": { "attributes": { "data-bind": "text: formatted_val" } }, "type": "node" } ], "instanceArgs": { "namespace": "html", "tag": "div" }, "nodeType": "DOM", "props": { "className": "interact-flex-row-right" }, "type": "node" } ], "instanceArgs": { "namespace": "html", "tag": "div" }, "nodeType": "DOM", "props": { "className": "interact-flex-row interact-widget" }, "type": "node" } ], "instanceArgs": { "handlers": { "changes": [ "(function (val){return (val!=this.model[\"changes\"]()) ? (this.valueFromJulia[\"changes\"]=true, this.model[\"changes\"](val)) : undefined})" ], "index": [ "(function (val){return (val!=this.model[\"index\"]()) ? (this.valueFromJulia[\"index\"]=true, this.model[\"index\"](val)) : undefined})" ] }, "id": "12081152369788741163", "imports": { "data": [ { "name": "knockout", "type": "js", "url": "/assetserver/800fa077652c804a9c5f68b6c1e29c6c61f85df7-knockout.js" }, { "name": "knockout_punches", "type": "js", "url": "/assetserver/81e3f253b58efa296c3c65b00e2bf7b25de6cca9-knockout_punches.js" }, { "name": null, "type": "js", "url": "/assetserver/5d2042c6908ffff0b7c8d26135740476bcf00827-all.js" }, { "name": null, "type": "css", "url": "/assetserver/87ad319ae61de5d44f67c268a0a8f65862fca478-style.css" }, { "name": null, "type": "css", "url": "/assetserver/a062b31556f81f574879e47f48c7fae2687f3c82-bulma_confined.min.css" } ], "type": "async_block" }, "mount_callbacks": [ "function () {\n var handler = (function (ko, koPunches) {\n ko.punches.enableAll();\n ko.bindingHandlers.numericValue = {\n init: function(element, valueAccessor, allBindings, data, context) {\n var stringified = ko.observable(ko.unwrap(valueAccessor()));\n stringified.subscribe(function(value) {\n var val = parseFloat(value);\n if (!isNaN(val)) {\n valueAccessor()(val);\n }\n });\n valueAccessor().subscribe(function(value) {\n var str = JSON.stringify(value);\n if ((str == \"0\") && ([\"-0\", \"-0.\"].indexOf(stringified()) >= 0))\n return;\n if ([\"null\", \"\"].indexOf(str) >= 0)\n return;\n stringified(str);\n });\n ko.applyBindingsToNode(\n element,\n {\n value: stringified,\n valueUpdate: allBindings.get('valueUpdate'),\n },\n context,\n );\n }\n };\n var json_data = {\"formatted_vals\":[\"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\",\"311\",\"312\",\"313\",\"314\",\"315\",\"316\",\"317\",\"318\",\"319\",\"320\",\"321\",\"322\",\"323\",\"324\",\"325\",\"326\",\"327\",\"328\",\"329\",\"330\",\"331\",\"332\",\"333\",\"334\",\"335\",\"336\",\"337\",\"338\",\"339\",\"340\",\"341\",\"342\",\"343\",\"344\",\"345\",\"346\",\"347\",\"348\",\"349\",\"350\",\"351\",\"352\",\"353\",\"354\",\"355\",\"356\",\"357\",\"358\",\"359\",\"360\",\"361\",\"362\",\"363\",\"364\",\"365\",\"366\",\"367\",\"368\",\"369\",\"370\",\"371\",\"372\",\"373\",\"374\",\"375\",\"376\",\"377\",\"378\",\"379\",\"380\",\"381\",\"382\",\"383\",\"384\",\"385\",\"386\",\"387\",\"388\",\"389\",\"390\",\"391\",\"392\",\"393\",\"394\",\"395\",\"396\",\"397\",\"398\",\"399\",\"400\",\"401\",\"402\",\"403\",\"404\",\"405\",\"406\",\"407\",\"408\",\"409\",\"410\",\"411\",\"412\",\"413\",\"414\",\"415\",\"416\",\"417\",\"418\",\"419\",\"420\",\"421\",\"422\",\"423\",\"424\",\"425\",\"426\",\"427\",\"428\",\"429\",\"430\",\"431\",\"432\",\"433\",\"434\",\"435\",\"436\",\"437\",\"438\",\"439\",\"440\",\"441\",\"442\",\"443\",\"444\",\"445\",\"446\",\"447\",\"448\",\"449\",\"450\",\"451\",\"452\",\"453\",\"454\",\"455\",\"456\",\"457\",\"458\",\"459\",\"460\",\"461\",\"462\",\"463\",\"464\",\"465\",\"466\",\"467\",\"468\",\"469\",\"470\",\"471\",\"472\",\"473\",\"474\",\"475\",\"476\",\"477\",\"478\",\"479\",\"480\",\"481\",\"482\",\"483\",\"484\",\"485\",\"486\",\"487\",\"488\",\"489\",\"490\",\"491\",\"492\",\"493\",\"494\",\"495\",\"496\",\"497\",\"498\",\"499\",\"500\",\"501\",\"502\",\"503\",\"504\",\"505\",\"506\",\"507\",\"508\",\"509\",\"510\",\"511\",\"512\",\"513\",\"514\",\"515\",\"516\",\"517\",\"518\",\"519\",\"520\",\"521\",\"522\",\"523\",\"524\",\"525\",\"526\",\"527\",\"528\",\"529\",\"530\",\"531\",\"532\",\"533\",\"534\",\"535\",\"536\",\"537\",\"538\",\"539\",\"540\",\"541\",\"542\",\"543\",\"544\",\"545\",\"546\",\"547\",\"548\",\"549\",\"550\",\"551\",\"552\",\"553\",\"554\",\"555\",\"556\",\"557\",\"558\",\"559\",\"560\",\"561\",\"562\",\"563\",\"564\",\"565\",\"566\",\"567\",\"568\",\"569\",\"570\",\"571\",\"572\",\"573\",\"574\",\"575\",\"576\",\"577\",\"578\",\"579\",\"580\",\"581\",\"582\",\"583\",\"584\",\"585\",\"586\",\"587\",\"588\",\"589\",\"590\",\"591\",\"592\",\"593\",\"594\",\"595\",\"596\",\"597\",\"598\",\"599\",\"600\",\"601\",\"602\",\"603\",\"604\",\"605\",\"606\",\"607\",\"608\",\"609\",\"610\",\"611\",\"612\",\"613\",\"614\",\"615\",\"616\",\"617\",\"618\",\"619\",\"620\",\"621\",\"622\",\"623\",\"624\",\"625\",\"626\",\"627\",\"628\",\"629\",\"630\",\"631\",\"632\",\"633\",\"634\",\"635\",\"636\",\"637\",\"638\",\"639\",\"640\",\"641\",\"642\",\"643\",\"644\",\"645\",\"646\",\"647\",\"648\",\"649\",\"650\",\"651\",\"652\",\"653\",\"654\",\"655\",\"656\",\"657\",\"658\",\"659\",\"660\",\"661\",\"662\",\"663\",\"664\",\"665\",\"666\",\"667\",\"668\",\"669\",\"670\",\"671\",\"672\",\"673\",\"674\",\"675\",\"676\",\"677\",\"678\",\"679\",\"680\",\"681\",\"682\",\"683\",\"684\",\"685\",\"686\",\"687\",\"688\",\"689\",\"690\",\"691\",\"692\",\"693\",\"694\",\"695\",\"696\",\"697\",\"698\",\"699\",\"700\",\"701\",\"702\",\"703\",\"704\",\"705\",\"706\",\"707\",\"708\",\"709\",\"710\",\"711\",\"712\",\"713\",\"714\",\"715\",\"716\",\"717\",\"718\",\"719\",\"720\",\"721\",\"722\",\"723\",\"724\",\"725\",\"726\",\"727\",\"728\",\"729\",\"730\",\"731\",\"732\",\"733\",\"734\",\"735\",\"736\",\"737\",\"738\",\"739\",\"740\",\"741\",\"742\",\"743\",\"744\",\"745\",\"746\",\"747\",\"748\",\"749\",\"750\",\"751\",\"752\",\"753\",\"754\",\"755\",\"756\",\"757\",\"758\",\"759\",\"760\",\"761\",\"762\",\"763\",\"764\",\"765\",\"766\",\"767\",\"768\",\"769\",\"770\",\"771\",\"772\",\"773\",\"774\",\"775\",\"776\",\"777\",\"778\",\"779\",\"780\",\"781\",\"782\",\"783\",\"784\",\"785\",\"786\",\"787\",\"788\",\"789\",\"790\",\"791\",\"792\",\"793\",\"794\",\"795\",\"796\",\"797\",\"798\",\"799\",\"800\",\"801\",\"802\",\"803\",\"804\",\"805\",\"806\",\"807\",\"808\",\"809\",\"810\",\"811\",\"812\",\"813\",\"814\",\"815\",\"816\",\"817\",\"818\",\"819\",\"820\",\"821\",\"822\",\"823\",\"824\",\"825\",\"826\",\"827\",\"828\",\"829\",\"830\",\"831\",\"832\",\"833\",\"834\",\"835\",\"836\",\"837\",\"838\",\"839\",\"840\",\"841\",\"842\",\"843\",\"844\",\"845\",\"846\",\"847\",\"848\",\"849\",\"850\",\"851\",\"852\",\"853\",\"854\",\"855\",\"856\",\"857\",\"858\",\"859\",\"860\",\"861\",\"862\",\"863\",\"864\",\"865\",\"866\",\"867\",\"868\",\"869\",\"870\",\"871\",\"872\",\"873\",\"874\",\"875\",\"876\",\"877\",\"878\",\"879\",\"880\",\"881\",\"882\",\"883\",\"884\",\"885\",\"886\",\"887\",\"888\",\"889\",\"890\",\"891\",\"892\",\"893\",\"894\",\"895\",\"896\",\"897\",\"898\",\"899\",\"900\",\"901\",\"902\",\"903\",\"904\",\"905\",\"906\",\"907\",\"908\",\"909\",\"910\",\"911\",\"912\",\"913\",\"914\",\"915\",\"916\",\"917\",\"918\",\"919\",\"920\",\"921\",\"922\",\"923\",\"924\",\"925\",\"926\",\"927\",\"928\",\"929\",\"930\",\"931\",\"932\",\"933\",\"934\",\"935\",\"936\",\"937\",\"938\",\"939\",\"940\",\"941\",\"942\",\"943\",\"944\",\"945\",\"946\",\"947\",\"948\",\"949\",\"950\",\"951\",\"952\",\"953\",\"954\",\"955\",\"956\",\"957\",\"958\",\"959\",\"960\",\"961\",\"962\",\"963\",\"964\",\"965\",\"966\",\"967\",\"968\",\"969\",\"970\",\"971\",\"972\",\"973\",\"974\",\"975\",\"976\",\"977\",\"978\",\"979\",\"980\",\"981\",\"982\",\"983\",\"984\",\"985\",\"986\",\"987\",\"988\",\"989\",\"990\",\"991\",\"992\",\"993\",\"994\",\"995\",\"996\",\"997\",\"998\",\"999\",\"1000\"],\"changes\":WebIO.getval({\"name\":\"changes\",\"scope\":\"12081152369788741163\",\"id\":\"ob_34\",\"type\":\"observable\"}),\"index\":WebIO.getval({\"name\":\"index\",\"scope\":\"12081152369788741163\",\"id\":\"ob_33\",\"type\":\"observable\"})};\n var self = this;\n function AppViewModel() {\n for (var key in json_data) {\n var el = json_data[key];\n this[key] = Array.isArray(el) ? ko.observableArray(el) : ko.observable(el);\n }\n \n [this[\"formatted_val\"]=ko.computed( function(){\n return this.formatted_vals()[parseInt(this.index())-(1)];\n }\n,this)]\n [this[\"changes\"].subscribe((function (val){!(this.valueFromJulia[\"changes\"]) ? (WebIO.setval({\"name\":\"changes\",\"scope\":\"12081152369788741163\",\"id\":\"ob_34\",\"type\":\"observable\"},val)) : undefined; return this.valueFromJulia[\"changes\"]=false}),self),this[\"index\"].subscribe((function (val){!(this.valueFromJulia[\"index\"]) ? (WebIO.setval({\"name\":\"index\",\"scope\":\"12081152369788741163\",\"id\":\"ob_33\",\"type\":\"observable\"},val)) : undefined; return this.valueFromJulia[\"index\"]=false}),self)]\n \n }\n self.model = new AppViewModel();\n self.valueFromJulia = {};\n for (var key in json_data) {\n self.valueFromJulia[key] = false;\n }\n ko.applyBindings(self.model, self.dom);\n}\n);\n (WebIO.importBlock({\"data\":[{\"name\":\"knockout\",\"type\":\"js\",\"url\":\"/assetserver/800fa077652c804a9c5f68b6c1e29c6c61f85df7-knockout.js\"},{\"name\":\"knockout_punches\",\"type\":\"js\",\"url\":\"/assetserver/81e3f253b58efa296c3c65b00e2bf7b25de6cca9-knockout_punches.js\"}],\"type\":\"async_block\"})).then((imports) => handler.apply(this, imports));\n}\n" ], "observables": { "changes": { "id": "ob_34", "sync": false, "value": 0 }, "index": { "id": "ob_33", "sync": true, "value": 1 } }, "systemjs_options": null }, "nodeType": "Scope", "props": {}, "type": "node" } ], "instanceArgs": { "namespace": "html", "tag": "div" }, "nodeType": "DOM", "props": { "className": "field interact-widget" }, "type": "node" }, { "children": [ { "children": [], "instanceArgs": { "id": "ob_40", "name": "obs-node" }, "nodeType": "ObservableNode", "props": {}, "type": "node" } ], "instanceArgs": { "handlers": {}, "id": "6905285092756041225", "imports": { "data": [], "type": "async_block" }, "mount_callbacks": [], "observables": { "obs-node": { "id": "ob_40", "sync": false, "value": { "children": [ { "children": [], "instanceArgs": { "namespace": "html", "tag": "div" }, "nodeType": "DOM", "props": { "setInnerHtml": "\n\n\n \n \n \n\n\n\n \n \n \n\n\n\n \n \n \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n0\n\n\n200\n\n\n400\n\n\n600\n\n\n800\n\n\n1000\n\n\n0\n\n\n2\n\n\n4\n\n\n6\n\n\n8\n\n\n10\n\n\n\n\n\n\n\ny1\n\n\n" }, "type": "node" } ], "instanceArgs": { "namespace": "html", "tag": "div" }, "nodeType": "DOM", "props": { "className": "interact-flex-row interact-widget" }, "type": "node" } } }, "systemjs_options": null }, "nodeType": "Scope", "props": {}, "type": "node" } ], "instanceArgs": { "namespace": "html", "tag": "div" }, "nodeType": "DOM", "props": {}, "type": "node" }, "text/html": [ "\n", " \n", "\n" ], "text/plain": [ "Node{WebIO.DOM}(WebIO.DOM(:html, :div), Any[Node{WebIO.DOM}(WebIO.DOM(:html, :div), Any[Scope(Node{WebIO.DOM}(WebIO.DOM(:html, :div), Any[Node{WebIO.DOM}(WebIO.DOM(:html, :div), Any[Node{WebIO.DOM}(WebIO.DOM(:html, :label), Any[nothing], Dict{Symbol,Any}(:className => \"interact \",:style => Dict{Any,Any}(:padding => \"5px 10px 0px 10px\")))], Dict{Symbol,Any}(:className => \"interact-flex-row-left\")), Node{WebIO.DOM}(WebIO.DOM(:html, :div), Any[Node{WebIO.DOM}(WebIO.DOM(:html, :input), Any[], Dict{Symbol,Any}(:max => 1000,:min => 1,:attributes => Dict{Any,Any}(:type => \"range\",Symbol(\"data-bind\") => \"numericValue: index, valueUpdate: 'input', event: {change: function (){this.changes(this.changes()+1)}}\",\"orient\" => \"horizontal\"),:step => 1,:className => \"slider slider is-fullwidth\",:style => Dict{Any,Any}()))], Dict{Symbol,Any}(:className => \"interact-flex-row-center\")), Node{WebIO.DOM}(WebIO.DOM(:html, :div), Any[Node{WebIO.DOM}(WebIO.DOM(:html, :p), Any[], Dict{Symbol,Any}(:attributes => Dict(\"data-bind\" => \"text: formatted_val\")))], Dict{Symbol,Any}(:className => \"interact-flex-row-right\"))], Dict{Symbol,Any}(:className => \"interact-flex-row interact-widget\")), Dict{String,Tuple{Observables.AbstractObservable,Union{Nothing, Bool}}}(\"changes\" => (Observable{Int64} with 1 listeners. Value:\n", "0, nothing),\"index\" => (Observable{Int64} with 2 listeners. Value:\n", "1, nothing)), Set(String[]), nothing, Asset[Asset(\"js\", \"knockout\", \"/Users/dpsanders/.julia/packages/Knockout/IP1uR/src/../assets/knockout.js\"), Asset(\"js\", \"knockout_punches\", \"/Users/dpsanders/.julia/packages/Knockout/IP1uR/src/../assets/knockout_punches.js\"), Asset(\"js\", nothing, \"/Users/dpsanders/.julia/packages/InteractBase/9mFwe/src/../assets/all.js\"), Asset(\"css\", nothing, \"/Users/dpsanders/.julia/packages/InteractBase/9mFwe/src/../assets/style.css\"), Asset(\"css\", nothing, \"/Users/dpsanders/.julia/packages/Interact/cdOnS/src/../assets/bulma_confined.min.css\")], Dict{Any,Any}(\"changes\" => Any[WebIO.JSString(\"(function (val){return (val!=this.model[\\\"changes\\\"]()) ? (this.valueFromJulia[\\\"changes\\\"]=true, this.model[\\\"changes\\\"](val)) : undefined})\")],\"index\" => Any[WebIO.JSString(\"(function (val){return (val!=this.model[\\\"index\\\"]()) ? (this.valueFromJulia[\\\"index\\\"]=true, this.model[\\\"index\\\"](val)) : undefined})\")]), WebIO.ConnectionPool(Channel{Any}(sz_max:32,sz_curr:0), Set(AbstractConnection[]), Base.GenericCondition{Base.AlwaysLockedST}(Base.InvasiveLinkedList{Task}(Task (runnable) @0x000000012f2a8250, Task (runnable) @0x000000012f2a8250), Base.AlwaysLockedST(1))), WebIO.JSString[WebIO.JSString(\"function () {\\n var handler = (function (ko, koPunches) {\\n ko.punches.enableAll();\\n ko.bindingHandlers.numericValue = {\\n init: function(element, valueAccessor, allBindings, data, context) {\\n var stringified = ko.observable(ko.unwrap(valueAccessor()));\\n stringified.subscribe(function(value) {\\n var val = parseFloat(value);\\n if (!isNaN(val)) {\\n valueAccessor()(val);\\n }\\n });\\n valueAccessor().subscribe(function(value) {\\n var str = JSON.stringify(value);\\n if ((str == \\\"0\\\") && ([\\\"-0\\\", \\\"-0.\\\"].indexOf(stringified()) >= 0))\\n return;\\n if ([\\\"null\\\", \\\"\\\"].indexOf(str) >= 0)\\n return;\\n stringified(str);\\n });\\n ko.applyBindingsToNode(\\n element,\\n {\\n value: stringified,\\n valueUpdate: allBindings.get('valueUpdate'),\\n },\\n context,\\n );\\n }\\n };\\n var json_data = {\\\"formatted_vals\\\":[\\\"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\\\",\\\"311\\\",\\\"312\\\",\\\"313\\\",\\\"314\\\",\\\"315\\\",\\\"316\\\",\\\"317\\\",\\\"318\\\",\\\"319\\\",\\\"320\\\",\\\"321\\\",\\\"322\\\",\\\"323\\\",\\\"324\\\",\\\"325\\\",\\\"326\\\",\\\"327\\\",\\\"328\\\",\\\"329\\\",\\\"330\\\",\\\"331\\\",\\\"332\\\",\\\"333\\\",\\\"334\\\",\\\"335\\\",\\\"336\\\",\\\"337\\\",\\\"338\\\",\\\"339\\\",\\\"340\\\",\\\"341\\\",\\\"342\\\",\\\"343\\\",\\\"344\\\",\\\"345\\\",\\\"346\\\",\\\"347\\\",\\\"348\\\",\\\"349\\\",\\\"350\\\",\\\"351\\\",\\\"352\\\",\\\"353\\\",\\\"354\\\",\\\"355\\\",\\\"356\\\",\\\"357\\\",\\\"358\\\",\\\"359\\\",\\\"360\\\",\\\"361\\\",\\\"362\\\",\\\"363\\\",\\\"364\\\",\\\"365\\\",\\\"366\\\",\\\"367\\\",\\\"368\\\",\\\"369\\\",\\\"370\\\",\\\"371\\\",\\\"372\\\",\\\"373\\\",\\\"374\\\",\\\"375\\\",\\\"376\\\",\\\"377\\\",\\\"378\\\",\\\"379\\\",\\\"380\\\",\\\"381\\\",\\\"382\\\",\\\"383\\\",\\\"384\\\",\\\"385\\\",\\\"386\\\",\\\"387\\\",\\\"388\\\",\\\"389\\\",\\\"390\\\",\\\"391\\\",\\\"392\\\",\\\"393\\\",\\\"394\\\",\\\"395\\\",\\\"396\\\",\\\"397\\\",\\\"398\\\",\\\"399\\\",\\\"400\\\",\\\"401\\\",\\\"402\\\",\\\"403\\\",\\\"404\\\",\\\"405\\\",\\\"406\\\",\\\"407\\\",\\\"408\\\",\\\"409\\\",\\\"410\\\",\\\"411\\\",\\\"412\\\",\\\"413\\\",\\\"414\\\",\\\"415\\\",\\\"416\\\",\\\"417\\\",\\\"418\\\",\\\"419\\\",\\\"420\\\",\\\"421\\\",\\\"422\\\",\\\"423\\\",\\\"424\\\",\\\"425\\\",\\\"426\\\",\\\"427\\\",\\\"428\\\",\\\"429\\\",\\\"430\\\",\\\"431\\\",\\\"432\\\",\\\"433\\\",\\\"434\\\",\\\"435\\\",\\\"436\\\",\\\"437\\\",\\\"438\\\",\\\"439\\\",\\\"440\\\",\\\"441\\\",\\\"442\\\",\\\"443\\\",\\\"444\\\",\\\"445\\\",\\\"446\\\",\\\"447\\\",\\\"448\\\",\\\"449\\\",\\\"450\\\",\\\"451\\\",\\\"452\\\",\\\"453\\\",\\\"454\\\",\\\"455\\\",\\\"456\\\",\\\"457\\\",\\\"458\\\",\\\"459\\\",\\\"460\\\",\\\"461\\\",\\\"462\\\",\\\"463\\\",\\\"464\\\",\\\"465\\\",\\\"466\\\",\\\"467\\\",\\\"468\\\",\\\"469\\\",\\\"470\\\",\\\"471\\\",\\\"472\\\",\\\"473\\\",\\\"474\\\",\\\"475\\\",\\\"476\\\",\\\"477\\\",\\\"478\\\",\\\"479\\\",\\\"480\\\",\\\"481\\\",\\\"482\\\",\\\"483\\\",\\\"484\\\",\\\"485\\\",\\\"486\\\",\\\"487\\\",\\\"488\\\",\\\"489\\\",\\\"490\\\",\\\"491\\\",\\\"492\\\",\\\"493\\\",\\\"494\\\",\\\"495\\\",\\\"496\\\",\\\"497\\\",\\\"498\\\",\\\"499\\\",\\\"500\\\",\\\"501\\\",\\\"502\\\",\\\"503\\\",\\\"504\\\",\\\"505\\\",\\\"506\\\",\\\"507\\\",\\\"508\\\",\\\"509\\\",\\\"510\\\",\\\"511\\\",\\\"512\\\",\\\"513\\\",\\\"514\\\",\\\"515\\\",\\\"516\\\",\\\"517\\\",\\\"518\\\",\\\"519\\\",\\\"520\\\",\\\"521\\\",\\\"522\\\",\\\"523\\\",\\\"524\\\",\\\"525\\\",\\\"526\\\",\\\"527\\\",\\\"528\\\",\\\"529\\\",\\\"530\\\",\\\"531\\\",\\\"532\\\",\\\"533\\\",\\\"534\\\",\\\"535\\\",\\\"536\\\",\\\"537\\\",\\\"538\\\",\\\"539\\\",\\\"540\\\",\\\"541\\\",\\\"542\\\",\\\"543\\\",\\\"544\\\",\\\"545\\\",\\\"546\\\",\\\"547\\\",\\\"548\\\",\\\"549\\\",\\\"550\\\",\\\"551\\\",\\\"552\\\",\\\"553\\\",\\\"554\\\",\\\"555\\\",\\\"556\\\",\\\"557\\\",\\\"558\\\",\\\"559\\\",\\\"560\\\",\\\"561\\\",\\\"562\\\",\\\"563\\\",\\\"564\\\",\\\"565\\\",\\\"566\\\",\\\"567\\\",\\\"568\\\",\\\"569\\\",\\\"570\\\",\\\"571\\\",\\\"572\\\",\\\"573\\\",\\\"574\\\",\\\"575\\\",\\\"576\\\",\\\"577\\\",\\\"578\\\",\\\"579\\\",\\\"580\\\",\\\"581\\\",\\\"582\\\",\\\"583\\\",\\\"584\\\",\\\"585\\\",\\\"586\\\",\\\"587\\\",\\\"588\\\",\\\"589\\\",\\\"590\\\",\\\"591\\\",\\\"592\\\",\\\"593\\\",\\\"594\\\",\\\"595\\\",\\\"596\\\",\\\"597\\\",\\\"598\\\",\\\"599\\\",\\\"600\\\",\\\"601\\\",\\\"602\\\",\\\"603\\\",\\\"604\\\",\\\"605\\\",\\\"606\\\",\\\"607\\\",\\\"608\\\",\\\"609\\\",\\\"610\\\",\\\"611\\\",\\\"612\\\",\\\"613\\\",\\\"614\\\",\\\"615\\\",\\\"616\\\",\\\"617\\\",\\\"618\\\",\\\"619\\\",\\\"620\\\",\\\"621\\\",\\\"622\\\",\\\"623\\\",\\\"624\\\",\\\"625\\\",\\\"626\\\",\\\"627\\\",\\\"628\\\",\\\"629\\\",\\\"630\\\",\\\"631\\\",\\\"632\\\",\\\"633\\\",\\\"634\\\",\\\"635\\\",\\\"636\\\",\\\"637\\\",\\\"638\\\",\\\"639\\\",\\\"640\\\",\\\"641\\\",\\\"642\\\",\\\"643\\\",\\\"644\\\",\\\"645\\\",\\\"646\\\",\\\"647\\\",\\\"648\\\",\\\"649\\\",\\\"650\\\",\\\"651\\\",\\\"652\\\",\\\"653\\\",\\\"654\\\",\\\"655\\\",\\\"656\\\",\\\"657\\\",\\\"658\\\",\\\"659\\\",\\\"660\\\",\\\"661\\\",\\\"662\\\",\\\"663\\\",\\\"664\\\",\\\"665\\\",\\\"666\\\",\\\"667\\\",\\\"668\\\",\\\"669\\\",\\\"670\\\",\\\"671\\\",\\\"672\\\",\\\"673\\\",\\\"674\\\",\\\"675\\\",\\\"676\\\",\\\"677\\\",\\\"678\\\",\\\"679\\\",\\\"680\\\",\\\"681\\\",\\\"682\\\",\\\"683\\\",\\\"684\\\",\\\"685\\\",\\\"686\\\",\\\"687\\\",\\\"688\\\",\\\"689\\\",\\\"690\\\",\\\"691\\\",\\\"692\\\",\\\"693\\\",\\\"694\\\",\\\"695\\\",\\\"696\\\",\\\"697\\\",\\\"698\\\",\\\"699\\\",\\\"700\\\",\\\"701\\\",\\\"702\\\",\\\"703\\\",\\\"704\\\",\\\"705\\\",\\\"706\\\",\\\"707\\\",\\\"708\\\",\\\"709\\\",\\\"710\\\",\\\"711\\\",\\\"712\\\",\\\"713\\\",\\\"714\\\",\\\"715\\\",\\\"716\\\",\\\"717\\\",\\\"718\\\",\\\"719\\\",\\\"720\\\",\\\"721\\\",\\\"722\\\",\\\"723\\\",\\\"724\\\",\\\"725\\\",\\\"726\\\",\\\"727\\\",\\\"728\\\",\\\"729\\\",\\\"730\\\",\\\"731\\\",\\\"732\\\",\\\"733\\\",\\\"734\\\",\\\"735\\\",\\\"736\\\",\\\"737\\\",\\\"738\\\",\\\"739\\\",\\\"740\\\",\\\"741\\\",\\\"742\\\",\\\"743\\\",\\\"744\\\",\\\"745\\\",\\\"746\\\",\\\"747\\\",\\\"748\\\",\\\"749\\\",\\\"750\\\",\\\"751\\\",\\\"752\\\",\\\"753\\\",\\\"754\\\",\\\"755\\\",\\\"756\\\",\\\"757\\\",\\\"758\\\",\\\"759\\\",\\\"760\\\",\\\"761\\\",\\\"762\\\",\\\"763\\\",\\\"764\\\",\\\"765\\\",\\\"766\\\",\\\"767\\\",\\\"768\\\",\\\"769\\\",\\\"770\\\",\\\"771\\\",\\\"772\\\",\\\"773\\\",\\\"774\\\",\\\"775\\\",\\\"776\\\",\\\"777\\\",\\\"778\\\",\\\"779\\\",\\\"780\\\",\\\"781\\\",\\\"782\\\",\\\"783\\\",\\\"784\\\",\\\"785\\\",\\\"786\\\",\\\"787\\\",\\\"788\\\",\\\"789\\\",\\\"790\\\",\\\"791\\\",\\\"792\\\",\\\"793\\\",\\\"794\\\",\\\"795\\\",\\\"796\\\",\\\"797\\\",\\\"798\\\",\\\"799\\\",\\\"800\\\",\\\"801\\\",\\\"802\\\",\\\"803\\\",\\\"804\\\",\\\"805\\\",\\\"806\\\",\\\"807\\\",\\\"808\\\",\\\"809\\\",\\\"810\\\",\\\"811\\\",\\\"812\\\",\\\"813\\\",\\\"814\\\",\\\"815\\\",\\\"816\\\",\\\"817\\\",\\\"818\\\",\\\"819\\\",\\\"820\\\",\\\"821\\\",\\\"822\\\",\\\"823\\\",\\\"824\\\",\\\"825\\\",\\\"826\\\",\\\"827\\\",\\\"828\\\",\\\"829\\\",\\\"830\\\",\\\"831\\\",\\\"832\\\",\\\"833\\\",\\\"834\\\",\\\"835\\\",\\\"836\\\",\\\"837\\\",\\\"838\\\",\\\"839\\\",\\\"840\\\",\\\"841\\\",\\\"842\\\",\\\"843\\\",\\\"844\\\",\\\"845\\\",\\\"846\\\",\\\"847\\\",\\\"848\\\",\\\"849\\\",\\\"850\\\",\\\"851\\\",\\\"852\\\",\\\"853\\\",\\\"854\\\",\\\"855\\\",\\\"856\\\",\\\"857\\\",\\\"858\\\",\\\"859\\\",\\\"860\\\",\\\"861\\\",\\\"862\\\",\\\"863\\\",\\\"864\\\",\\\"865\\\",\\\"866\\\",\\\"867\\\",\\\"868\\\",\\\"869\\\",\\\"870\\\",\\\"871\\\",\\\"872\\\",\\\"873\\\",\\\"874\\\",\\\"875\\\",\\\"876\\\",\\\"877\\\",\\\"878\\\",\\\"879\\\",\\\"880\\\",\\\"881\\\",\\\"882\\\",\\\"883\\\",\\\"884\\\",\\\"885\\\",\\\"886\\\",\\\"887\\\",\\\"888\\\",\\\"889\\\",\\\"890\\\",\\\"891\\\",\\\"892\\\",\\\"893\\\",\\\"894\\\",\\\"895\\\",\\\"896\\\",\\\"897\\\",\\\"898\\\",\\\"899\\\",\\\"900\\\",\\\"901\\\",\\\"902\\\",\\\"903\\\",\\\"904\\\",\\\"905\\\",\\\"906\\\",\\\"907\\\",\\\"908\\\",\\\"909\\\",\\\"910\\\",\\\"911\\\",\\\"912\\\",\\\"913\\\",\\\"914\\\",\\\"915\\\",\\\"916\\\",\\\"917\\\",\\\"918\\\",\\\"919\\\",\\\"920\\\",\\\"921\\\",\\\"922\\\",\\\"923\\\",\\\"924\\\",\\\"925\\\",\\\"926\\\",\\\"927\\\",\\\"928\\\",\\\"929\\\",\\\"930\\\",\\\"931\\\",\\\"932\\\",\\\"933\\\",\\\"934\\\",\\\"935\\\",\\\"936\\\",\\\"937\\\",\\\"938\\\",\\\"939\\\",\\\"940\\\",\\\"941\\\",\\\"942\\\",\\\"943\\\",\\\"944\\\",\\\"945\\\",\\\"946\\\",\\\"947\\\",\\\"948\\\",\\\"949\\\",\\\"950\\\",\\\"951\\\",\\\"952\\\",\\\"953\\\",\\\"954\\\",\\\"955\\\",\\\"956\\\",\\\"957\\\",\\\"958\\\",\\\"959\\\",\\\"960\\\",\\\"961\\\",\\\"962\\\",\\\"963\\\",\\\"964\\\",\\\"965\\\",\\\"966\\\",\\\"967\\\",\\\"968\\\",\\\"969\\\",\\\"970\\\",\\\"971\\\",\\\"972\\\",\\\"973\\\",\\\"974\\\",\\\"975\\\",\\\"976\\\",\\\"977\\\",\\\"978\\\",\\\"979\\\",\\\"980\\\",\\\"981\\\",\\\"982\\\",\\\"983\\\",\\\"984\\\",\\\"985\\\",\\\"986\\\",\\\"987\\\",\\\"988\\\",\\\"989\\\",\\\"990\\\",\\\"991\\\",\\\"992\\\",\\\"993\\\",\\\"994\\\",\\\"995\\\",\\\"996\\\",\\\"997\\\",\\\"998\\\",\\\"999\\\",\\\"1000\\\"],\\\"changes\\\":WebIO.getval({\\\"name\\\":\\\"changes\\\",\\\"scope\\\":\\\"12081152369788741163\\\",\\\"id\\\":\\\"ob_34\\\",\\\"type\\\":\\\"observable\\\"}),\\\"index\\\":WebIO.getval({\\\"name\\\":\\\"index\\\",\\\"scope\\\":\\\"12081152369788741163\\\",\\\"id\\\":\\\"ob_33\\\",\\\"type\\\":\\\"observable\\\"})};\\n var self = this;\\n function AppViewModel() {\\n for (var key in json_data) {\\n var el = json_data[key];\\n this[key] = Array.isArray(el) ? ko.observableArray(el) : ko.observable(el);\\n }\\n \\n [this[\\\"formatted_val\\\"]=ko.computed( function(){\\n return this.formatted_vals()[parseInt(this.index())-(1)];\\n }\\n,this)]\\n [this[\\\"changes\\\"].subscribe((function (val){!(this.valueFromJulia[\\\"changes\\\"]) ? (WebIO.setval({\\\"name\\\":\\\"changes\\\",\\\"scope\\\":\\\"12081152369788741163\\\",\\\"id\\\":\\\"ob_34\\\",\\\"type\\\":\\\"observable\\\"},val)) : undefined; return this.valueFromJulia[\\\"changes\\\"]=false}),self),this[\\\"index\\\"].subscribe((function (val){!(this.valueFromJulia[\\\"index\\\"]) ? (WebIO.setval({\\\"name\\\":\\\"index\\\",\\\"scope\\\":\\\"12081152369788741163\\\",\\\"id\\\":\\\"ob_33\\\",\\\"type\\\":\\\"observable\\\"},val)) : undefined; return this.valueFromJulia[\\\"index\\\"]=false}),self)]\\n \\n }\\n self.model = new AppViewModel();\\n self.valueFromJulia = {};\\n for (var key in json_data) {\\n self.valueFromJulia[key] = false;\\n }\\n ko.applyBindings(self.model, self.dom);\\n}\\n);\\n (WebIO.importBlock({\\\"data\\\":[{\\\"name\\\":\\\"knockout\\\",\\\"type\\\":\\\"js\\\",\\\"url\\\":\\\"/assetserver/800fa077652c804a9c5f68b6c1e29c6c61f85df7-knockout.js\\\"},{\\\"name\\\":\\\"knockout_punches\\\",\\\"type\\\":\\\"js\\\",\\\"url\\\":\\\"/assetserver/81e3f253b58efa296c3c65b00e2bf7b25de6cca9-knockout_punches.js\\\"}],\\\"type\\\":\\\"async_block\\\"})).then((imports) => handler.apply(this, imports));\\n}\\n\")])], Dict{Symbol,Any}(:className => \"field interact-widget\")), Observable{Any} with 0 listeners. Value:\n", "Node{WebIO.DOM}(WebIO.DOM(:html, :div), Any[Plot{Plots.GRBackend() n=1}], Dict{Symbol,Any}(:className => \"interact-flex-row interact-widget\"))], Dict{Symbol,Any}())" ] }, "execution_count": 44, "metadata": { "application/vnd.webio.node+json": { "kernelId": "d59a816c-9a2c-4330-8c1f-213f8e4252cb" } }, "output_type": "execute_result" } ], "source": [ "end_T = 1000\n", "@manipulate for T in slider(1:end_T, value=1)\n", " I_result = run_infection(T)\n", "\n", " plot(I_result, m=:o)\n", " \n", " xlims!(0, end_T)\n", " ylims!(0, 10)\n", "end" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Exponential growth" ] }, { "cell_type": "code", "execution_count": 46, "metadata": {}, "outputs": [ { "data": { "image/svg+xml": [ "\n", "\n", "\n", " \n", " \n", " \n", "\n", "\n", "\n", " \n", " \n", " \n", "\n", "\n", "\n", " \n", " \n", " \n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "0\n", "\n", "\n", "250\n", "\n", "\n", "500\n", "\n", "\n", "750\n", "\n", "\n", "1000\n", "\n", "\n", "0\n", "\n", "\n", "5.0×10\n", "\n", "\n", "3\n", "\n", "\n", "1.0×10\n", "\n", "\n", "4\n", "\n", "\n", "1.5×10\n", "\n", "\n", "4\n", "\n", "\n", "2.0×10\n", "\n", "\n", "4\n", "\n", "\n", "\n", "\n", "\n", "\n", "y1\n", "\n", "\n" ] }, "execution_count": 46, "metadata": {}, "output_type": "execute_result" } ], "source": [ "plot(run_infection(1000))" ] }, { "cell_type": "code", "execution_count": 47, "metadata": {}, "outputs": [ { "data": { "image/svg+xml": [ "\n", "\n", "\n", " \n", " \n", " \n", "\n", "\n", "\n", " \n", " \n", " \n", "\n", "\n", "\n", " \n", " \n", " \n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "0\n", "\n", "\n", "250\n", "\n", "\n", "500\n", "\n", "\n", "750\n", "\n", "\n", "1000\n", "\n", "\n", "10\n", "\n", "\n", "0\n", "\n", "\n", "10\n", "\n", "\n", "1\n", "\n", "\n", "10\n", "\n", "\n", "2\n", "\n", "\n", "10\n", "\n", "\n", "3\n", "\n", "\n", "10\n", "\n", "\n", "4\n", "\n", "\n", "\n", "\n", "\n", "\n", "y1\n", "\n", "\n" ] }, "execution_count": 47, "metadata": {}, "output_type": "execute_result" } ], "source": [ "plot(run_infection(1000), yscale=:log10)" ] }, { "cell_type": "code", "execution_count": 50, "metadata": {}, "outputs": [ { "data": { "image/svg+xml": [ "\n", "\n", "\n", " \n", " \n", " \n", "\n", "\n", "\n", " \n", " \n", " \n", "\n", "\n", "\n", " \n", " \n", " \n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "0\n", "\n", "\n", "250\n", "\n", "\n", "500\n", "\n", "\n", "750\n", "\n", "\n", "1000\n", "\n", "\n", "0\n", "\n", "\n", "1\n", "\n", "\n", "2\n", "\n", "\n", "3\n", "\n", "\n", "4\n", "\n", "\n", "log(I_n)\n", "\n", "\n", "\n", "\n", "\n", "\n", "y1\n", "\n", "\n" ] }, "execution_count": 50, "metadata": {}, "output_type": "execute_result" } ], "source": [ "I_result = run_infection(1000)\n", "\n", "plot(log10.(I_result)) # log of each element in I_result\n", "ylabel!(\"log(I_n)\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "$\\log(I_n) = a n + b$" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Take exponentials of both sides:" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "$I_n = \\exp(an + b) = C e^{a n}$" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Solve $I_{n+1} = \\lambda I_n$:" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "$I_n = \\lambda^n I_0$" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "$\\log(\\lambda^n) = n \\log(\\lambda)$" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Logistic growth" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Exp growth is unrealistic: Assumes that there are always more people to infect -- wrong (finite population)." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "$I_{n+1} = I_n + c I_n$" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Each individual will be in contact with a fraction $\\alpha$ of the population. At each contact there will a probability $p$ that you infect each person.\n", "\n", "Number of contacts = $\\alpha N$\n", "\n", "So $c = p \\alpha N$" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Original model:\n", "\n", "$I_{n+1} = I_n + (p \\alpha N) I_n$ -- good approximation when almost everybody still susceptible" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "New model:\n", "\n", "Can only infect uninfected people!" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "$I_{n+1} = I_n + (p \\alpha S_n) I_n$" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "$I_{n+1} = I_n + [p \\alpha (N - I_n)] I_n = f(I_n)$\n", "\n", "$I_{n+1} = I_n + \\beta(I_n, S_n) I_n = f(I_n)$" ] }, { "cell_type": "code", "execution_count": 56, "metadata": { "scrolled": true }, "outputs": [ { "data": { "text/plain": [ "run_infection (generic function with 2 methods)" ] }, "execution_count": 56, "metadata": {}, "output_type": "execute_result" } ], "source": [ "p = 0.02\n", "α = 0.01\n", "N = 1000\n", "\n", "β(I, S) = p * α * S\n", "\n", "function run_infection(T=20) # default\n", "\n", " I = zeros(T)\n", " I[1] = I_0\n", "\n", " for n in 1:T-1\n", " I[n+1] = I[n] + β(I[n], N - I[n]) * I[n]\n", " end\n", "\n", " return I\n", "end" ] }, { "cell_type": "code", "execution_count": 57, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "20-element Array{Float64,1}:\n", " 1.0\n", " 1.1998\n", " 1.439472095992\n", " 1.7269520992073721\n", " 2.071746046338255\n", " 2.4852368292698026\n", " 2.9810489147042514\n", " 3.57548136711873\n", " 4.288020827141153\n", " 5.141947568046585\n", " 6.165049156697394\n", " 7.390457421815974\n", " 8.857625133998434\n", " 10.613458656195233\n", " 12.713621286504926\n", " 15.224018310562577\n", " 18.222467825971023\n", " 21.80054972443152\n", " 26.065606875660343\n", " 31.14284507843312" ] }, "execution_count": 57, "metadata": {}, "output_type": "execute_result" } ], "source": [ "I = run_infection(20)" ] }, { "cell_type": "code", "execution_count": 58, "metadata": {}, "outputs": [ { "data": { "image/svg+xml": [ "\n", "\n", "\n", " \n", " \n", " \n", "\n", "\n", "\n", " \n", " \n", " \n", "\n", "\n", "\n", " \n", " \n", " \n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "5\n", "\n", "\n", "10\n", "\n", "\n", "15\n", "\n", "\n", "20\n", "\n", "\n", "5\n", "\n", "\n", "10\n", "\n", "\n", "15\n", "\n", "\n", "20\n", "\n", "\n", "25\n", "\n", "\n", "30\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "y1\n", "\n", "\n" ] }, "execution_count": 58, "metadata": {}, "output_type": "execute_result" } ], "source": [ "plot(I, m=:o)" ] }, { "cell_type": "code", "execution_count": 59, "metadata": {}, "outputs": [ { "data": { "image/svg+xml": [ "\n", "\n", "\n", " \n", " \n", " \n", "\n", "\n", "\n", " \n", " \n", " \n", "\n", "\n", "\n", " \n", " \n", " \n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "5\n", "\n", "\n", "10\n", "\n", "\n", "15\n", "\n", "\n", "20\n", "\n", "\n", "10\n", "\n", "\n", "0.0\n", "\n", "\n", "10\n", "\n", "\n", "0.5\n", "\n", "\n", "10\n", "\n", "\n", "1.0\n", "\n", "\n", "10\n", "\n", "\n", "1.5\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "y1\n", "\n", "\n" ] }, "execution_count": 59, "metadata": {}, "output_type": "execute_result" } ], "source": [ "plot(I, m=:o, yscale=:log10)" ] }, { "cell_type": "code", "execution_count": 61, "metadata": {}, "outputs": [ { "data": { "image/svg+xml": [ "\n", "\n", "\n", " \n", " \n", " \n", "\n", "\n", "\n", " \n", " \n", " \n", "\n", "\n", "\n", " \n", " \n", " \n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "0\n", "\n", "\n", "25\n", "\n", "\n", "50\n", "\n", "\n", "75\n", "\n", "\n", "100\n", "\n", "\n", "10\n", "\n", "\n", "0\n", "\n", "\n", "10\n", "\n", "\n", "1\n", "\n", "\n", "10\n", "\n", "\n", "2\n", "\n", "\n", "10\n", "\n", "\n", "3\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "y1\n", "\n", "\n" ] }, "execution_count": 61, "metadata": {}, "output_type": "execute_result" } ], "source": [ "I = run_infection(100)\n", "plot(I, m=:o, yscale=:log10)" ] }, { "cell_type": "code", "execution_count": 64, "metadata": {}, "outputs": [ { "data": { "image/svg+xml": [ "\n", "\n", "\n", " \n", " \n", " \n", "\n", "\n", "\n", " \n", " \n", " \n", "\n", "\n", "\n", " \n", " \n", " \n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "0\n", "\n", "\n", "25\n", "\n", "\n", "50\n", "\n", "\n", "75\n", "\n", "\n", "100\n", "\n", "\n", "0\n", "\n", "\n", "25\n", "\n", "\n", "50\n", "\n", "\n", "75\n", "\n", "\n", "100\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "y1\n", "\n", "\n" ] }, "execution_count": 64, "metadata": {}, "output_type": "execute_result" } ], "source": [ "p = 0.01\n", "α = 0.1\n", "N = 100\n", "\n", "I = run_infection(100)\n", "plot(I, m=:o)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**Sigmoid** shape -- S-shaped" ] }, { "cell_type": "code", "execution_count": 65, "metadata": {}, "outputs": [ { "data": { "image/svg+xml": [ "\n", "\n", "\n", " \n", " \n", " \n", "\n", "\n", "\n", " \n", " \n", " \n", "\n", "\n", "\n", " \n", " \n", " \n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "0\n", "\n", "\n", "25\n", "\n", "\n", "50\n", "\n", "\n", "75\n", "\n", "\n", "100\n", "\n", "\n", "10\n", "\n", "\n", "0.0\n", "\n", "\n", "10\n", "\n", "\n", "0.5\n", "\n", "\n", "10\n", "\n", "\n", "1.0\n", "\n", "\n", "10\n", "\n", "\n", "1.5\n", "\n", "\n", "10\n", "\n", "\n", "2.0\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "y1\n", "\n", "\n" ] }, "execution_count": 65, "metadata": {}, "output_type": "execute_result" } ], "source": [ "plot(I, m=:o, yscale=:log10)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\"Logistic-type growth\"" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "$I_{n+1} = \\lambda I_n$" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## More realism: Heterogeneity of individuals or groups" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Idea: Instead of modelling population globally, model each individual" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\"Patch model\": Local patches where population is **well mixed**" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Network model: Links between nodes" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Exponential growth:" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "$I_{n+1} = \\lambda_n I_n$ -- growth rate changes in time" ] }, { "cell_type": "code", "execution_count": 66, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0.2767437763441829" ] }, "execution_count": 66, "metadata": {}, "output_type": "execute_result" } ], "source": [ "rand()" ] }, { "cell_type": "code", "execution_count": 67, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0.7089008345855983" ] }, "execution_count": 67, "metadata": {}, "output_type": "execute_result" } ], "source": [ "rand()" ] }, { "cell_type": "code", "execution_count": 68, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0.3789568897206148" ] }, "execution_count": 68, "metadata": {}, "output_type": "execute_result" } ], "source": [ "rand()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "www.random.org" ] }, { "cell_type": "code", "execution_count": 69, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "-0.33523291258515997" ] }, "execution_count": 69, "metadata": {}, "output_type": "execute_result" } ], "source": [ "randn()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": 71, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "run_infection (generic function with 3 methods)" ] }, "execution_count": 71, "metadata": {}, "output_type": "execute_result" } ], "source": [ "p = 0.02\n", "α = 0.01\n", "N = 1000\n", "\n", "\n", "\n", "function run_infection(c_average=1.1, T=20) # default\n", "\n", " I = zeros(T)\n", " I[1] = I_0\n", "\n", " for n in 1:T-1\n", " c = c_average + 0.1*randn()\n", " I[n+1] = I[n] + c * I[n]\n", " end\n", "\n", " return I\n", "end" ] }, { "cell_type": "code", "execution_count": 73, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "100-element Array{Float64,1}:\n", " 1.1794683814069813\n", " 1.0510617699472489\n", " 1.0799811965453343\n", " 1.3160413008055867\n", " 1.0655215426073297\n", " 1.014913328568307\n", " 1.2142141455660913\n", " 0.9952511944053644\n", " 1.1118228511102424\n", " 1.2274911767386665\n", " 1.097194489799497\n", " 1.156157408743076\n", " 1.0138054185809025\n", " ⋮\n", " 1.252209922391299\n", " 1.0305288124096037\n", " 1.1816089517166688\n", " 0.9848866930013738\n", " 1.175520029029598\n", " 1.1695318311722314\n", " 1.1237453859981914\n", " 1.1925550201637143\n", " 0.9331362892813453\n", " 1.0848564135882912\n", " 1.184898469695791\n", " 1.0756350756110384" ] }, "execution_count": 73, "metadata": {}, "output_type": "execute_result" } ], "source": [ "c_average = 1.1\n", "\n", "cs = [c_average + 0.1*randn() for i in 1:100]" ] }, { "cell_type": "code", "execution_count": 74, "metadata": {}, "outputs": [ { "data": { "image/svg+xml": [ "\n", "\n", "\n", " \n", " \n", " \n", "\n", "\n", "\n", " \n", " \n", " \n", "\n", "\n", "\n", " \n", " \n", " \n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "0\n", "\n", "\n", "25\n", "\n", "\n", "50\n", "\n", "\n", "75\n", "\n", "\n", "100\n", "\n", "\n", "0.8\n", "\n", "\n", "0.9\n", "\n", "\n", "1.0\n", "\n", "\n", "1.1\n", "\n", "\n", "1.2\n", "\n", "\n", "1.3\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "y1\n", "\n", "\n" ] }, "execution_count": 74, "metadata": {}, "output_type": "execute_result" } ], "source": [ "scatter(cs)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "@webio": { "lastCommId": "e7ddcbf8f6164cee88c88a68ff1650b4", "lastKernelId": "a7a5b129-5bc8-4f18-873d-1d9becb8ff75" }, "kernelspec": { "display_name": "Julia 1.4.0", "language": "julia", "name": "julia-1.4" }, "language_info": { "file_extension": ".jl", "mimetype": "application/julia", "name": "julia", "version": "1.4.0" } }, "nbformat": 4, "nbformat_minor": 4 }