-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix incompatibility with MyBinder in notebooks
- Loading branch information
1 parent
c8710a3
commit 3314c2b
Showing
2 changed files
with
1 addition
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
{"cells": [{"cell_type": "markdown", "metadata": {}, "source": ["#################################################################\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t #<br>\n", "Basic plot for two-strain SIR model:<br>\n", "Bifurcation diagram for one parameter<br>\n", "##################################################################"]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["import sys\n", "import numpy as np\n", "import matplotlib as mpl\n", "mpl.use('TkAgg')\n", "from matplotlib.font_manager import FontProperties \n", "import matplotlib.pyplot as plt\n", "from two_strain import *"]}, {"cell_type": "markdown", "metadata": {}, "source": ["Run parameters"]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["run_num = 1 # sys.argv[1]\n", "end_time = 1000*365\n", "output_interval = 365.0 # if not 365., need to adjust strobe interval\n", "step_size = 1.0\n", "sweep_par = \"beta[0]\" # e.g., \"beta[0]\", \"a[1]\", \"alpha[0]\"\n", "par_min = 1.0/7.0\n", "par_max = 7.0/7.0\n", "n_points = 40 # number of points in parameter range\n", "n_strobes = 50 # number of years to sample"]}, {"cell_type": "markdown", "metadata": {}, "source": ["Strain parameters, including initial conditions"]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["beta = np.array([5, 5])/7.0\n", "epsilon = 0.1\n", "gamma = np.array([1, 1])/7.0\n", "mu = 1/(10*365.0)\n", "alpha = np.array([1., 1.])\n", "a = np.array([1., 1.])\n", "omega = 2*np.pi/365.\n", "obs_sd = 0.01"]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["NSS = 0.2\n", "NIS = 1e-3\n", "NRS = 0.02\n", "NRI = 0.0\n", "NSI = 1e-3\n", "NSR = 0.02\n", "NIR = 0.0"]}, {"cell_type": "markdown", "metadata": {}, "source": ["Organize and run simulations"]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["SI = np.array([NSS, NIS, NRS, NRI, NSI, NSR, NIR], dtype=\"object\")\n", "ic = np.array([NSS, NIS, NRS, NRI, NSI, NSR, NIR, 1-np.sum(SI)], dtype=\"object\")\n", "par_vals = np.linspace(par_min, par_max, n_points)\n", "bif_vals = np.zeros((len(par_vals), n_strobes))\n", "for i in range(len(par_vals)):\n", " print('Running value %d of %d' % (i+1,len(par_vals)))\n", " exec(sweep_par + \" = par_vals[i]\")\n", " params = np.array([gamma, mu, alpha, a, omega, beta, epsilon], dtype=\"object\")\n", " output = run_two_strain(end_time, output_interval, step_size, params, ic)\n", " I = output[:, 1] + output[:, 6] # NIS + NIR\n", " bif_vals[i, :] = I[-n_strobes:len(I)]"]}, {"cell_type": "markdown", "metadata": {}, "source": ["Plot output"]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["plt.plot(par_vals, bif_vals, '.k')\n", "plt.xlabel(sweep_par)\n", "plt.ylabel(\"NIS + NIR\")\n", "plt.xlim([par_min, par_max])\n", "plt.show()\n", "plt.savefig(\"bifurcation_\" + sweep_par + \".png\")\n", "plt.close()"]}], "metadata": {"kernelspec": {"display_name": "Python 3", "language": "python", "name": "python3"}, "language_info": {"codemirror_mode": {"name": "ipython", "version": 3}, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.6.4"}}, "nbformat": 4, "nbformat_minor": 2} | ||
{"cells": [{"cell_type": "markdown", "metadata": {}, "source": ["#################################################################\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t #<br>\n", "Basic plot for two-strain SIR model:<br>\n", "Bifurcation diagram for one parameter<br>\n", "##################################################################"]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["import sys\n", "import numpy as np\n", "import matplotlib as mpl\n", "from matplotlib.font_manager import FontProperties \n", "import matplotlib.pyplot as plt\n", "from two_strain import *"]}, {"cell_type": "markdown", "metadata": {}, "source": ["Run parameters"]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["run_num = 1 # sys.argv[1]\n", "end_time = 1000*365\n", "output_interval = 365.0 # if not 365., need to adjust strobe interval\n", "step_size = 1.0\n", "sweep_par = \"beta[0]\" # e.g., \"beta[0]\", \"a[1]\", \"alpha[0]\"\n", "par_min = 1.0/7.0\n", "par_max = 7.0/7.0\n", "n_points = 40 # number of points in parameter range\n", "n_strobes = 50 # number of years to sample"]}, {"cell_type": "markdown", "metadata": {}, "source": ["Strain parameters, including initial conditions"]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["beta = np.array([5, 5])/7.0\n", "epsilon = 0.1\n", "gamma = np.array([1, 1])/7.0\n", "mu = 1/(10*365.0)\n", "alpha = np.array([1., 1.])\n", "a = np.array([1., 1.])\n", "omega = 2*np.pi/365.\n", "obs_sd = 0.01"]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["NSS = 0.2\n", "NIS = 1e-3\n", "NRS = 0.02\n", "NRI = 0.0\n", "NSI = 1e-3\n", "NSR = 0.02\n", "NIR = 0.0"]}, {"cell_type": "markdown", "metadata": {}, "source": ["Organize and run simulations"]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["SI = np.array([NSS, NIS, NRS, NRI, NSI, NSR, NIR], dtype=\"object\")\n", "ic = np.array([NSS, NIS, NRS, NRI, NSI, NSR, NIR, 1-np.sum(SI)], dtype=\"object\")\n", "par_vals = np.linspace(par_min, par_max, n_points)\n", "bif_vals = np.zeros((len(par_vals), n_strobes))\n", "for i in range(len(par_vals)):\n", " print('Running value %d of %d' % (i+1,len(par_vals)))\n", " exec(sweep_par + \" = par_vals[i]\")\n", " params = np.array([gamma, mu, alpha, a, omega, beta, epsilon], dtype=\"object\")\n", " output = run_two_strain(end_time, output_interval, step_size, params, ic)\n", " I = output[:, 1] + output[:, 6] # NIS + NIR\n", " bif_vals[i, :] = I[-n_strobes:len(I)]"]}, {"cell_type": "markdown", "metadata": {}, "source": ["Plot output"]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["plt.plot(par_vals, bif_vals, '.k')\n", "plt.xlabel(sweep_par)\n", "plt.ylabel(\"NIS + NIR\")\n", "plt.xlim([par_min, par_max])\n", "plt.show()\n", "plt.savefig(\"bifurcation_\" + sweep_par + \".png\")\n", "plt.close()"]}], "metadata": {"kernelspec": {"display_name": "Python 3", "language": "python", "name": "python3"}, "language_info": {"codemirror_mode": {"name": "ipython", "version": 3}, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.6.4"}}, "nbformat": 4, "nbformat_minor": 2} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters