diff --git a/.gitignore b/.gitignore index 587f911..dce285e 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,3 @@ .ipynb_checkpoints/* *.png *.pdf -.DS_Store diff --git a/02_Coursera_3.ipynb b/02_Coursera_3.ipynb index 70c40fc..8c80293 100644 --- a/02_Coursera_3.ipynb +++ b/02_Coursera_3.ipynb @@ -98,7 +98,7 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 5, "metadata": {}, "outputs": [ { @@ -107,7 +107,7 @@ "approxcos (generic function with 1 method)" ] }, - "execution_count": 7, + "execution_count": 5, "metadata": {}, "output_type": "execute_result" } @@ -128,7 +128,7 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 6, "metadata": {}, "outputs": [], "source": [ @@ -142,7 +142,7 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 7, "metadata": {}, "outputs": [ { @@ -151,7 +151,7 @@ "Plots.GRBackend()" ] }, - "execution_count": 9, + "execution_count": 7, "metadata": {}, "output_type": "execute_result" } @@ -163,7 +163,7 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 8, "metadata": {}, "outputs": [ { @@ -172,103 +172,103 @@ "\n", "\n", "\n", - " \n", + " \n", " \n", " \n", "\n", - "\n", "\n", - " \n", + " \n", " \n", " \n", "\n", - "\n", "\n", - " \n", + " \n", " \n", " \n", "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n" ] }, - "execution_count": 10, + "execution_count": 8, "metadata": {}, "output_type": "execute_result" } diff --git a/03_Coursera_3.ipynb b/03_Coursera_3.ipynb new file mode 100644 index 0000000..cfa7190 --- /dev/null +++ b/03_Coursera_3.ipynb @@ -0,0 +1,1261 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [], + "source": [ + "using Plots\n", + "gr()\n", + "using DelimitedFiles" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "EVDdata = DelimitedFiles.readdlm(\"wikipediaEVDdatesconverted.csv\", ',')\n", + "tvalsfromdata = EVDdata[:,1] \n", + "totalcasesfromdata = EVDdata[:,2];" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "updateSIR (generic function with 1 method)" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "function updateSIR(popnvector)\n", + " susceptibles = popnvector[1];\n", + " infecteds = popnvector[2];\n", + " removeds = popnvector[3];\n", + " newS = susceptibles - λ*susceptibles*infecteds*dt\n", + " newI = infecteds + λ*susceptibles*infecteds*dt - γ*infecteds*dt\n", + " newR = removeds + γ*infecteds*dt\n", + " return [newS newI newR]\n", + "end" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": {}, + "outputs": [], + "source": [ + "# Values for the test run\n", + "λ = 1.47*10^-6 #0.0005\n", + "γ = 0.125\n", + "dt = 0.5\n", + "tfinal = 610\n", + "s0 = 1.0*10^5 #150.0\n", + "i0 = 20.\n", + "r0 = 0.0;\n" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": {}, + "outputs": [], + "source": [ + "nsteps = round(Int64,tfinal/dt)\n", + "resultvals = Array{Float64}(undef,nsteps+1,3)\n", + "timevec = Array{Float64}(undef,nsteps+1)\n", + "resultvals[1,:] = [s0, i0, r0]\n", + "timevec[1] = 0.;" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": {}, + "outputs": [], + "source": [ + "for step = 1:nsteps\n", + " resultvals[step+1,:] = updateSIR(resultvals[step,:])\n", + " timevec[step+1] = timevec[step] + dt\n", + "end" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": {}, + "outputs": [], + "source": [ + "ivals = resultvals[:,2];\n", + "rvals = resultvals[:,3];\n", + "cvals = ivals + rvals;" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "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", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n" + ] + }, + "execution_count": 18, + "metadata": {}, + "output_type": "execute_result" + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "GKS: character ignored due to unicode error\n", + "GKS: character ignored due to unicode error\n", + "GKS: character ignored due to unicode error\n", + "GKS: character ignored due to unicode error\n", + "GKS: character ignored due to unicode error\n", + "GKS: character ignored due to unicode error\n", + "GKS: character ignored due to unicode error\n", + "GKS: character ignored due to unicode error\n", + "GKS: character ignored due to unicode error\n", + "GKS: character ignored due to unicode error\n", + "GKS: character ignored due to unicode error\n", + "GKS: character ignored due to unicode error\n", + "GKS: character ignored due to unicode error\n", + "GKS: character ignored due to unicode error\n", + "GKS: character ignored due to unicode error\n", + "GKS: character ignored due to unicode error\n", + "GKS: character ignored due to unicode error\n", + "GKS: character ignored due to unicode error\n", + "GKS: character ignored due to unicode error\n", + "GKS: character ignored due to unicode error\n", + "GKS: character ignored due to unicode error\n", + "GKS: character ignored due to unicode error\n", + "GKS: character ignored due to unicode error\n", + "GKS: character ignored due to unicode error\n", + "GKS: character ignored due to unicode error\n", + "GKS: character ignored due to unicode error\n", + "GKS: character ignored due to unicode error\n", + "GKS: character ignored due to unicode error\n", + "GKS: character ignored due to unicode error\n", + "GKS: character ignored due to unicode error\n", + "GKS: character ignored due to unicode error\n", + "GKS: character ignored due to unicode error\n", + "GKS: character ignored due to unicode error\n" + ] + } + ], + "source": [ + "plot(timevec,cvals,\n", + " label = \"Model Values\",\n", + " xlabel = \"Epidemic Day\",\n", + " ylabel = \"Number of cases to date\",\n", + " title = \"Model vs Data\"\n", + ")\n", + "\n", + "plot!(tvalsfromdata,totalcasesfromdata,\n", + " legend=:right,\n", + " line=:scatter,\n", + " label=\"Reported number of cases\"\n", + ")" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "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", + "\n", + "\n", + "\n", + "\n" + ] + }, + "execution_count": 19, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "f(x) = 5 * x^2 + 3 * x - 20\n", + "plot(f, -10:10) " + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "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", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n" + ] + }, + "execution_count": 20, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "plot!(zero,-10,10)" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "f (generic function with 1 method)" + ] + }, + "execution_count": 21, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "f(x) = -9*x^2 + 3*x + 6" + ] + }, + { + "cell_type": "code", + "execution_count": 22, + "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" + ] + }, + "execution_count": 22, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "plot(f,-2,2)" + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "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", + "\n", + "\n" + ] + }, + "execution_count": 23, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "plot(f)" + ] + }, + { + "cell_type": "code", + "execution_count": 24, + "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" + ] + }, + "execution_count": 24, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "plot(f,-2:2)" + ] + }, + { + "cell_type": "code", + "execution_count": 25, + "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", + "\n", + "\n" + ] + }, + "execution_count": 25, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "plot(-2,2,f)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Julia 1.2.0", + "language": "julia", + "name": "julia-1.2" + }, + "language_info": { + "file_extension": ".jl", + "mimetype": "application/julia", + "name": "julia", + "version": "1.2.0" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +}