update on how to read data

This commit is contained in:
mhjensen
2017-12-01 22:54:29 +01:00
parent c94663c683
commit 98389d1368
25 changed files with 2615 additions and 44 deletions
@@ -45,17 +45,66 @@ Automatically generated HTML file from DocOnce source
('Different algorithms', 2, None, '___sec2'),
('Software and needed installations', 2, None, '___sec3'),
('Python installers', 2, None, '___sec4'),
('Installing R and C++', 2, None, '___sec5'),
('Installing R, C++, cython or Julia', 2, None, '___sec5'),
('Introduction to Jupyter notebook and available tools',
2,
None,
'___sec6'),
('Representing data, overarching aims', 2, None, '___sec7'),
('Representing data, more examples', 2, None, '___sec8')]}
('Doing it in R', 2, None, '___sec7'),
('Representing data, overarching aims', 2, None, '___sec8'),
('Representing data, more examples', 2, None, '___sec9'),
('Binning of data', 2, None, '___sec10'),
('Adding model complexity: Predator-Prey model from ecology',
2,
None,
'___sec11'),
('Case study from Hudson bay', 2, None, '___sec12'),
('Hudson bay data', 2, None, '___sec13'),
('Plotting the data', 2, None, '___sec14'),
('Hares and lynx in Hudson bay from 1900 to 1920',
2,
None,
'___sec15'),
('Why now create a computer model for the hare and lynx '
'populations?',
2,
None,
'___sec16'),
('The traditional (top-down) approach', 2, None, '___sec17'),
("The ``new'' discrete bottom-up approach", 2, None, '___sec18'),
('Basic (computer-friendly) mathematics notation',
2,
None,
'___sec19'),
('Basic dynamics of the population of hares',
2,
None,
'___sec20'),
('Basic dynamics of the population of lynx', 2, None, '___sec21'),
('Evolution equations', 2, None, '___sec22'),
('Adapt the model to the Hudson Bay case', 2, None, '___sec23'),
('The program', 2, None, '___sec24'),
('The plot', 2, None, '___sec25')]}
end of tocinfo -->
<body>
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
TeX: {
equationNumbers: { autoNumber: "none" },
extensions: ["AMSmath.js", "AMSsymbols.js", "autobold.js", "color.js"]
}
});
</script>
<script type="text/javascript" async
src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
</script>
<!-- Bootstrap navigation bar -->
<div class="navbar navbar-default navbar-fixed-top">
@@ -78,10 +127,27 @@ end of tocinfo -->
<!-- navigation toc: --> <li><a href="._How2ReadData-bs003.html#___sec2" style="font-size: 80%;">Different algorithms</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs004.html#___sec3" style="font-size: 80%;">Software and needed installations</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs005.html#___sec4" style="font-size: 80%;">Python installers</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs006.html#___sec5" style="font-size: 80%;">Installing R and C++</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs006.html#___sec5" style="font-size: 80%;">Installing R, C++, cython or Julia</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs007.html#___sec6" style="font-size: 80%;">Introduction to Jupyter notebook and available tools</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs008.html#___sec7" style="font-size: 80%;">Representing data, overarching aims</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs009.html#___sec8" style="font-size: 80%;">Representing data, more examples</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs008.html#___sec7" style="font-size: 80%;">Doing it in R</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs009.html#___sec8" style="font-size: 80%;">Representing data, overarching aims</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs010.html#___sec9" style="font-size: 80%;">Representing data, more examples</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs011.html#___sec10" style="font-size: 80%;">Binning of data</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs012.html#___sec11" style="font-size: 80%;">Adding model complexity: Predator-Prey model from ecology</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs013.html#___sec12" style="font-size: 80%;">Case study from Hudson bay</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs014.html#___sec13" style="font-size: 80%;">Hudson bay data</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs015.html#___sec14" style="font-size: 80%;">Plotting the data</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs016.html#___sec15" style="font-size: 80%;">Hares and lynx in Hudson bay from 1900 to 1920</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs017.html#___sec16" style="font-size: 80%;">Why now create a computer model for the hare and lynx populations?</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs018.html#___sec17" style="font-size: 80%;">The traditional (top-down) approach</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs019.html#___sec18" style="font-size: 80%;">The ``new'' discrete bottom-up approach</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs020.html#___sec19" style="font-size: 80%;">Basic (computer-friendly) mathematics notation</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs021.html#___sec20" style="font-size: 80%;">Basic dynamics of the population of hares</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs022.html#___sec21" style="font-size: 80%;">Basic dynamics of the population of lynx</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs023.html#___sec22" style="font-size: 80%;">Evolution equations</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs024.html#___sec23" style="font-size: 80%;">Adapt the model to the Hudson Bay case</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs025.html#___sec24" style="font-size: 80%;">The program</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs026.html#___sec25" style="font-size: 80%;">The plot</a></li>
</ul>
</li>
@@ -116,7 +182,7 @@ end of tocinfo -->
<center>[2] <b>Department of Physics and Astronomy and National Superconducting Cyclotron Laboratory, Michigan State University</b></center>
<br>
<p>
<center><h4>Nov 27, 2017</h4></center> <!-- date -->
<center><h4>Dec 1, 2017</h4></center> <!-- date -->
<br>
<p>
@@ -139,6 +205,8 @@ end of tocinfo -->
<li><a href="._How2ReadData-bs007.html">8</a></li>
<li><a href="._How2ReadData-bs008.html">9</a></li>
<li><a href="._How2ReadData-bs009.html">10</a></li>
<li><a href="">...</a></li>
<li><a href="._How2ReadData-bs026.html">27</a></li>
<li><a href="._How2ReadData-bs001.html">&raquo;</a></li>
</ul>
<!-- ------------------- end of main content --------------- -->
@@ -45,17 +45,66 @@ Automatically generated HTML file from DocOnce source
('Different algorithms', 2, None, '___sec2'),
('Software and needed installations', 2, None, '___sec3'),
('Python installers', 2, None, '___sec4'),
('Installing R and C++', 2, None, '___sec5'),
('Installing R, C++, cython or Julia', 2, None, '___sec5'),
('Introduction to Jupyter notebook and available tools',
2,
None,
'___sec6'),
('Representing data, overarching aims', 2, None, '___sec7'),
('Representing data, more examples', 2, None, '___sec8')]}
('Doing it in R', 2, None, '___sec7'),
('Representing data, overarching aims', 2, None, '___sec8'),
('Representing data, more examples', 2, None, '___sec9'),
('Binning of data', 2, None, '___sec10'),
('Adding model complexity: Predator-Prey model from ecology',
2,
None,
'___sec11'),
('Case study from Hudson bay', 2, None, '___sec12'),
('Hudson bay data', 2, None, '___sec13'),
('Plotting the data', 2, None, '___sec14'),
('Hares and lynx in Hudson bay from 1900 to 1920',
2,
None,
'___sec15'),
('Why now create a computer model for the hare and lynx '
'populations?',
2,
None,
'___sec16'),
('The traditional (top-down) approach', 2, None, '___sec17'),
("The ``new'' discrete bottom-up approach", 2, None, '___sec18'),
('Basic (computer-friendly) mathematics notation',
2,
None,
'___sec19'),
('Basic dynamics of the population of hares',
2,
None,
'___sec20'),
('Basic dynamics of the population of lynx', 2, None, '___sec21'),
('Evolution equations', 2, None, '___sec22'),
('Adapt the model to the Hudson Bay case', 2, None, '___sec23'),
('The program', 2, None, '___sec24'),
('The plot', 2, None, '___sec25')]}
end of tocinfo -->
<body>
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
TeX: {
equationNumbers: { autoNumber: "none" },
extensions: ["AMSmath.js", "AMSsymbols.js", "autobold.js", "color.js"]
}
});
</script>
<script type="text/javascript" async
src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
</script>
<!-- Bootstrap navigation bar -->
<div class="navbar navbar-default navbar-fixed-top">
@@ -78,10 +127,27 @@ end of tocinfo -->
<!-- navigation toc: --> <li><a href="._How2ReadData-bs003.html#___sec2" style="font-size: 80%;">Different algorithms</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs004.html#___sec3" style="font-size: 80%;">Software and needed installations</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs005.html#___sec4" style="font-size: 80%;">Python installers</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs006.html#___sec5" style="font-size: 80%;">Installing R and C++</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs006.html#___sec5" style="font-size: 80%;">Installing R, C++, cython or Julia</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs007.html#___sec6" style="font-size: 80%;">Introduction to Jupyter notebook and available tools</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs008.html#___sec7" style="font-size: 80%;">Representing data, overarching aims</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs009.html#___sec8" style="font-size: 80%;">Representing data, more examples</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs008.html#___sec7" style="font-size: 80%;">Doing it in R</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs009.html#___sec8" style="font-size: 80%;">Representing data, overarching aims</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs010.html#___sec9" style="font-size: 80%;">Representing data, more examples</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs011.html#___sec10" style="font-size: 80%;">Binning of data</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs012.html#___sec11" style="font-size: 80%;">Adding model complexity: Predator-Prey model from ecology</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs013.html#___sec12" style="font-size: 80%;">Case study from Hudson bay</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs014.html#___sec13" style="font-size: 80%;">Hudson bay data</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs015.html#___sec14" style="font-size: 80%;">Plotting the data</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs016.html#___sec15" style="font-size: 80%;">Hares and lynx in Hudson bay from 1900 to 1920</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs017.html#___sec16" style="font-size: 80%;">Why now create a computer model for the hare and lynx populations?</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs018.html#___sec17" style="font-size: 80%;">The traditional (top-down) approach</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs019.html#___sec18" style="font-size: 80%;">The ``new'' discrete bottom-up approach</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs020.html#___sec19" style="font-size: 80%;">Basic (computer-friendly) mathematics notation</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs021.html#___sec20" style="font-size: 80%;">Basic dynamics of the population of hares</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs022.html#___sec21" style="font-size: 80%;">Basic dynamics of the population of lynx</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs023.html#___sec22" style="font-size: 80%;">Evolution equations</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs024.html#___sec23" style="font-size: 80%;">Adapt the model to the Hudson Bay case</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs025.html#___sec24" style="font-size: 80%;">The program</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs026.html#___sec25" style="font-size: 80%;">The plot</a></li>
</ul>
</li>
@@ -130,6 +196,9 @@ bioinformatics, economy, physics, finance and marketing.
<li><a href="._How2ReadData-bs007.html">8</a></li>
<li><a href="._How2ReadData-bs008.html">9</a></li>
<li><a href="._How2ReadData-bs009.html">10</a></li>
<li><a href="._How2ReadData-bs010.html">11</a></li>
<li><a href="">...</a></li>
<li><a href="._How2ReadData-bs026.html">27</a></li>
<li><a href="._How2ReadData-bs002.html">&raquo;</a></li>
</ul>
<!-- ------------------- end of main content --------------- -->
+75 -7
View File
@@ -45,17 +45,66 @@ Automatically generated HTML file from DocOnce source
('Different algorithms', 2, None, '___sec2'),
('Software and needed installations', 2, None, '___sec3'),
('Python installers', 2, None, '___sec4'),
('Installing R and C++', 2, None, '___sec5'),
('Installing R, C++, cython or Julia', 2, None, '___sec5'),
('Introduction to Jupyter notebook and available tools',
2,
None,
'___sec6'),
('Representing data, overarching aims', 2, None, '___sec7'),
('Representing data, more examples', 2, None, '___sec8')]}
('Doing it in R', 2, None, '___sec7'),
('Representing data, overarching aims', 2, None, '___sec8'),
('Representing data, more examples', 2, None, '___sec9'),
('Binning of data', 2, None, '___sec10'),
('Adding model complexity: Predator-Prey model from ecology',
2,
None,
'___sec11'),
('Case study from Hudson bay', 2, None, '___sec12'),
('Hudson bay data', 2, None, '___sec13'),
('Plotting the data', 2, None, '___sec14'),
('Hares and lynx in Hudson bay from 1900 to 1920',
2,
None,
'___sec15'),
('Why now create a computer model for the hare and lynx '
'populations?',
2,
None,
'___sec16'),
('The traditional (top-down) approach', 2, None, '___sec17'),
("The ``new'' discrete bottom-up approach", 2, None, '___sec18'),
('Basic (computer-friendly) mathematics notation',
2,
None,
'___sec19'),
('Basic dynamics of the population of hares',
2,
None,
'___sec20'),
('Basic dynamics of the population of lynx', 2, None, '___sec21'),
('Evolution equations', 2, None, '___sec22'),
('Adapt the model to the Hudson Bay case', 2, None, '___sec23'),
('The program', 2, None, '___sec24'),
('The plot', 2, None, '___sec25')]}
end of tocinfo -->
<body>
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
TeX: {
equationNumbers: { autoNumber: "none" },
extensions: ["AMSmath.js", "AMSsymbols.js", "autobold.js", "color.js"]
}
});
</script>
<script type="text/javascript" async
src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
</script>
<!-- Bootstrap navigation bar -->
<div class="navbar navbar-default navbar-fixed-top">
@@ -78,10 +127,27 @@ end of tocinfo -->
<!-- navigation toc: --> <li><a href="._How2ReadData-bs003.html#___sec2" style="font-size: 80%;">Different algorithms</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs004.html#___sec3" style="font-size: 80%;">Software and needed installations</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs005.html#___sec4" style="font-size: 80%;">Python installers</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs006.html#___sec5" style="font-size: 80%;">Installing R and C++</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs006.html#___sec5" style="font-size: 80%;">Installing R, C++, cython or Julia</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs007.html#___sec6" style="font-size: 80%;">Introduction to Jupyter notebook and available tools</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs008.html#___sec7" style="font-size: 80%;">Representing data, overarching aims</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs009.html#___sec8" style="font-size: 80%;">Representing data, more examples</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs008.html#___sec7" style="font-size: 80%;">Doing it in R</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs009.html#___sec8" style="font-size: 80%;">Representing data, overarching aims</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs010.html#___sec9" style="font-size: 80%;">Representing data, more examples</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs011.html#___sec10" style="font-size: 80%;">Binning of data</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs012.html#___sec11" style="font-size: 80%;">Adding model complexity: Predator-Prey model from ecology</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs013.html#___sec12" style="font-size: 80%;">Case study from Hudson bay</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs014.html#___sec13" style="font-size: 80%;">Hudson bay data</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs015.html#___sec14" style="font-size: 80%;">Plotting the data</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs016.html#___sec15" style="font-size: 80%;">Hares and lynx in Hudson bay from 1900 to 1920</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs017.html#___sec16" style="font-size: 80%;">Why now create a computer model for the hare and lynx populations?</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs018.html#___sec17" style="font-size: 80%;">The traditional (top-down) approach</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs019.html#___sec18" style="font-size: 80%;">The ``new'' discrete bottom-up approach</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs020.html#___sec19" style="font-size: 80%;">Basic (computer-friendly) mathematics notation</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs021.html#___sec20" style="font-size: 80%;">Basic dynamics of the population of hares</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs022.html#___sec21" style="font-size: 80%;">Basic dynamics of the population of lynx</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs023.html#___sec22" style="font-size: 80%;">Evolution equations</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs024.html#___sec23" style="font-size: 80%;">Adapt the model to the Hudson Bay case</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs025.html#___sec24" style="font-size: 80%;">The program</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs026.html#___sec25" style="font-size: 80%;">The plot</a></li>
</ul>
</li>
@@ -116,7 +182,7 @@ end of tocinfo -->
<center>[2] <b>Department of Physics and Astronomy and National Superconducting Cyclotron Laboratory, Michigan State University</b></center>
<br>
<p>
<center><h4>Nov 27, 2017</h4></center> <!-- date -->
<center><h4>Dec 1, 2017</h4></center> <!-- date -->
<br>
<p>
@@ -139,6 +205,8 @@ end of tocinfo -->
<li><a href="._How2ReadData-bs007.html">8</a></li>
<li><a href="._How2ReadData-bs008.html">9</a></li>
<li><a href="._How2ReadData-bs009.html">10</a></li>
<li><a href="">...</a></li>
<li><a href="._How2ReadData-bs026.html">27</a></li>
<li><a href="._How2ReadData-bs001.html">&raquo;</a></li>
</ul>
<!-- ------------------- end of main content --------------- -->
@@ -107,6 +107,22 @@ td.padding {
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
TeX: {
equationNumbers: { autoNumber: "none" },
extensions: ["AMSmath.js", "AMSsymbols.js", "autobold.js", "color.js"]
}
});
</script>
<script type="text/javascript" async
src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
</script>
@@ -132,7 +148,7 @@ td.padding {
<center>[2] <b>Department of Physics and Astronomy and National Superconducting Cyclotron Laboratory, Michigan State University</b></center>
<br>
<p>&nbsp;<br>
<center><h4>Nov 27, 2017</h4></center> <!-- date -->
<center><h4>Dec 1, 2017</h4></center> <!-- date -->
<br>
<p>
@@ -232,7 +248,7 @@ we recommend that you install the following Python packages via <b>pip</b> as
For Python3, replace <b>pip</b> with <b>pip3</b>.
<p>
For OSX user we recommend also, after having installed Xcode, to install <b>brew</b>. Brew allows
For OSX users we recommend also, after having installed Xcode, to install <b>brew</b>. Brew allows
for a seamless installation of additional software via for example
<ol>
@@ -265,7 +281,7 @@ all relevant dependencies for Python, namely
<section>
<h2 id="___sec5">Installing R and C++ </h2>
<h2 id="___sec5">Installing R, C++, cython or Julia </h2>
<p>
You will also find it convenient to utilize R. Say more about R.
@@ -282,6 +298,13 @@ To add more entropy, <b>cython</b> can also be used when running your notebooks.
setup allows you to integrate widely popular softwares and tools for scientific computing. With its versatility,
including symbolic operations, Python offers a unique computational environment. Your Jupyter/IPython notebook
can easily be converted into a nicely rendered <b>PDF</b> file or a Latex file for further processing.
<p>
This never ends,
<p>
If you se the light mark-up language <b>doconce</b> you can convert a standard ascii text file into various HTML
formats, ipython notebooks, latex files, pdf files etc.
</section>
@@ -291,7 +314,13 @@ can easily be converted into a nicely rendered <b>PDF</b> file or a Latex file f
<section>
<h2 id="___sec7">Representing data, overarching aims </h2>
<h2 id="___sec7">Doing it in R </h2>
Use the Hudson bay model to load data and make plot in R and with python
</section>
<section>
<h2 id="___sec8">Representing data, overarching aims </h2>
<div class="alert alert-block alert-block alert-text-normal">
<b></b>
<p>
@@ -320,7 +349,7 @@ display(data_pandas)
<section>
<h2 id="___sec8">Representing data, more examples </h2>
<h2 id="___sec9">Representing data, more examples </h2>
<div class="alert alert-block alert-block alert-text-normal">
<b></b>
<p>
@@ -348,6 +377,445 @@ plt.show()
</section>
<section>
<h2 id="___sec10">Binning of data </h2>
Use the Hudson bay model to load data and make plot in R and with python
</section>
<section>
<h2 id="___sec11">Adding model complexity: Predator-Prey model from ecology </h2>
<p>
<div class="alert alert-block alert-block alert-text-normal">
<b></b>
<p>
The population dynamics of a simple predator-prey system is a
classical example shown in many biology textbooks when ecological
systems are discussed. The system contains all elements of the
scientific method:
<ul>
<p><li> The set up of a specific hypothesis combined with</li>
<p><li> the experimental methods needed (one can study existing data or perform experiments)</li>
<p><li> analyzing and interpreting the data and performing further experiments if needed</li>
<p><li> trying to extract general behaviors and extract eventual laws or patterns</li>
<p><li> develop mathematical relations for the uncovered regularities/laws and test these by per forming new experiments</li>
</ul>
</div>
</section>
<section>
<h2 id="___sec12">Case study from Hudson bay </h2>
<p>
<div class="alert alert-block alert-block alert-text-normal">
<b></b>
<p>
Lots of data about populations of hares and lynx collected from furs in Hudson Bay, Canada, are available. It is known that the populations oscillate. Why?
We shall demonstrate the scientific method by
<ol>
<p><li> plotting the data</li>
<p><li> derive a simple model for the population dynamics</li>
<p><li> (fitting parameters in the model to the data)</li>
<p><li> using the model predict the evolution other predator-pray systems</li>
</ol>
</div>
</section>
<section>
<h2 id="___sec13">Hudson bay data </h2>
<p>
<div class="alert alert-block alert-block alert-text-normal">
<b></b>
<p>
% if FORMAT == 'ipynb':
Most mammalian predators rely on a variety of prey, which complicates mathematical modeling; however, a few predators have become highly specialized and seek almost exclusively a single prey species. An example of this simplified predator-prey interaction is seen in Canadian northern forests, where the populations of the lynx and the snowshoe hare are intertwined in a life and death struggle.
<p>
One reason that this particular system has been so extensively studied is that the Hudson Bay company kept careful records of all furs from the early 1800s into the 1900s. The records for the furs collected by the Hudson Bay company showed distinct oscillations (approximately 12 year periods), suggesting that these species caused almost periodic fluctuations of each other's populations. The table here shows data from 1900 to 1920.
% endif
<p>
<table border="1">
<thead>
<tr><th align="center">Year</th> <th align="center">Hares (x1000)</th> <th align="center">Lynx (x1000)</th> </tr>
</thead>
<tbody>
<tr><td align="left"> 1900 </td> <td align="right"> 30.0 </td> <td align="right"> 4.0 </td> </tr>
<tr><td align="left"> 1901 </td> <td align="right"> 47.2 </td> <td align="right"> 6.1 </td> </tr>
<tr><td align="left"> 1902 </td> <td align="right"> 70.2 </td> <td align="right"> 9.8 </td> </tr>
<tr><td align="left"> 1903 </td> <td align="right"> 77.4 </td> <td align="right"> 35.2 </td> </tr>
<tr><td align="left"> 1904 </td> <td align="right"> 36.3 </td> <td align="right"> 59.4 </td> </tr>
<tr><td align="left"> 1905 </td> <td align="right"> 20.6 </td> <td align="right"> 41.7 </td> </tr>
<tr><td align="left"> 1906 </td> <td align="right"> 18.1 </td> <td align="right"> 19.0 </td> </tr>
<tr><td align="left"> 1907 </td> <td align="right"> 21.4 </td> <td align="right"> 13.0 </td> </tr>
<tr><td align="left"> 1908 </td> <td align="right"> 22.0 </td> <td align="right"> 8.3 </td> </tr>
<tr><td align="left"> 1909 </td> <td align="right"> 25.4 </td> <td align="right"> 9.1 </td> </tr>
<tr><td align="left"> 1910 </td> <td align="right"> 27.1 </td> <td align="right"> 7.4 </td> </tr>
<tr><td align="left"> 1911 </td> <td align="right"> 40.3 </td> <td align="right"> 8.0 </td> </tr>
<tr><td align="left"> 1912 </td> <td align="right"> 57 </td> <td align="right"> 12.3 </td> </tr>
<tr><td align="left"> 1913 </td> <td align="right"> 76.6 </td> <td align="right"> 19.5 </td> </tr>
<tr><td align="left"> 1914 </td> <td align="right"> 52.3 </td> <td align="right"> 45.7 </td> </tr>
<tr><td align="left"> 1915 </td> <td align="right"> 19.5 </td> <td align="right"> 51.1 </td> </tr>
<tr><td align="left"> 1916 </td> <td align="right"> 11.2 </td> <td align="right"> 29.7 </td> </tr>
<tr><td align="left"> 1917 </td> <td align="right"> 7.6 </td> <td align="right"> 15.8 </td> </tr>
<tr><td align="left"> 1918 </td> <td align="right"> 14.6 </td> <td align="right"> 9.7 </td> </tr>
<tr><td align="left"> 1919 </td> <td align="right"> 16.2 </td> <td align="right"> 10.1 </td> </tr>
<tr><td align="left"> 1920 </td> <td align="right"> 24.7 </td> <td align="right"> 8.6 </td> </tr>
</tbody>
</table>
</div>
</section>
<section>
<h2 id="___sec14">Plotting the data </h2>
<p>
<div class="alert alert-block alert-block alert-text-normal">
<b></b>
<p>
<!-- code=python (!bc pypro) typeset with pygments style "perldoc" -->
<div class="highlight" style="background: #eeeedd"><pre style="font-size: 80%; line-height: 125%"><span></span><span style="color: #8B008B; font-weight: bold">import</span> <span style="color: #008b45; text-decoration: underline">numpy</span> <span style="color: #8B008B; font-weight: bold">as</span> <span style="color: #008b45; text-decoration: underline">np</span>
<span style="color: #8B008B; font-weight: bold">from</span> <span style="color: #008b45; text-decoration: underline">matplotlib</span> <span style="color: #8B008B; font-weight: bold">import</span> pyplot <span style="color: #8B008B; font-weight: bold">as</span> plt
<span style="color: #228B22"># Load in data file</span>
data = np.loadtxt(<span style="color: #CD5555">&#39;Hudson_Bay.dat&#39;</span>, delimiter=<span style="color: #CD5555">&#39;,&#39;</span>, skiprows=<span style="color: #B452CD">1</span>)
<span style="color: #228B22"># Make arrays containing x-axis and hares and lynx populations</span>
year = data[:,<span style="color: #B452CD">0</span>]
hares = data[:,<span style="color: #B452CD">1</span>]
lynx = data[:,<span style="color: #B452CD">2</span>]
plt.plot(year, hares ,<span style="color: #CD5555">&#39;b-+&#39;</span>, year, lynx, <span style="color: #CD5555">&#39;r-o&#39;</span>)
plt.axis([<span style="color: #B452CD">1900</span>,<span style="color: #B452CD">1920</span>,<span style="color: #B452CD">0</span>, <span style="color: #B452CD">100.0</span>])
plt.xlabel(<span style="color: #CD5555">r&#39;Year&#39;</span>)
plt.ylabel(<span style="color: #CD5555">r&#39;Numbers of hares and lynx &#39;</span>)
plt.legend((<span style="color: #CD5555">&#39;Hares&#39;</span>,<span style="color: #CD5555">&#39;Lynx&#39;</span>), loc=<span style="color: #CD5555">&#39;upper right&#39;</span>)
plt.title(<span style="color: #CD5555">r&#39;Population of hares and lynx from 1900-1920 (x1000)}&#39;</span>)
plt.savefig(<span style="color: #CD5555">&#39;Hudson_Bay_data.pdf&#39;</span>)
plt.savefig(<span style="color: #CD5555">&#39;Hudson_Bay_data.png&#39;</span>)
plt.show()
</pre></div>
</div>
<p>
% if FORMAT != 'ipynb':
</section>
<section>
<h2 id="___sec15">Hares and lynx in Hudson bay from 1900 to 1920 </h2>
<p>
<br /><br /><center><p><img src="fig/Hudson_Bay_data.png" align="bottom" width=700></p></center><br /><br />
% endif
</section>
<section>
<h2 id="___sec16">Why now create a computer model for the hare and lynx populations? </h2>
<div class="alert alert-block alert-block alert-text-normal">
<b></b>
<p>
% if FORMAT == 'ipynb':
We see from the plot that there are indeed fluctuations.
We would like to create a mathematical model that explains these
population fluctuations. Ecologists have predicted that in a simple
predator-prey system that a rise in prey population is followed (with
a lag) by a rise in the predator population. When the predator
population is sufficiently high, then the prey population begins
dropping. After the prey population falls, then the predator
population falls, which allows the prey population to recover and
complete one cycle of this interaction. Thus, we see that
qualitatively oscillations occur. Can a mathematical model predict
this? What causes cycles to slow or speed up? What affects the
amplitude of the oscillation or do you expect to see the oscillations
damp to a stable equilibrium? The models tend to ignore factors like
climate and other complicating factors. How significant are these?
% else:
<ul>
<p><li> We see oscillations in the data</li>
<p><li> What causes cycles to slow or speed up?</li>
<p><li> What affects the amplitude of the oscillation or do you expect to see the oscillations damp to a stable equilibrium?</li>
<p><li> With a model we can better <em>understand the data</em></li>
<p><li> More important: we can understand the ecology dynamics of
predator-pray populations</li>
</ul>
<p>
% endif
</div>
</section>
<section>
<h2 id="___sec17">The traditional (top-down) approach </h2>
<p>
<div class="alert alert-block alert-block alert-text-normal">
<b></b>
<p>
The classical way (in all books) is to present the Lotka-Volterra equations:
<p>&nbsp;<br>
$$
\begin{align*}
\frac{dH}{dt} &= H(a - b L)\\
\frac{dL}{dt} &= - L(d - c H)
\end{align*}
$$
<p>&nbsp;<br>
<p>
Here,
<ul>
<p><li> \( H \) is the number of preys</li>
<p><li> \( L \) the number of predators</li>
<p><li> \( a \), \( b \), \( d \), \( c \) are parameters</li>
</ul>
<p>
Most books quickly establish the model and then use considerable space on
discussing the qualitative properties of this <em>nonlinear system of
ODEs</em> (which cannot be solved)
</div>
</section>
<section>
<h2 id="___sec18">The &quot;new&quot; discrete bottom-up approach </h2>
<p>
<div class="alert alert-block alert-block alert-text-normal">
<b>The bottom-up approach.</b>
<ul>
<p><li class="fragment"> Start with experimental data and discuss the methods which have been used to collect the data, the assumptions, the electronic devices, the aims etc. That is, expose the students to the theory and assumptions behind the data that have been collected and motivate for the scientific method.</li>
<p><li class="fragment"> Where appropriate the students should do the experiment(s) needed to collect the data.</li>
<p><li class="fragment"> The first programming tasks are to read and visualize the data to see if there are patterns or regularities. This strengthens a research-driven intuition.</li>
<p><li class="fragment"> Now we want to increase the understanding through modeling.</li>
<p><li class="fragment"> Most of the biology lies in the <em>derivation</em> of the model. We shall
focus on an intuitive discrete approach that leads to difference
equations that can be programmed <em>and solved</em> directly.</li>
</ul>
</div>
</section>
<section>
<h2 id="___sec19">Basic (computer-friendly) mathematics notation </h2>
<div class="alert alert-block alert-block alert-text-normal">
<b></b>
<ul>
<p><li> Time points: \( t_0,t_1,\ldots,t_m \)</li>
<p><li> Uniform distribution of time points: \( t_n=n\Delta t \)</li>
<p><li> \( H^n \): population of hares at time \( t_n \)</li>
<p><li> \( L^n \): population of lynx at time \( t_n \)</li>
<p><li> We want to model the changes in populations, \( \Delta H=H^{n+1}-H^n \)
and \( \Delta L=L^{n+1}-L^n \) during a general time interval \( [t_{n+1},t_n] \)
of length \( \Delta t=t_{n+1}-t_n \)</li>
</ul>
</div>
</section>
<section>
<h2 id="___sec20">Basic dynamics of the population of hares </h2>
<p>
<div class="alert alert-block alert-block alert-text-normal">
<b></b>
<p>
The population of hares evolves due to births and deaths exactly as a bacteria population:
<p>&nbsp;<br>
$$
\Delta H = a \Delta t H^n
$$
<p>&nbsp;<br>
However, hares have an additional loss in the population because
they are eaten by lynx.
All the hares and lynx can form
\( H\cdot L \) pairs in total. When such pairs meet during a time
interval \( \Delta t \), there is some
small probablity that the lynx will eat the hare.
So in fraction \( b\Delta t HL \), the lynx eat hares. This
loss of hares and must be accounted for:
subtracted in the equation for hares:
<p>&nbsp;<br>
$$ \Delta H = a\Delta t H^n - b \Delta t H^nL^n$$
<p>&nbsp;<br>
</div>
</section>
<section>
<h2 id="___sec21">Basic dynamics of the population of lynx </h2>
<p>
<div class="alert alert-block alert-block alert-text-normal">
<b></b>
<p>
We assume that the primary growth for the lynx population depends on sufficient food for raising lynx kittens, which implies an adequate source of nutrients from predation on hares. Thus, the growth of the lynx population does not only depend of how many lynx there are, but on how many hares they can eat.
In a time interval \( \Delta t HL \) hares and lynx can meet, and in a
fraction \( b\Delta t HL \) the lynx eats the hare. All of this does not
contribute to the growth of lynx, again just a fraction of
\( b\Delta t HL \) that we write as
\( d\Delta t HL \). In addition, lynx die just as in the population
dynamics with one isolated animal population, leading to a loss
\( -c\Delta t L \).
</div>
<p>
<div class="alert alert-block alert-block alert-text-normal">
<b></b>
<p>
The accounting of lynx then looks like
<p>&nbsp;<br>
$$ \Delta L = d\Delta t H^nL^n - c\Delta t L^n$$
<p>&nbsp;<br>
</div>
</section>
<section>
<h2 id="___sec22">Evolution equations </h2>
<p>
<div class="alert alert-block alert-block alert-text-normal">
<b></b>
<p>
By writing up the definition of \( \Delta H \) and \( \Delta L \), and putting
all assumed known terms \( H^n \) and \( L^n \) on the right-hand side, we have
<p>&nbsp;<br>
$$ H^{n+1} = H^n + a\Delta t H^n - b\Delta t H^n L^n $$
<p>&nbsp;<br>
<p>&nbsp;<br>
$$ L^{n+1} = L^n + d\Delta t H^nL^n - c\Delta t L^n $$
<p>&nbsp;<br>
<p>
Note:
<ul>
<p><li> These equations are ready to be implemented!</li>
<p><li> But to start, we need \( H^0 \) and \( L^0 \) <br />
(which we can get from the data)</li>
<p><li> We also need values for \( a \), \( b \), \( d \), \( c \)</li>
</ul>
</div>
</section>
<section>
<h2 id="___sec23">Adapt the model to the Hudson Bay case </h2>
<p>
<div class="alert alert-block alert-block alert-text-normal">
<b></b>
<ul>
<p><li> As always, models tend to be general - as here, applicable
to &quot;all&quot; predator-pray systems</li>
<p><li> The critical issue is whether the <em>interaction</em> between hares and lynx
is sufficiently well modeled by \( \hbox{const}HL \)</li>
<p><li> The parameters \( a \), \( b \), \( d \), and \( c \) must be
estimated from data</li>
<p><li> Measure time in years</li>
<p><li> \( t_0=1900 \), \( t_m=1920 \)</li>
</ul>
</div>
</section>
<section>
<h2 id="___sec24">The program </h2>
<p>
<div class="alert alert-block alert-block alert-text-normal">
<b></b>
<p>
<!-- code=python (!bc pypro) typeset with pygments style "perldoc" -->
<div class="highlight" style="background: #eeeedd"><pre style="font-size: 80%; line-height: 125%"><span></span><span style="color: #8B008B; font-weight: bold">import</span> <span style="color: #008b45; text-decoration: underline">numpy</span> <span style="color: #8B008B; font-weight: bold">as</span> <span style="color: #008b45; text-decoration: underline">np</span>
<span style="color: #8B008B; font-weight: bold">import</span> <span style="color: #008b45; text-decoration: underline">matplotlib.pyplot</span> <span style="color: #8B008B; font-weight: bold">as</span> <span style="color: #008b45; text-decoration: underline">plt</span>
<span style="color: #8B008B; font-weight: bold">def</span> <span style="color: #008b45">solver</span>(m, H0, L0, dt, a, b, c, d, t0):
<span style="color: #CD5555">&quot;&quot;&quot;Solve the difference equations for H and L over m years</span>
<span style="color: #CD5555"> with time step dt (measured in years.&quot;&quot;&quot;</span>
num_intervals = <span style="color: #658b00">int</span>(m/<span style="color: #658b00">float</span>(dt))
t = np.linspace(t0, t0 + m, num_intervals+<span style="color: #B452CD">1</span>)
H = np.zeros(t.size)
L = np.zeros(t.size)
<span style="color: #8B008B; font-weight: bold">print</span> <span style="color: #CD5555">&#39;Init:&#39;</span>, H0, L0, dt
H[<span style="color: #B452CD">0</span>] = H0
L[<span style="color: #B452CD">0</span>] = L0
<span style="color: #8B008B; font-weight: bold">for</span> n <span style="color: #8B008B">in</span> <span style="color: #658b00">range</span>(<span style="color: #B452CD">0</span>, <span style="color: #658b00">len</span>(t)-<span style="color: #B452CD">1</span>):
H[n+<span style="color: #B452CD">1</span>] = H[n] + a*dt*H[n] - b*dt*H[n]*L[n]
L[n+<span style="color: #B452CD">1</span>] = L[n] + d*dt*H[n]*L[n] - c*dt*L[n]
<span style="color: #8B008B; font-weight: bold">return</span> H, L, t
<span style="color: #228B22"># Load in data file</span>
data = np.loadtxt(<span style="color: #CD5555">&#39;Hudson_Bay.csv&#39;</span>, delimiter=<span style="color: #CD5555">&#39;,&#39;</span>, skiprows=<span style="color: #B452CD">1</span>)
<span style="color: #228B22"># Make arrays containing x-axis and hares and lynx populations</span>
t_e = data[:,<span style="color: #B452CD">0</span>]
H_e = data[:,<span style="color: #B452CD">1</span>]
L_e = data[:,<span style="color: #B452CD">2</span>]
<span style="color: #228B22"># Simulate using the model</span>
H, L, t = solver(m=<span style="color: #B452CD">20</span>, H0=<span style="color: #B452CD">34.91</span>, L0=<span style="color: #B452CD">3.857</span>, dt=<span style="color: #B452CD">0.1</span>,
a=<span style="color: #B452CD">0.4807</span>, b=<span style="color: #B452CD">0.02482</span>, c=<span style="color: #B452CD">0.9272</span>, d=<span style="color: #B452CD">0.02756</span>,
t0=<span style="color: #B452CD">1900</span>)
<span style="color: #228B22"># Visualize simulations and data</span>
plt.plot(t_e, H_e, <span style="color: #CD5555">&#39;b-+&#39;</span>, t_e, L_e, <span style="color: #CD5555">&#39;r-o&#39;</span>, t, H, <span style="color: #CD5555">&#39;m--&#39;</span>, t, L, <span style="color: #CD5555">&#39;k--&#39;</span>)
plt.xlabel(<span style="color: #CD5555">&#39;Year&#39;</span>)
plt.ylabel(<span style="color: #CD5555">&#39;Numbers of hares and lynx&#39;</span>)
plt.axis([<span style="color: #B452CD">1900</span>, <span style="color: #B452CD">1920</span>, <span style="color: #B452CD">0</span>, <span style="color: #B452CD">140</span>])
plt.title(<span style="color: #CD5555">r&#39;Population of hares and lynx 1900-1920 (x1000)&#39;</span>)
plt.legend((<span style="color: #CD5555">&#39;H_e&#39;</span>, <span style="color: #CD5555">&#39;L_e&#39;</span>, <span style="color: #CD5555">&#39;H&#39;</span>, <span style="color: #CD5555">&#39;L&#39;</span>), loc=<span style="color: #CD5555">&#39;upper left&#39;</span>)
plt.savefig(<span style="color: #CD5555">&#39;Hudson_Bay_sim.pdf&#39;</span>)
plt.savefig(<span style="color: #CD5555">&#39;Hudson_Bay_sim.png&#39;</span>)
plt.show()
</pre></div>
</div>
<p>
% if FORMAT != 'ipynb':
</section>
<section>
<h2 id="___sec25">The plot </h2>
<p>
<br /><br /><center><p><img src="fig/Hudson_Bay_sim.png" align="bottom" width=700></p></center><br /><br />
<p>
% else:
If we perform a least-square fitting, we can find optimal values for the parameters \( a \), \( b \), \( d \), \( c \). The optimal parameters are \( a=0.4807 \), \( b=0.02482 \), \( d=0.9272 \) and \( c=0.02756 \). These parameters result in a slightly modified initial conditions, namely \( H(0) = 34.91 \) and \( L(0)=3.857 \). With these parameters we are now ready to solve the equations and plot these data together with the experimental values.
% endif
</section>
</div> <!-- class="slides" -->
</div> <!-- class="reveal" -->
@@ -65,17 +65,66 @@ div { text-align: justify; text-justify: inter-word; }
('Different algorithms', 2, None, '___sec2'),
('Software and needed installations', 2, None, '___sec3'),
('Python installers', 2, None, '___sec4'),
('Installing R and C++', 2, None, '___sec5'),
('Installing R, C++, cython or Julia', 2, None, '___sec5'),
('Introduction to Jupyter notebook and available tools',
2,
None,
'___sec6'),
('Representing data, overarching aims', 2, None, '___sec7'),
('Representing data, more examples', 2, None, '___sec8')]}
('Doing it in R', 2, None, '___sec7'),
('Representing data, overarching aims', 2, None, '___sec8'),
('Representing data, more examples', 2, None, '___sec9'),
('Binning of data', 2, None, '___sec10'),
('Adding model complexity: Predator-Prey model from ecology',
2,
None,
'___sec11'),
('Case study from Hudson bay', 2, None, '___sec12'),
('Hudson bay data', 2, None, '___sec13'),
('Plotting the data', 2, None, '___sec14'),
('Hares and lynx in Hudson bay from 1900 to 1920',
2,
None,
'___sec15'),
('Why now create a computer model for the hare and lynx '
'populations?',
2,
None,
'___sec16'),
('The traditional (top-down) approach', 2, None, '___sec17'),
("The ``new'' discrete bottom-up approach", 2, None, '___sec18'),
('Basic (computer-friendly) mathematics notation',
2,
None,
'___sec19'),
('Basic dynamics of the population of hares',
2,
None,
'___sec20'),
('Basic dynamics of the population of lynx', 2, None, '___sec21'),
('Evolution equations', 2, None, '___sec22'),
('Adapt the model to the Hudson Bay case', 2, None, '___sec23'),
('The program', 2, None, '___sec24'),
('The plot', 2, None, '___sec25')]}
end of tocinfo -->
<body>
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
TeX: {
equationNumbers: { autoNumber: "AMS" },
extensions: ["AMSmath.js", "AMSsymbols.js", "autobold.js", "color.js"]
}
});
</script>
<script type="text/javascript" async
src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
</script>
<!-- ------------------- main content ---------------------- -->
@@ -97,7 +146,7 @@ end of tocinfo -->
<center>[2] <b>Department of Physics and Astronomy and National Superconducting Cyclotron Laboratory, Michigan State University</b></center>
<br>
<p>
<center><h4>Nov 27, 2017</h4></center> <!-- date -->
<center><h4>Dec 1, 2017</h4></center> <!-- date -->
<br>
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
@@ -185,7 +234,7 @@ we recommend that you install the following Python packages via <b>pip</b> as
For Python3, replace <b>pip</b> with <b>pip3</b>.
<p>
For OSX user we recommend also, after having installed Xcode, to install <b>brew</b>. Brew allows
For OSX users we recommend also, after having installed Xcode, to install <b>brew</b>. Brew allows
for a seamless installation of additional software via for example
<ol>
@@ -215,7 +264,7 @@ all relevant dependencies for Python, namely
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec5">Installing R and C++ </h2>
<h2 id="___sec5">Installing R, C++, cython or Julia </h2>
<p>
You will also find it convenient to utilize R. Say more about R.
@@ -233,6 +282,13 @@ setup allows you to integrate widely popular softwares and tools for scientific
including symbolic operations, Python offers a unique computational environment. Your Jupyter/IPython notebook
can easily be converted into a nicely rendered <b>PDF</b> file or a Latex file for further processing.
<p>
This never ends,
<p>
If you se the light mark-up language <b>doconce</b> you can convert a standard ascii text file into various HTML
formats, ipython notebooks, latex files, pdf files etc.
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
@@ -241,7 +297,13 @@ can easily be converted into a nicely rendered <b>PDF</b> file or a Latex file f
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec7">Representing data, overarching aims </h2>
<h2 id="___sec7">Doing it in R </h2>
Use the Hudson bay model to load data and make plot in R and with python
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec8">Representing data, overarching aims </h2>
<div class="alert alert-block alert-block alert-text-normal">
<b></b>
<p>
@@ -272,7 +334,7 @@ display(data_pandas)
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec8">Representing data, more examples </h2>
<h2 id="___sec9">Representing data, more examples </h2>
<div class="alert alert-block alert-block alert-text-normal">
<b></b>
<p>
@@ -300,6 +362,451 @@ plt.show()
</div>
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec10">Binning of data </h2>
Use the Hudson bay model to load data and make plot in R and with python
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec11">Adding model complexity: Predator-Prey model from ecology </h2>
<p>
<div class="alert alert-block alert-block alert-text-normal">
<b></b>
<p>
The population dynamics of a simple predator-prey system is a
classical example shown in many biology textbooks when ecological
systems are discussed. The system contains all elements of the
scientific method:
<ul>
<li> The set up of a specific hypothesis combined with</li>
<li> the experimental methods needed (one can study existing data or perform experiments)</li>
<li> analyzing and interpreting the data and performing further experiments if needed</li>
<li> trying to extract general behaviors and extract eventual laws or patterns</li>
<li> develop mathematical relations for the uncovered regularities/laws and test these by per forming new experiments</li>
</ul>
</div>
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec12">Case study from Hudson bay </h2>
<p>
<div class="alert alert-block alert-block alert-text-normal">
<b></b>
<p>
Lots of data about populations of hares and lynx collected from furs in Hudson Bay, Canada, are available. It is known that the populations oscillate. Why?
We shall demonstrate the scientific method by
<ol>
<li> plotting the data</li>
<li> derive a simple model for the population dynamics</li>
<li> (fitting parameters in the model to the data)</li>
<li> using the model predict the evolution other predator-pray systems</li>
</ol>
</div>
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec13">Hudson bay data </h2>
<p>
<div class="alert alert-block alert-block alert-text-normal">
<b></b>
<p>
% if FORMAT == 'ipynb':
Most mammalian predators rely on a variety of prey, which complicates mathematical modeling; however, a few predators have become highly specialized and seek almost exclusively a single prey species. An example of this simplified predator-prey interaction is seen in Canadian northern forests, where the populations of the lynx and the snowshoe hare are intertwined in a life and death struggle.
<p>
One reason that this particular system has been so extensively studied is that the Hudson Bay company kept careful records of all furs from the early 1800s into the 1900s. The records for the furs collected by the Hudson Bay company showed distinct oscillations (approximately 12 year periods), suggesting that these species caused almost periodic fluctuations of each other's populations. The table here shows data from 1900 to 1920.
% endif
<p>
<table border="1">
<thead>
<tr><th align="center">Year</th> <th align="center">Hares (x1000)</th> <th align="center">Lynx (x1000)</th> </tr>
</thead>
<tbody>
<tr><td align="left"> 1900 </td> <td align="right"> 30.0 </td> <td align="right"> 4.0 </td> </tr>
<tr><td align="left"> 1901 </td> <td align="right"> 47.2 </td> <td align="right"> 6.1 </td> </tr>
<tr><td align="left"> 1902 </td> <td align="right"> 70.2 </td> <td align="right"> 9.8 </td> </tr>
<tr><td align="left"> 1903 </td> <td align="right"> 77.4 </td> <td align="right"> 35.2 </td> </tr>
<tr><td align="left"> 1904 </td> <td align="right"> 36.3 </td> <td align="right"> 59.4 </td> </tr>
<tr><td align="left"> 1905 </td> <td align="right"> 20.6 </td> <td align="right"> 41.7 </td> </tr>
<tr><td align="left"> 1906 </td> <td align="right"> 18.1 </td> <td align="right"> 19.0 </td> </tr>
<tr><td align="left"> 1907 </td> <td align="right"> 21.4 </td> <td align="right"> 13.0 </td> </tr>
<tr><td align="left"> 1908 </td> <td align="right"> 22.0 </td> <td align="right"> 8.3 </td> </tr>
<tr><td align="left"> 1909 </td> <td align="right"> 25.4 </td> <td align="right"> 9.1 </td> </tr>
<tr><td align="left"> 1910 </td> <td align="right"> 27.1 </td> <td align="right"> 7.4 </td> </tr>
<tr><td align="left"> 1911 </td> <td align="right"> 40.3 </td> <td align="right"> 8.0 </td> </tr>
<tr><td align="left"> 1912 </td> <td align="right"> 57 </td> <td align="right"> 12.3 </td> </tr>
<tr><td align="left"> 1913 </td> <td align="right"> 76.6 </td> <td align="right"> 19.5 </td> </tr>
<tr><td align="left"> 1914 </td> <td align="right"> 52.3 </td> <td align="right"> 45.7 </td> </tr>
<tr><td align="left"> 1915 </td> <td align="right"> 19.5 </td> <td align="right"> 51.1 </td> </tr>
<tr><td align="left"> 1916 </td> <td align="right"> 11.2 </td> <td align="right"> 29.7 </td> </tr>
<tr><td align="left"> 1917 </td> <td align="right"> 7.6 </td> <td align="right"> 15.8 </td> </tr>
<tr><td align="left"> 1918 </td> <td align="right"> 14.6 </td> <td align="right"> 9.7 </td> </tr>
<tr><td align="left"> 1919 </td> <td align="right"> 16.2 </td> <td align="right"> 10.1 </td> </tr>
<tr><td align="left"> 1920 </td> <td align="right"> 24.7 </td> <td align="right"> 8.6 </td> </tr>
</tbody>
</table>
</div>
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec14">Plotting the data </h2>
<p>
<div class="alert alert-block alert-block alert-text-normal">
<b></b>
<p>
<p>
<!-- code=python (!bc pypro) typeset with pygments style "perldoc" -->
<div class="highlight" style="background: #eee8d5"><pre style="line-height: 125%"><span></span><span style="color: #8B008B; font-weight: bold">import</span> <span style="color: #008b45; text-decoration: underline">numpy</span> <span style="color: #8B008B; font-weight: bold">as</span> <span style="color: #008b45; text-decoration: underline">np</span>
<span style="color: #8B008B; font-weight: bold">from</span> <span style="color: #008b45; text-decoration: underline">matplotlib</span> <span style="color: #8B008B; font-weight: bold">import</span> pyplot <span style="color: #8B008B; font-weight: bold">as</span> plt
<span style="color: #228B22"># Load in data file</span>
data = np.loadtxt(<span style="color: #CD5555">&#39;Hudson_Bay.dat&#39;</span>, delimiter=<span style="color: #CD5555">&#39;,&#39;</span>, skiprows=<span style="color: #B452CD">1</span>)
<span style="color: #228B22"># Make arrays containing x-axis and hares and lynx populations</span>
year = data[:,<span style="color: #B452CD">0</span>]
hares = data[:,<span style="color: #B452CD">1</span>]
lynx = data[:,<span style="color: #B452CD">2</span>]
plt.plot(year, hares ,<span style="color: #CD5555">&#39;b-+&#39;</span>, year, lynx, <span style="color: #CD5555">&#39;r-o&#39;</span>)
plt.axis([<span style="color: #B452CD">1900</span>,<span style="color: #B452CD">1920</span>,<span style="color: #B452CD">0</span>, <span style="color: #B452CD">100.0</span>])
plt.xlabel(<span style="color: #CD5555">r&#39;Year&#39;</span>)
plt.ylabel(<span style="color: #CD5555">r&#39;Numbers of hares and lynx &#39;</span>)
plt.legend((<span style="color: #CD5555">&#39;Hares&#39;</span>,<span style="color: #CD5555">&#39;Lynx&#39;</span>), loc=<span style="color: #CD5555">&#39;upper right&#39;</span>)
plt.title(<span style="color: #CD5555">r&#39;Population of hares and lynx from 1900-1920 (x1000)}&#39;</span>)
plt.savefig(<span style="color: #CD5555">&#39;Hudson_Bay_data.pdf&#39;</span>)
plt.savefig(<span style="color: #CD5555">&#39;Hudson_Bay_data.png&#39;</span>)
plt.show()
</pre></div>
</div>
<p>
% if FORMAT != 'ipynb':
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec15">Hares and lynx in Hudson bay from 1900 to 1920 </h2>
<p>
<br /><br /><center><p><img src="fig/Hudson_Bay_data.png" align="bottom" width=700></p></center><br /><br />
% endif
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec16">Why now create a computer model for the hare and lynx populations? </h2>
<div class="alert alert-block alert-block alert-text-normal">
<b></b>
<p>
% if FORMAT == 'ipynb':
We see from the plot that there are indeed fluctuations.
We would like to create a mathematical model that explains these
population fluctuations. Ecologists have predicted that in a simple
predator-prey system that a rise in prey population is followed (with
a lag) by a rise in the predator population. When the predator
population is sufficiently high, then the prey population begins
dropping. After the prey population falls, then the predator
population falls, which allows the prey population to recover and
complete one cycle of this interaction. Thus, we see that
qualitatively oscillations occur. Can a mathematical model predict
this? What causes cycles to slow or speed up? What affects the
amplitude of the oscillation or do you expect to see the oscillations
damp to a stable equilibrium? The models tend to ignore factors like
climate and other complicating factors. How significant are these?
% else:
<ul>
<li> We see oscillations in the data</li>
<li> What causes cycles to slow or speed up?</li>
<li> What affects the amplitude of the oscillation or do you expect to see the oscillations damp to a stable equilibrium?</li>
<li> With a model we can better <em>understand the data</em></li>
<li> More important: we can understand the ecology dynamics of
predator-pray populations</li>
</ul>
% endif
</div>
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec17">The traditional (top-down) approach </h2>
<p>
<div class="alert alert-block alert-block alert-text-normal">
<b></b>
<p>
The classical way (in all books) is to present the Lotka-Volterra equations:
$$
\begin{align*}
\frac{dH}{dt} &= H(a - b L)\\
\frac{dL}{dt} &= - L(d - c H)
\end{align*}
$$
<p>
Here,
<ul>
<li> \( H \) is the number of preys</li>
<li> \( L \) the number of predators</li>
<li> \( a \), \( b \), \( d \), \( c \) are parameters</li>
</ul>
Most books quickly establish the model and then use considerable space on
discussing the qualitative properties of this <em>nonlinear system of
ODEs</em> (which cannot be solved)
</div>
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec18">The &quot;new&quot; discrete bottom-up approach </h2>
<p>
<div class="alert alert-block alert-block alert-text-normal">
<b>The bottom-up approach.</b>
<p>
<!-- !bpop -->
<ul>
<li> Start with experimental data and discuss the methods which have been used to collect the data, the assumptions, the electronic devices, the aims etc. That is, expose the students to the theory and assumptions behind the data that have been collected and motivate for the scientific method.</li>
<li> Where appropriate the students should do the experiment(s) needed to collect the data.</li>
<li> The first programming tasks are to read and visualize the data to see if there are patterns or regularities. This strengthens a research-driven intuition.</li>
<li> Now we want to increase the understanding through modeling.</li>
<li> Most of the biology lies in the <em>derivation</em> of the model. We shall
focus on an intuitive discrete approach that leads to difference
equations that can be programmed <em>and solved</em> directly.</li>
</ul>
<!-- !epop -->
</div>
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec19">Basic (computer-friendly) mathematics notation </h2>
<div class="alert alert-block alert-block alert-text-normal">
<b></b>
<p>
<ul>
<li> Time points: \( t_0,t_1,\ldots,t_m \)</li>
<li> Uniform distribution of time points: \( t_n=n\Delta t \)</li>
<li> \( H^n \): population of hares at time \( t_n \)</li>
<li> \( L^n \): population of lynx at time \( t_n \)</li>
<li> We want to model the changes in populations, \( \Delta H=H^{n+1}-H^n \)
and \( \Delta L=L^{n+1}-L^n \) during a general time interval \( [t_{n+1},t_n] \)
of length \( \Delta t=t_{n+1}-t_n \)</li>
</ul>
</div>
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec20">Basic dynamics of the population of hares </h2>
<p>
<div class="alert alert-block alert-block alert-text-normal">
<b></b>
<p>
The population of hares evolves due to births and deaths exactly as a bacteria population:
$$
\Delta H = a \Delta t H^n
$$
However, hares have an additional loss in the population because
they are eaten by lynx.
All the hares and lynx can form
\( H\cdot L \) pairs in total. When such pairs meet during a time
interval \( \Delta t \), there is some
small probablity that the lynx will eat the hare.
So in fraction \( b\Delta t HL \), the lynx eat hares. This
loss of hares and must be accounted for:
subtracted in the equation for hares:
$$ \Delta H = a\Delta t H^n - b \Delta t H^nL^n$$
</div>
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec21">Basic dynamics of the population of lynx </h2>
<p>
<div class="alert alert-block alert-block alert-text-normal">
<b></b>
<p>
We assume that the primary growth for the lynx population depends on sufficient food for raising lynx kittens, which implies an adequate source of nutrients from predation on hares. Thus, the growth of the lynx population does not only depend of how many lynx there are, but on how many hares they can eat.
In a time interval \( \Delta t HL \) hares and lynx can meet, and in a
fraction \( b\Delta t HL \) the lynx eats the hare. All of this does not
contribute to the growth of lynx, again just a fraction of
\( b\Delta t HL \) that we write as
\( d\Delta t HL \). In addition, lynx die just as in the population
dynamics with one isolated animal population, leading to a loss
\( -c\Delta t L \).
</div>
<p>
<div class="alert alert-block alert-block alert-text-normal">
<b></b>
<p>
The accounting of lynx then looks like
$$ \Delta L = d\Delta t H^nL^n - c\Delta t L^n$$
</div>
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec22">Evolution equations </h2>
<p>
<div class="alert alert-block alert-block alert-text-normal">
<b></b>
<p>
By writing up the definition of \( \Delta H \) and \( \Delta L \), and putting
all assumed known terms \( H^n \) and \( L^n \) on the right-hand side, we have
$$ H^{n+1} = H^n + a\Delta t H^n - b\Delta t H^n L^n $$
$$ L^{n+1} = L^n + d\Delta t H^nL^n - c\Delta t L^n $$
<p>
Note:
<ul>
<li> These equations are ready to be implemented!</li>
<li> But to start, we need \( H^0 \) and \( L^0 \) <br />
(which we can get from the data)</li>
<li> We also need values for \( a \), \( b \), \( d \), \( c \)</li>
</ul>
</div>
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec23">Adapt the model to the Hudson Bay case </h2>
<p>
<div class="alert alert-block alert-block alert-text-normal">
<b></b>
<p>
<ul>
<li> As always, models tend to be general - as here, applicable
to &quot;all&quot; predator-pray systems</li>
<li> The critical issue is whether the <em>interaction</em> between hares and lynx
is sufficiently well modeled by \( \hbox{const}HL \)</li>
<li> The parameters \( a \), \( b \), \( d \), and \( c \) must be
estimated from data</li>
<li> Measure time in years</li>
<li> \( t_0=1900 \), \( t_m=1920 \)</li>
</ul>
</div>
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec24">The program </h2>
<p>
<div class="alert alert-block alert-block alert-text-normal">
<b></b>
<p>
<p>
<!-- code=python (!bc pypro) typeset with pygments style "perldoc" -->
<div class="highlight" style="background: #eee8d5"><pre style="line-height: 125%"><span></span><span style="color: #8B008B; font-weight: bold">import</span> <span style="color: #008b45; text-decoration: underline">numpy</span> <span style="color: #8B008B; font-weight: bold">as</span> <span style="color: #008b45; text-decoration: underline">np</span>
<span style="color: #8B008B; font-weight: bold">import</span> <span style="color: #008b45; text-decoration: underline">matplotlib.pyplot</span> <span style="color: #8B008B; font-weight: bold">as</span> <span style="color: #008b45; text-decoration: underline">plt</span>
<span style="color: #8B008B; font-weight: bold">def</span> <span style="color: #008b45">solver</span>(m, H0, L0, dt, a, b, c, d, t0):
<span style="color: #CD5555">&quot;&quot;&quot;Solve the difference equations for H and L over m years</span>
<span style="color: #CD5555"> with time step dt (measured in years.&quot;&quot;&quot;</span>
num_intervals = <span style="color: #658b00">int</span>(m/<span style="color: #658b00">float</span>(dt))
t = np.linspace(t0, t0 + m, num_intervals+<span style="color: #B452CD">1</span>)
H = np.zeros(t.size)
L = np.zeros(t.size)
<span style="color: #8B008B; font-weight: bold">print</span> <span style="color: #CD5555">&#39;Init:&#39;</span>, H0, L0, dt
H[<span style="color: #B452CD">0</span>] = H0
L[<span style="color: #B452CD">0</span>] = L0
<span style="color: #8B008B; font-weight: bold">for</span> n <span style="color: #8B008B">in</span> <span style="color: #658b00">range</span>(<span style="color: #B452CD">0</span>, <span style="color: #658b00">len</span>(t)-<span style="color: #B452CD">1</span>):
H[n+<span style="color: #B452CD">1</span>] = H[n] + a*dt*H[n] - b*dt*H[n]*L[n]
L[n+<span style="color: #B452CD">1</span>] = L[n] + d*dt*H[n]*L[n] - c*dt*L[n]
<span style="color: #8B008B; font-weight: bold">return</span> H, L, t
<span style="color: #228B22"># Load in data file</span>
data = np.loadtxt(<span style="color: #CD5555">&#39;Hudson_Bay.csv&#39;</span>, delimiter=<span style="color: #CD5555">&#39;,&#39;</span>, skiprows=<span style="color: #B452CD">1</span>)
<span style="color: #228B22"># Make arrays containing x-axis and hares and lynx populations</span>
t_e = data[:,<span style="color: #B452CD">0</span>]
H_e = data[:,<span style="color: #B452CD">1</span>]
L_e = data[:,<span style="color: #B452CD">2</span>]
<span style="color: #228B22"># Simulate using the model</span>
H, L, t = solver(m=<span style="color: #B452CD">20</span>, H0=<span style="color: #B452CD">34.91</span>, L0=<span style="color: #B452CD">3.857</span>, dt=<span style="color: #B452CD">0.1</span>,
a=<span style="color: #B452CD">0.4807</span>, b=<span style="color: #B452CD">0.02482</span>, c=<span style="color: #B452CD">0.9272</span>, d=<span style="color: #B452CD">0.02756</span>,
t0=<span style="color: #B452CD">1900</span>)
<span style="color: #228B22"># Visualize simulations and data</span>
plt.plot(t_e, H_e, <span style="color: #CD5555">&#39;b-+&#39;</span>, t_e, L_e, <span style="color: #CD5555">&#39;r-o&#39;</span>, t, H, <span style="color: #CD5555">&#39;m--&#39;</span>, t, L, <span style="color: #CD5555">&#39;k--&#39;</span>)
plt.xlabel(<span style="color: #CD5555">&#39;Year&#39;</span>)
plt.ylabel(<span style="color: #CD5555">&#39;Numbers of hares and lynx&#39;</span>)
plt.axis([<span style="color: #B452CD">1900</span>, <span style="color: #B452CD">1920</span>, <span style="color: #B452CD">0</span>, <span style="color: #B452CD">140</span>])
plt.title(<span style="color: #CD5555">r&#39;Population of hares and lynx 1900-1920 (x1000)&#39;</span>)
plt.legend((<span style="color: #CD5555">&#39;H_e&#39;</span>, <span style="color: #CD5555">&#39;L_e&#39;</span>, <span style="color: #CD5555">&#39;H&#39;</span>, <span style="color: #CD5555">&#39;L&#39;</span>), loc=<span style="color: #CD5555">&#39;upper left&#39;</span>)
plt.savefig(<span style="color: #CD5555">&#39;Hudson_Bay_sim.pdf&#39;</span>)
plt.savefig(<span style="color: #CD5555">&#39;Hudson_Bay_sim.png&#39;</span>)
plt.show()
</pre></div>
</div>
<p>
% if FORMAT != 'ipynb':
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec25">The plot </h2>
<p>
<br /><br /><center><p><img src="fig/Hudson_Bay_sim.png" align="bottom" width=700></p></center><br /><br />
<p>
% else:
If we perform a least-square fitting, we can find optimal values for the parameters \( a \), \( b \), \( d \), \( c \). The optimal parameters are \( a=0.4807 \), \( b=0.02482 \), \( d=0.9272 \) and \( c=0.02756 \). These parameters result in a slightly modified initial conditions, namely \( H(0) = 34.91 \) and \( L(0)=3.857 \). With these parameters we are now ready to solve the equations and plot these data together with the experimental values.
% endif
<p>
<!-- ------------------- end of main content --------------- -->
+515 -8
View File
@@ -70,17 +70,66 @@ div { text-align: justify; text-justify: inter-word; }
('Different algorithms', 2, None, '___sec2'),
('Software and needed installations', 2, None, '___sec3'),
('Python installers', 2, None, '___sec4'),
('Installing R and C++', 2, None, '___sec5'),
('Installing R, C++, cython or Julia', 2, None, '___sec5'),
('Introduction to Jupyter notebook and available tools',
2,
None,
'___sec6'),
('Representing data, overarching aims', 2, None, '___sec7'),
('Representing data, more examples', 2, None, '___sec8')]}
('Doing it in R', 2, None, '___sec7'),
('Representing data, overarching aims', 2, None, '___sec8'),
('Representing data, more examples', 2, None, '___sec9'),
('Binning of data', 2, None, '___sec10'),
('Adding model complexity: Predator-Prey model from ecology',
2,
None,
'___sec11'),
('Case study from Hudson bay', 2, None, '___sec12'),
('Hudson bay data', 2, None, '___sec13'),
('Plotting the data', 2, None, '___sec14'),
('Hares and lynx in Hudson bay from 1900 to 1920',
2,
None,
'___sec15'),
('Why now create a computer model for the hare and lynx '
'populations?',
2,
None,
'___sec16'),
('The traditional (top-down) approach', 2, None, '___sec17'),
("The ``new'' discrete bottom-up approach", 2, None, '___sec18'),
('Basic (computer-friendly) mathematics notation',
2,
None,
'___sec19'),
('Basic dynamics of the population of hares',
2,
None,
'___sec20'),
('Basic dynamics of the population of lynx', 2, None, '___sec21'),
('Evolution equations', 2, None, '___sec22'),
('Adapt the model to the Hudson Bay case', 2, None, '___sec23'),
('The program', 2, None, '___sec24'),
('The plot', 2, None, '___sec25')]}
end of tocinfo -->
<body>
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
TeX: {
equationNumbers: { autoNumber: "AMS" },
extensions: ["AMSmath.js", "AMSsymbols.js", "autobold.js", "color.js"]
}
});
</script>
<script type="text/javascript" async
src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
</script>
<!-- ------------------- main content ---------------------- -->
@@ -102,7 +151,7 @@ end of tocinfo -->
<center>[2] <b>Department of Physics and Astronomy and National Superconducting Cyclotron Laboratory, Michigan State University</b></center>
<br>
<p>
<center><h4>Nov 27, 2017</h4></center> <!-- date -->
<center><h4>Dec 1, 2017</h4></center> <!-- date -->
<br>
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
@@ -190,7 +239,7 @@ we recommend that you install the following Python packages via <b>pip</b> as
For Python3, replace <b>pip</b> with <b>pip3</b>.
<p>
For OSX user we recommend also, after having installed Xcode, to install <b>brew</b>. Brew allows
For OSX users we recommend also, after having installed Xcode, to install <b>brew</b>. Brew allows
for a seamless installation of additional software via for example
<ol>
@@ -220,7 +269,7 @@ all relevant dependencies for Python, namely
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec5">Installing R and C++ </h2>
<h2 id="___sec5">Installing R, C++, cython or Julia </h2>
<p>
You will also find it convenient to utilize R. Say more about R.
@@ -238,6 +287,13 @@ setup allows you to integrate widely popular softwares and tools for scientific
including symbolic operations, Python offers a unique computational environment. Your Jupyter/IPython notebook
can easily be converted into a nicely rendered <b>PDF</b> file or a Latex file for further processing.
<p>
This never ends,
<p>
If you se the light mark-up language <b>doconce</b> you can convert a standard ascii text file into various HTML
formats, ipython notebooks, latex files, pdf files etc.
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
@@ -246,7 +302,13 @@ can easily be converted into a nicely rendered <b>PDF</b> file or a Latex file f
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec7">Representing data, overarching aims </h2>
<h2 id="___sec7">Doing it in R </h2>
Use the Hudson bay model to load data and make plot in R and with python
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec8">Representing data, overarching aims </h2>
<div class="alert alert-block alert-block alert-text-normal">
<b></b>
<p>
@@ -277,7 +339,7 @@ display(data_pandas)
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec8">Representing data, more examples </h2>
<h2 id="___sec9">Representing data, more examples </h2>
<div class="alert alert-block alert-block alert-text-normal">
<b></b>
<p>
@@ -305,6 +367,451 @@ plt<span style="color: #666666">.</span>show()
</div>
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec10">Binning of data </h2>
Use the Hudson bay model to load data and make plot in R and with python
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec11">Adding model complexity: Predator-Prey model from ecology </h2>
<p>
<div class="alert alert-block alert-block alert-text-normal">
<b></b>
<p>
The population dynamics of a simple predator-prey system is a
classical example shown in many biology textbooks when ecological
systems are discussed. The system contains all elements of the
scientific method:
<ul>
<li> The set up of a specific hypothesis combined with</li>
<li> the experimental methods needed (one can study existing data or perform experiments)</li>
<li> analyzing and interpreting the data and performing further experiments if needed</li>
<li> trying to extract general behaviors and extract eventual laws or patterns</li>
<li> develop mathematical relations for the uncovered regularities/laws and test these by per forming new experiments</li>
</ul>
</div>
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec12">Case study from Hudson bay </h2>
<p>
<div class="alert alert-block alert-block alert-text-normal">
<b></b>
<p>
Lots of data about populations of hares and lynx collected from furs in Hudson Bay, Canada, are available. It is known that the populations oscillate. Why?
We shall demonstrate the scientific method by
<ol>
<li> plotting the data</li>
<li> derive a simple model for the population dynamics</li>
<li> (fitting parameters in the model to the data)</li>
<li> using the model predict the evolution other predator-pray systems</li>
</ol>
</div>
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec13">Hudson bay data </h2>
<p>
<div class="alert alert-block alert-block alert-text-normal">
<b></b>
<p>
% if FORMAT == 'ipynb':
Most mammalian predators rely on a variety of prey, which complicates mathematical modeling; however, a few predators have become highly specialized and seek almost exclusively a single prey species. An example of this simplified predator-prey interaction is seen in Canadian northern forests, where the populations of the lynx and the snowshoe hare are intertwined in a life and death struggle.
<p>
One reason that this particular system has been so extensively studied is that the Hudson Bay company kept careful records of all furs from the early 1800s into the 1900s. The records for the furs collected by the Hudson Bay company showed distinct oscillations (approximately 12 year periods), suggesting that these species caused almost periodic fluctuations of each other's populations. The table here shows data from 1900 to 1920.
% endif
<p>
<table border="1">
<thead>
<tr><th align="center">Year</th> <th align="center">Hares (x1000)</th> <th align="center">Lynx (x1000)</th> </tr>
</thead>
<tbody>
<tr><td align="left"> 1900 </td> <td align="right"> 30.0 </td> <td align="right"> 4.0 </td> </tr>
<tr><td align="left"> 1901 </td> <td align="right"> 47.2 </td> <td align="right"> 6.1 </td> </tr>
<tr><td align="left"> 1902 </td> <td align="right"> 70.2 </td> <td align="right"> 9.8 </td> </tr>
<tr><td align="left"> 1903 </td> <td align="right"> 77.4 </td> <td align="right"> 35.2 </td> </tr>
<tr><td align="left"> 1904 </td> <td align="right"> 36.3 </td> <td align="right"> 59.4 </td> </tr>
<tr><td align="left"> 1905 </td> <td align="right"> 20.6 </td> <td align="right"> 41.7 </td> </tr>
<tr><td align="left"> 1906 </td> <td align="right"> 18.1 </td> <td align="right"> 19.0 </td> </tr>
<tr><td align="left"> 1907 </td> <td align="right"> 21.4 </td> <td align="right"> 13.0 </td> </tr>
<tr><td align="left"> 1908 </td> <td align="right"> 22.0 </td> <td align="right"> 8.3 </td> </tr>
<tr><td align="left"> 1909 </td> <td align="right"> 25.4 </td> <td align="right"> 9.1 </td> </tr>
<tr><td align="left"> 1910 </td> <td align="right"> 27.1 </td> <td align="right"> 7.4 </td> </tr>
<tr><td align="left"> 1911 </td> <td align="right"> 40.3 </td> <td align="right"> 8.0 </td> </tr>
<tr><td align="left"> 1912 </td> <td align="right"> 57 </td> <td align="right"> 12.3 </td> </tr>
<tr><td align="left"> 1913 </td> <td align="right"> 76.6 </td> <td align="right"> 19.5 </td> </tr>
<tr><td align="left"> 1914 </td> <td align="right"> 52.3 </td> <td align="right"> 45.7 </td> </tr>
<tr><td align="left"> 1915 </td> <td align="right"> 19.5 </td> <td align="right"> 51.1 </td> </tr>
<tr><td align="left"> 1916 </td> <td align="right"> 11.2 </td> <td align="right"> 29.7 </td> </tr>
<tr><td align="left"> 1917 </td> <td align="right"> 7.6 </td> <td align="right"> 15.8 </td> </tr>
<tr><td align="left"> 1918 </td> <td align="right"> 14.6 </td> <td align="right"> 9.7 </td> </tr>
<tr><td align="left"> 1919 </td> <td align="right"> 16.2 </td> <td align="right"> 10.1 </td> </tr>
<tr><td align="left"> 1920 </td> <td align="right"> 24.7 </td> <td align="right"> 8.6 </td> </tr>
</tbody>
</table>
</div>
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec14">Plotting the data </h2>
<p>
<div class="alert alert-block alert-block alert-text-normal">
<b></b>
<p>
<p>
<!-- code=python (!bc pypro) typeset with pygments style "default" -->
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%"><span></span><span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">numpy</span> <span style="color: #008000; font-weight: bold">as</span> <span style="color: #0000FF; font-weight: bold">np</span>
<span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">matplotlib</span> <span style="color: #008000; font-weight: bold">import</span> pyplot <span style="color: #008000; font-weight: bold">as</span> plt
<span style="color: #408080; font-style: italic"># Load in data file</span>
data <span style="color: #666666">=</span> np<span style="color: #666666">.</span>loadtxt(<span style="color: #BA2121">&#39;Hudson_Bay.dat&#39;</span>, delimiter<span style="color: #666666">=</span><span style="color: #BA2121">&#39;,&#39;</span>, skiprows<span style="color: #666666">=1</span>)
<span style="color: #408080; font-style: italic"># Make arrays containing x-axis and hares and lynx populations</span>
year <span style="color: #666666">=</span> data[:,<span style="color: #666666">0</span>]
hares <span style="color: #666666">=</span> data[:,<span style="color: #666666">1</span>]
lynx <span style="color: #666666">=</span> data[:,<span style="color: #666666">2</span>]
plt<span style="color: #666666">.</span>plot(year, hares ,<span style="color: #BA2121">&#39;b-+&#39;</span>, year, lynx, <span style="color: #BA2121">&#39;r-o&#39;</span>)
plt<span style="color: #666666">.</span>axis([<span style="color: #666666">1900</span>,<span style="color: #666666">1920</span>,<span style="color: #666666">0</span>, <span style="color: #666666">100.0</span>])
plt<span style="color: #666666">.</span>xlabel(<span style="color: #BA2121">r&#39;Year&#39;</span>)
plt<span style="color: #666666">.</span>ylabel(<span style="color: #BA2121">r&#39;Numbers of hares and lynx &#39;</span>)
plt<span style="color: #666666">.</span>legend((<span style="color: #BA2121">&#39;Hares&#39;</span>,<span style="color: #BA2121">&#39;Lynx&#39;</span>), loc<span style="color: #666666">=</span><span style="color: #BA2121">&#39;upper right&#39;</span>)
plt<span style="color: #666666">.</span>title(<span style="color: #BA2121">r&#39;Population of hares and lynx from 1900-1920 (x1000)}&#39;</span>)
plt<span style="color: #666666">.</span>savefig(<span style="color: #BA2121">&#39;Hudson_Bay_data.pdf&#39;</span>)
plt<span style="color: #666666">.</span>savefig(<span style="color: #BA2121">&#39;Hudson_Bay_data.png&#39;</span>)
plt<span style="color: #666666">.</span>show()
</pre></div>
</div>
<p>
% if FORMAT != 'ipynb':
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec15">Hares and lynx in Hudson bay from 1900 to 1920 </h2>
<p>
<br /><br /><center><p><img src="fig/Hudson_Bay_data.png" align="bottom" width=700></p></center><br /><br />
% endif
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec16">Why now create a computer model for the hare and lynx populations? </h2>
<div class="alert alert-block alert-block alert-text-normal">
<b></b>
<p>
% if FORMAT == 'ipynb':
We see from the plot that there are indeed fluctuations.
We would like to create a mathematical model that explains these
population fluctuations. Ecologists have predicted that in a simple
predator-prey system that a rise in prey population is followed (with
a lag) by a rise in the predator population. When the predator
population is sufficiently high, then the prey population begins
dropping. After the prey population falls, then the predator
population falls, which allows the prey population to recover and
complete one cycle of this interaction. Thus, we see that
qualitatively oscillations occur. Can a mathematical model predict
this? What causes cycles to slow or speed up? What affects the
amplitude of the oscillation or do you expect to see the oscillations
damp to a stable equilibrium? The models tend to ignore factors like
climate and other complicating factors. How significant are these?
% else:
<ul>
<li> We see oscillations in the data</li>
<li> What causes cycles to slow or speed up?</li>
<li> What affects the amplitude of the oscillation or do you expect to see the oscillations damp to a stable equilibrium?</li>
<li> With a model we can better <em>understand the data</em></li>
<li> More important: we can understand the ecology dynamics of
predator-pray populations</li>
</ul>
% endif
</div>
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec17">The traditional (top-down) approach </h2>
<p>
<div class="alert alert-block alert-block alert-text-normal">
<b></b>
<p>
The classical way (in all books) is to present the Lotka-Volterra equations:
$$
\begin{align*}
\frac{dH}{dt} &= H(a - b L)\\
\frac{dL}{dt} &= - L(d - c H)
\end{align*}
$$
<p>
Here,
<ul>
<li> \( H \) is the number of preys</li>
<li> \( L \) the number of predators</li>
<li> \( a \), \( b \), \( d \), \( c \) are parameters</li>
</ul>
Most books quickly establish the model and then use considerable space on
discussing the qualitative properties of this <em>nonlinear system of
ODEs</em> (which cannot be solved)
</div>
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec18">The &quot;new&quot; discrete bottom-up approach </h2>
<p>
<div class="alert alert-block alert-block alert-text-normal">
<b>The bottom-up approach.</b>
<p>
<!-- !bpop -->
<ul>
<li> Start with experimental data and discuss the methods which have been used to collect the data, the assumptions, the electronic devices, the aims etc. That is, expose the students to the theory and assumptions behind the data that have been collected and motivate for the scientific method.</li>
<li> Where appropriate the students should do the experiment(s) needed to collect the data.</li>
<li> The first programming tasks are to read and visualize the data to see if there are patterns or regularities. This strengthens a research-driven intuition.</li>
<li> Now we want to increase the understanding through modeling.</li>
<li> Most of the biology lies in the <em>derivation</em> of the model. We shall
focus on an intuitive discrete approach that leads to difference
equations that can be programmed <em>and solved</em> directly.</li>
</ul>
<!-- !epop -->
</div>
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec19">Basic (computer-friendly) mathematics notation </h2>
<div class="alert alert-block alert-block alert-text-normal">
<b></b>
<p>
<ul>
<li> Time points: \( t_0,t_1,\ldots,t_m \)</li>
<li> Uniform distribution of time points: \( t_n=n\Delta t \)</li>
<li> \( H^n \): population of hares at time \( t_n \)</li>
<li> \( L^n \): population of lynx at time \( t_n \)</li>
<li> We want to model the changes in populations, \( \Delta H=H^{n+1}-H^n \)
and \( \Delta L=L^{n+1}-L^n \) during a general time interval \( [t_{n+1},t_n] \)
of length \( \Delta t=t_{n+1}-t_n \)</li>
</ul>
</div>
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec20">Basic dynamics of the population of hares </h2>
<p>
<div class="alert alert-block alert-block alert-text-normal">
<b></b>
<p>
The population of hares evolves due to births and deaths exactly as a bacteria population:
$$
\Delta H = a \Delta t H^n
$$
However, hares have an additional loss in the population because
they are eaten by lynx.
All the hares and lynx can form
\( H\cdot L \) pairs in total. When such pairs meet during a time
interval \( \Delta t \), there is some
small probablity that the lynx will eat the hare.
So in fraction \( b\Delta t HL \), the lynx eat hares. This
loss of hares and must be accounted for:
subtracted in the equation for hares:
$$ \Delta H = a\Delta t H^n - b \Delta t H^nL^n$$
</div>
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec21">Basic dynamics of the population of lynx </h2>
<p>
<div class="alert alert-block alert-block alert-text-normal">
<b></b>
<p>
We assume that the primary growth for the lynx population depends on sufficient food for raising lynx kittens, which implies an adequate source of nutrients from predation on hares. Thus, the growth of the lynx population does not only depend of how many lynx there are, but on how many hares they can eat.
In a time interval \( \Delta t HL \) hares and lynx can meet, and in a
fraction \( b\Delta t HL \) the lynx eats the hare. All of this does not
contribute to the growth of lynx, again just a fraction of
\( b\Delta t HL \) that we write as
\( d\Delta t HL \). In addition, lynx die just as in the population
dynamics with one isolated animal population, leading to a loss
\( -c\Delta t L \).
</div>
<p>
<div class="alert alert-block alert-block alert-text-normal">
<b></b>
<p>
The accounting of lynx then looks like
$$ \Delta L = d\Delta t H^nL^n - c\Delta t L^n$$
</div>
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec22">Evolution equations </h2>
<p>
<div class="alert alert-block alert-block alert-text-normal">
<b></b>
<p>
By writing up the definition of \( \Delta H \) and \( \Delta L \), and putting
all assumed known terms \( H^n \) and \( L^n \) on the right-hand side, we have
$$ H^{n+1} = H^n + a\Delta t H^n - b\Delta t H^n L^n $$
$$ L^{n+1} = L^n + d\Delta t H^nL^n - c\Delta t L^n $$
<p>
Note:
<ul>
<li> These equations are ready to be implemented!</li>
<li> But to start, we need \( H^0 \) and \( L^0 \) <br />
(which we can get from the data)</li>
<li> We also need values for \( a \), \( b \), \( d \), \( c \)</li>
</ul>
</div>
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec23">Adapt the model to the Hudson Bay case </h2>
<p>
<div class="alert alert-block alert-block alert-text-normal">
<b></b>
<p>
<ul>
<li> As always, models tend to be general - as here, applicable
to &quot;all&quot; predator-pray systems</li>
<li> The critical issue is whether the <em>interaction</em> between hares and lynx
is sufficiently well modeled by \( \hbox{const}HL \)</li>
<li> The parameters \( a \), \( b \), \( d \), and \( c \) must be
estimated from data</li>
<li> Measure time in years</li>
<li> \( t_0=1900 \), \( t_m=1920 \)</li>
</ul>
</div>
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec24">The program </h2>
<p>
<div class="alert alert-block alert-block alert-text-normal">
<b></b>
<p>
<p>
<!-- code=python (!bc pypro) typeset with pygments style "default" -->
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%"><span></span><span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">numpy</span> <span style="color: #008000; font-weight: bold">as</span> <span style="color: #0000FF; font-weight: bold">np</span>
<span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">matplotlib.pyplot</span> <span style="color: #008000; font-weight: bold">as</span> <span style="color: #0000FF; font-weight: bold">plt</span>
<span style="color: #008000; font-weight: bold">def</span> <span style="color: #0000FF">solver</span>(m, H0, L0, dt, a, b, c, d, t0):
<span style="color: #BA2121; font-style: italic">&quot;&quot;&quot;Solve the difference equations for H and L over m years</span>
<span style="color: #BA2121; font-style: italic"> with time step dt (measured in years.&quot;&quot;&quot;</span>
num_intervals <span style="color: #666666">=</span> <span style="color: #008000">int</span>(m<span style="color: #666666">/</span><span style="color: #008000">float</span>(dt))
t <span style="color: #666666">=</span> np<span style="color: #666666">.</span>linspace(t0, t0 <span style="color: #666666">+</span> m, num_intervals<span style="color: #666666">+1</span>)
H <span style="color: #666666">=</span> np<span style="color: #666666">.</span>zeros(t<span style="color: #666666">.</span>size)
L <span style="color: #666666">=</span> np<span style="color: #666666">.</span>zeros(t<span style="color: #666666">.</span>size)
<span style="color: #008000; font-weight: bold">print</span> <span style="color: #BA2121">&#39;Init:&#39;</span>, H0, L0, dt
H[<span style="color: #666666">0</span>] <span style="color: #666666">=</span> H0
L[<span style="color: #666666">0</span>] <span style="color: #666666">=</span> L0
<span style="color: #008000; font-weight: bold">for</span> n <span style="color: #AA22FF; font-weight: bold">in</span> <span style="color: #008000">range</span>(<span style="color: #666666">0</span>, <span style="color: #008000">len</span>(t)<span style="color: #666666">-1</span>):
H[n<span style="color: #666666">+1</span>] <span style="color: #666666">=</span> H[n] <span style="color: #666666">+</span> a<span style="color: #666666">*</span>dt<span style="color: #666666">*</span>H[n] <span style="color: #666666">-</span> b<span style="color: #666666">*</span>dt<span style="color: #666666">*</span>H[n]<span style="color: #666666">*</span>L[n]
L[n<span style="color: #666666">+1</span>] <span style="color: #666666">=</span> L[n] <span style="color: #666666">+</span> d<span style="color: #666666">*</span>dt<span style="color: #666666">*</span>H[n]<span style="color: #666666">*</span>L[n] <span style="color: #666666">-</span> c<span style="color: #666666">*</span>dt<span style="color: #666666">*</span>L[n]
<span style="color: #008000; font-weight: bold">return</span> H, L, t
<span style="color: #408080; font-style: italic"># Load in data file</span>
data <span style="color: #666666">=</span> np<span style="color: #666666">.</span>loadtxt(<span style="color: #BA2121">&#39;Hudson_Bay.csv&#39;</span>, delimiter<span style="color: #666666">=</span><span style="color: #BA2121">&#39;,&#39;</span>, skiprows<span style="color: #666666">=1</span>)
<span style="color: #408080; font-style: italic"># Make arrays containing x-axis and hares and lynx populations</span>
t_e <span style="color: #666666">=</span> data[:,<span style="color: #666666">0</span>]
H_e <span style="color: #666666">=</span> data[:,<span style="color: #666666">1</span>]
L_e <span style="color: #666666">=</span> data[:,<span style="color: #666666">2</span>]
<span style="color: #408080; font-style: italic"># Simulate using the model</span>
H, L, t <span style="color: #666666">=</span> solver(m<span style="color: #666666">=20</span>, H0<span style="color: #666666">=34.91</span>, L0<span style="color: #666666">=3.857</span>, dt<span style="color: #666666">=0.1</span>,
a<span style="color: #666666">=0.4807</span>, b<span style="color: #666666">=0.02482</span>, c<span style="color: #666666">=0.9272</span>, d<span style="color: #666666">=0.02756</span>,
t0<span style="color: #666666">=1900</span>)
<span style="color: #408080; font-style: italic"># Visualize simulations and data</span>
plt<span style="color: #666666">.</span>plot(t_e, H_e, <span style="color: #BA2121">&#39;b-+&#39;</span>, t_e, L_e, <span style="color: #BA2121">&#39;r-o&#39;</span>, t, H, <span style="color: #BA2121">&#39;m--&#39;</span>, t, L, <span style="color: #BA2121">&#39;k--&#39;</span>)
plt<span style="color: #666666">.</span>xlabel(<span style="color: #BA2121">&#39;Year&#39;</span>)
plt<span style="color: #666666">.</span>ylabel(<span style="color: #BA2121">&#39;Numbers of hares and lynx&#39;</span>)
plt<span style="color: #666666">.</span>axis([<span style="color: #666666">1900</span>, <span style="color: #666666">1920</span>, <span style="color: #666666">0</span>, <span style="color: #666666">140</span>])
plt<span style="color: #666666">.</span>title(<span style="color: #BA2121">r&#39;Population of hares and lynx 1900-1920 (x1000)&#39;</span>)
plt<span style="color: #666666">.</span>legend((<span style="color: #BA2121">&#39;H_e&#39;</span>, <span style="color: #BA2121">&#39;L_e&#39;</span>, <span style="color: #BA2121">&#39;H&#39;</span>, <span style="color: #BA2121">&#39;L&#39;</span>), loc<span style="color: #666666">=</span><span style="color: #BA2121">&#39;upper left&#39;</span>)
plt<span style="color: #666666">.</span>savefig(<span style="color: #BA2121">&#39;Hudson_Bay_sim.pdf&#39;</span>)
plt<span style="color: #666666">.</span>savefig(<span style="color: #BA2121">&#39;Hudson_Bay_sim.png&#39;</span>)
plt<span style="color: #666666">.</span>show()
</pre></div>
</div>
<p>
% if FORMAT != 'ipynb':
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec25">The plot </h2>
<p>
<br /><br /><center><p><img src="fig/Hudson_Bay_sim.png" align="bottom" width=700></p></center><br /><br />
<p>
% else:
If we perform a least-square fitting, we can find optimal values for the parameters \( a \), \( b \), \( d \), \( c \). The optimal parameters are \( a=0.4807 \), \( b=0.02482 \), \( d=0.9272 \) and \( c=0.02756 \). These parameters result in a slightly modified initial conditions, namely \( H(0) = 34.91 \) and \( L(0)=3.857 \). With these parameters we are now ready to solve the equations and plot these data together with the experimental values.
% endif
<p>
<!-- ------------------- end of main content --------------- -->
+452 -3
View File
@@ -10,7 +10,7 @@
"<!-- Author: --> \n",
"**Morten Hjorth-Jensen**, Department of Physics, University of Oslo and Department of Physics and Astronomy and National Superconducting Cyclotron Laboratory, Michigan State University\n",
"\n",
"Date: **Nov 27, 2017**\n",
"Date: **Dec 1, 2017**\n",
"\n",
"Copyright 1999-2017, Morten Hjorth-Jensen. Released under CC Attribution-NonCommercial 4.0 license\n",
"\n",
@@ -88,7 +88,7 @@
"\n",
"For Python3, replace **pip** with **pip3**.\n",
"\n",
"For OSX user we recommend also, after having installed Xcode, to install **brew**. Brew allows \n",
"For OSX users we recommend also, after having installed Xcode, to install **brew**. Brew allows \n",
"for a seamless installation of additional software via for example\n",
"1. brew install python3\n",
"\n",
@@ -105,7 +105,7 @@
"\n",
"2. Enthought canopy\n",
"\n",
"## Installing R and C++\n",
"## Installing R, C++, cython or Julia\n",
"\n",
"You will also find it convenient to utilize R. Say more about R. \n",
"Jupyter/Ipython notebook allows you run **R** code interactively in your browser. The software library **R** is \n",
@@ -120,9 +120,15 @@
"including symbolic operations, Python offers a unique computational environment. Your Jupyter/IPython notebook \n",
"can easily be converted into a nicely rendered **PDF** file or a Latex file for further processing.\n",
"\n",
"This never ends, \n",
"\n",
"If you se the light mark-up language **doconce** you can convert a standard ascii text file into various HTML \n",
"formats, ipython notebooks, latex files, pdf files etc. \n",
"\n",
"## Introduction to Jupyter notebook and available tools\n",
"\n",
"## Doing it in R\n",
"Use the Hudson bay model to load data and make plot in R and with python\n",
"\n",
"\n",
"## Representing data, overarching aims"
@@ -188,6 +194,449 @@
"plt.plot(line, regline.predict(line), label= \"Linear Rgression\")\n",
"plt.show()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Binning of data\n",
"Use the Hudson bay model to load data and make plot in R and with python\n",
"\n",
"\n",
"\n",
"\n",
"## Adding model complexity: Predator-Prey model from ecology\n",
"\n",
"The population dynamics of a simple predator-prey system is a\n",
"classical example shown in many biology textbooks when ecological\n",
"systems are discussed. The system contains all elements of the\n",
"scientific method:\n",
"\n",
" * The set up of a specific hypothesis combined with\n",
"\n",
" * the experimental methods needed (one can study existing data or perform experiments)\n",
"\n",
" * analyzing and interpreting the data and performing further experiments if needed\n",
"\n",
" * trying to extract general behaviors and extract eventual laws or patterns\n",
"\n",
" * develop mathematical relations for the uncovered regularities/laws and test these by per forming new experiments\n",
"\n",
"\n",
"\n",
"\n",
"## Case study from Hudson bay\n",
"\n",
"Lots of data about populations of hares and lynx collected from furs in Hudson Bay, Canada, are available. It is known that the populations oscillate. Why?\n",
"We shall demonstrate the scientific method by\n",
"\n",
"1. plotting the data\n",
"\n",
"2. derive a simple model for the population dynamics\n",
"\n",
"3. (fitting parameters in the model to the data)\n",
"\n",
"4. using the model predict the evolution other predator-pray systems\n",
"\n",
"\n",
"\n",
"## Hudson bay data\n",
"\n",
"\n",
"% if FORMAT == 'ipynb':\n",
"Most mammalian predators rely on a variety of prey, which complicates mathematical modeling; however, a few predators have become highly specialized and seek almost exclusively a single prey species. An example of this simplified predator-prey interaction is seen in Canadian northern forests, where the populations of the lynx and the snowshoe hare are intertwined in a life and death struggle.\n",
"\n",
"One reason that this particular system has been so extensively studied is that the Hudson Bay company kept careful records of all furs from the early 1800s into the 1900s. The records for the furs collected by the Hudson Bay company showed distinct oscillations (approximately 12 year periods), suggesting that these species caused almost periodic fluctuations of each other's populations. The table here shows data from 1900 to 1920.\n",
"% endif\n",
"\n",
"<table border=\"1\">\n",
"<thead>\n",
"<tr><th align=\"center\">Year</th> <th align=\"center\">Hares (x1000)</th> <th align=\"center\">Lynx (x1000)</th> </tr>\n",
"</thead>\n",
"<tbody>\n",
"<tr><td align=\"left\"> 1900 </td> <td align=\"right\"> 30.0 </td> <td align=\"right\"> 4.0 </td> </tr>\n",
"<tr><td align=\"left\"> 1901 </td> <td align=\"right\"> 47.2 </td> <td align=\"right\"> 6.1 </td> </tr>\n",
"<tr><td align=\"left\"> 1902 </td> <td align=\"right\"> 70.2 </td> <td align=\"right\"> 9.8 </td> </tr>\n",
"<tr><td align=\"left\"> 1903 </td> <td align=\"right\"> 77.4 </td> <td align=\"right\"> 35.2 </td> </tr>\n",
"<tr><td align=\"left\"> 1904 </td> <td align=\"right\"> 36.3 </td> <td align=\"right\"> 59.4 </td> </tr>\n",
"<tr><td align=\"left\"> 1905 </td> <td align=\"right\"> 20.6 </td> <td align=\"right\"> 41.7 </td> </tr>\n",
"<tr><td align=\"left\"> 1906 </td> <td align=\"right\"> 18.1 </td> <td align=\"right\"> 19.0 </td> </tr>\n",
"<tr><td align=\"left\"> 1907 </td> <td align=\"right\"> 21.4 </td> <td align=\"right\"> 13.0 </td> </tr>\n",
"<tr><td align=\"left\"> 1908 </td> <td align=\"right\"> 22.0 </td> <td align=\"right\"> 8.3 </td> </tr>\n",
"<tr><td align=\"left\"> 1909 </td> <td align=\"right\"> 25.4 </td> <td align=\"right\"> 9.1 </td> </tr>\n",
"<tr><td align=\"left\"> 1910 </td> <td align=\"right\"> 27.1 </td> <td align=\"right\"> 7.4 </td> </tr>\n",
"<tr><td align=\"left\"> 1911 </td> <td align=\"right\"> 40.3 </td> <td align=\"right\"> 8.0 </td> </tr>\n",
"<tr><td align=\"left\"> 1912 </td> <td align=\"right\"> 57 </td> <td align=\"right\"> 12.3 </td> </tr>\n",
"<tr><td align=\"left\"> 1913 </td> <td align=\"right\"> 76.6 </td> <td align=\"right\"> 19.5 </td> </tr>\n",
"<tr><td align=\"left\"> 1914 </td> <td align=\"right\"> 52.3 </td> <td align=\"right\"> 45.7 </td> </tr>\n",
"<tr><td align=\"left\"> 1915 </td> <td align=\"right\"> 19.5 </td> <td align=\"right\"> 51.1 </td> </tr>\n",
"<tr><td align=\"left\"> 1916 </td> <td align=\"right\"> 11.2 </td> <td align=\"right\"> 29.7 </td> </tr>\n",
"<tr><td align=\"left\"> 1917 </td> <td align=\"right\"> 7.6 </td> <td align=\"right\"> 15.8 </td> </tr>\n",
"<tr><td align=\"left\"> 1918 </td> <td align=\"right\"> 14.6 </td> <td align=\"right\"> 9.7 </td> </tr>\n",
"<tr><td align=\"left\"> 1919 </td> <td align=\"right\"> 16.2 </td> <td align=\"right\"> 10.1 </td> </tr>\n",
"<tr><td align=\"left\"> 1920 </td> <td align=\"right\"> 24.7 </td> <td align=\"right\"> 8.6 </td> </tr>\n",
"</tbody>\n",
"</table>\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"## Plotting the data"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import numpy as np\n",
"from matplotlib import pyplot as plt\n",
"\n",
"# Load in data file\n",
"data = np.loadtxt('Hudson_Bay.dat', delimiter=',', skiprows=1)\n",
"# Make arrays containing x-axis and hares and lynx populations\n",
"year = data[:,0]\n",
"hares = data[:,1]\n",
"lynx = data[:,2]\n",
"\n",
"plt.plot(year, hares ,'b-+', year, lynx, 'r-o')\n",
"plt.axis([1900,1920,0, 100.0])\n",
"plt.xlabel(r'Year')\n",
"plt.ylabel(r'Numbers of hares and lynx ')\n",
"plt.legend(('Hares','Lynx'), loc='upper right')\n",
"plt.title(r'Population of hares and lynx from 1900-1920 (x1000)}')\n",
"plt.savefig('Hudson_Bay_data.pdf')\n",
"plt.savefig('Hudson_Bay_data.png')\n",
"plt.show()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"% if FORMAT != 'ipynb':\n",
"## Hares and lynx in Hudson bay from 1900 to 1920\n",
"\n",
"<!-- dom:FIGURE: [fig/Hudson_Bay_data.png, width=700 frac=0.9] -->\n",
"<!-- begin figure -->\n",
"\n",
"<p></p>\n",
"<img src=\"fig/Hudson_Bay_data.png\" width=700>\n",
"\n",
"<!-- end figure -->\n",
"\n",
"% endif\n",
"\n",
"\n",
"## Why now create a computer model for the hare and lynx populations?\n",
"% if FORMAT == 'ipynb':\n",
"We see from the plot that there are indeed fluctuations.\n",
"We would like to create a mathematical model that explains these\n",
"population fluctuations. Ecologists have predicted that in a simple\n",
"predator-prey system that a rise in prey population is followed (with\n",
"a lag) by a rise in the predator population. When the predator\n",
"population is sufficiently high, then the prey population begins\n",
"dropping. After the prey population falls, then the predator\n",
"population falls, which allows the prey population to recover and\n",
"complete one cycle of this interaction. Thus, we see that\n",
"qualitatively oscillations occur. Can a mathematical model predict\n",
"this? What causes cycles to slow or speed up? What affects the\n",
"amplitude of the oscillation or do you expect to see the oscillations\n",
"damp to a stable equilibrium? The models tend to ignore factors like\n",
"climate and other complicating factors. How significant are these?\n",
"% else:\n",
" * We see oscillations in the data\n",
"\n",
" * What causes cycles to slow or speed up?\n",
"\n",
" * What affects the amplitude of the oscillation or do you expect to see the oscillations damp to a stable equilibrium?\n",
"\n",
" * With a model we can better *understand the data*\n",
"\n",
" * More important: we can understand the ecology dynamics of\n",
" predator-pray populations\n",
"\n",
"% endif\n",
"\n",
"\n",
"\n",
"\n",
"## The traditional (top-down) approach\n",
"\n",
"The classical way (in all books) is to present the Lotka-Volterra equations:"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"$$\n",
"\\begin{align*}\n",
"\\frac{dH}{dt} &= H(a - b L)\\\\\n",
"\\frac{dL}{dt} &= - L(d - c H)\n",
"\\end{align*}\n",
"$$"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Here,\n",
"\n",
" * $H$ is the number of preys\n",
"\n",
" * $L$ the number of predators\n",
"\n",
" * $a$, $b$, $d$, $c$ are parameters\n",
"\n",
"Most books quickly establish the model and then use considerable space on\n",
"discussing the qualitative properties of this *nonlinear system of\n",
"ODEs* (which cannot be solved)\n",
"\n",
"\n",
"\n",
"\n",
"## The \"new\" discrete bottom-up approach\n",
"\n",
"**The bottom-up approach.**\n",
"\n",
" * Start with experimental data and discuss the methods which have been used to collect the data, the assumptions, the electronic devices, the aims etc. That is, expose the students to the theory and assumptions behind the data that have been collected and motivate for the scientific method.\n",
"\n",
" * Where appropriate the students should do the experiment(s) needed to collect the data.\n",
"\n",
" * The first programming tasks are to read and visualize the data to see if there are patterns or regularities. This strengthens a research-driven intuition.\n",
"\n",
" * Now we want to increase the understanding through modeling.\n",
"\n",
" * Most of the biology lies in the *derivation* of the model. We shall\n",
" focus on an intuitive discrete approach that leads to difference\n",
" equations that can be programmed *and solved* directly.\n",
"\n",
"\n",
"\n",
"## Basic (computer-friendly) mathematics notation\n",
" * Time points: $t_0,t_1,\\ldots,t_m$\n",
"\n",
" * Uniform distribution of time points: $t_n=n\\Delta t$\n",
"\n",
" * $H^n$: population of hares at time $t_n$\n",
"\n",
" * $L^n$: population of lynx at time $t_n$\n",
"\n",
" * We want to model the changes in populations, $\\Delta H=H^{n+1}-H^n$\n",
" and $\\Delta L=L^{n+1}-L^n$ during a general time interval $[t_{n+1},t_n]$\n",
" of length $\\Delta t=t_{n+1}-t_n$\n",
"\n",
"\n",
"\n",
"## Basic dynamics of the population of hares\n",
"\n",
"The population of hares evolves due to births and deaths exactly as a bacteria population:"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"$$\n",
"\\Delta H = a \\Delta t H^n\n",
"$$"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"However, hares have an additional loss in the population because\n",
"they are eaten by lynx.\n",
"All the hares and lynx can form\n",
"$H\\cdot L$ pairs in total. When such pairs meet during a time\n",
"interval $\\Delta t$, there is some\n",
"small probablity that the lynx will eat the hare.\n",
"So in fraction $b\\Delta t HL$, the lynx eat hares. This\n",
"loss of hares and must be accounted for:\n",
"subtracted in the equation for hares:"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"$$\n",
"\\Delta H = a\\Delta t H^n - b \\Delta t H^nL^n\n",
"$$"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Basic dynamics of the population of lynx\n",
"\n",
"We assume that the primary growth for the lynx population depends on sufficient food for raising lynx kittens, which implies an adequate source of nutrients from predation on hares. Thus, the growth of the lynx population does not only depend of how many lynx there are, but on how many hares they can eat.\n",
"In a time interval $\\Delta t HL$ hares and lynx can meet, and in a\n",
"fraction $b\\Delta t HL$ the lynx eats the hare. All of this does not\n",
"contribute to the growth of lynx, again just a fraction of\n",
"$b\\Delta t HL$ that we write as\n",
"$d\\Delta t HL$. In addition, lynx die just as in the population\n",
"dynamics with one isolated animal population, leading to a loss\n",
"$-c\\Delta t L$.\n",
"\n",
"\n",
"\n",
"The accounting of lynx then looks like"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"$$\n",
"\\Delta L = d\\Delta t H^nL^n - c\\Delta t L^n\n",
"$$"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Evolution equations\n",
"\n",
"By writing up the definition of $\\Delta H$ and $\\Delta L$, and putting\n",
"all assumed known terms $H^n$ and $L^n$ on the right-hand side, we have"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"$$\n",
"H^{n+1} = H^n + a\\Delta t H^n - b\\Delta t H^n L^n\n",
"$$"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"$$\n",
"L^{n+1} = L^n + d\\Delta t H^nL^n - c\\Delta t L^n\n",
"$$"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Note:\n",
"\n",
" * These equations are ready to be implemented!\n",
"\n",
" * But to start, we need $H^0$ and $L^0$ \n",
" (which we can get from the data)\n",
"\n",
" * We also need values for $a$, $b$, $d$, $c$\n",
"\n",
"\n",
"\n",
"## Adapt the model to the Hudson Bay case\n",
"\n",
" * As always, models tend to be general - as here, applicable\n",
" to \"all\" predator-pray systems\n",
"\n",
" * The critical issue is whether the *interaction* between hares and lynx\n",
" is sufficiently well modeled by $\\hbox{const}HL$\n",
"\n",
" * The parameters $a$, $b$, $d$, and $c$ must be\n",
" estimated from data\n",
"\n",
" * Measure time in years\n",
"\n",
" * $t_0=1900$, $t_m=1920$\n",
"\n",
"\n",
"\n",
"## The program"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"\n",
"def solver(m, H0, L0, dt, a, b, c, d, t0):\n",
" \"\"\"Solve the difference equations for H and L over m years\n",
" with time step dt (measured in years.\"\"\"\n",
"\n",
" num_intervals = int(m/float(dt))\n",
" t = np.linspace(t0, t0 + m, num_intervals+1)\n",
" H = np.zeros(t.size)\n",
" L = np.zeros(t.size)\n",
"\n",
" print 'Init:', H0, L0, dt\n",
" H[0] = H0\n",
" L[0] = L0\n",
"\n",
" for n in range(0, len(t)-1):\n",
" H[n+1] = H[n] + a*dt*H[n] - b*dt*H[n]*L[n]\n",
" L[n+1] = L[n] + d*dt*H[n]*L[n] - c*dt*L[n]\n",
" return H, L, t\n",
"\n",
"# Load in data file\n",
"data = np.loadtxt('Hudson_Bay.csv', delimiter=',', skiprows=1)\n",
"# Make arrays containing x-axis and hares and lynx populations\n",
"t_e = data[:,0]\n",
"H_e = data[:,1]\n",
"L_e = data[:,2]\n",
"\n",
"# Simulate using the model\n",
"H, L, t = solver(m=20, H0=34.91, L0=3.857, dt=0.1,\n",
" a=0.4807, b=0.02482, c=0.9272, d=0.02756,\n",
" t0=1900)\n",
"\n",
"# Visualize simulations and data\n",
"plt.plot(t_e, H_e, 'b-+', t_e, L_e, 'r-o', t, H, 'm--', t, L, 'k--')\n",
"plt.xlabel('Year')\n",
"plt.ylabel('Numbers of hares and lynx')\n",
"plt.axis([1900, 1920, 0, 140])\n",
"plt.title(r'Population of hares and lynx 1900-1920 (x1000)')\n",
"plt.legend(('H_e', 'L_e', 'H', 'L'), loc='upper left')\n",
"plt.savefig('Hudson_Bay_sim.pdf')\n",
"plt.savefig('Hudson_Bay_sim.png')\n",
"plt.show()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"% if FORMAT != 'ipynb':\n",
"## The plot\n",
"\n",
"<!-- dom:FIGURE: [fig/Hudson_Bay_sim.png, width=700 frac=0.9] -->\n",
"<!-- begin figure -->\n",
"\n",
"<p></p>\n",
"<img src=\"fig/Hudson_Bay_sim.png\" width=700>\n",
"\n",
"<!-- end figure -->\n",
"\n",
"\n",
"% else:\n",
"If we perform a least-square fitting, we can find optimal values for the parameters $a$, $b$, $d$, $c$. The optimal parameters are $a=0.4807$, $b=0.02482$, $d=0.9272$ and $c=0.02756$. These parameters result in a slightly modified initial conditions, namely $H(0) = 34.91$ and $L(0)=3.857$. With these parameters we are now ready to solve the equations and plot these data together with the experimental values.\n",
"% endif"
]
}
],
"metadata": {},
Binary file not shown.
Binary file not shown.
+274
View File
@@ -168,6 +168,280 @@ plt.show()
!eblock
!split
===== Binning of data =====
Use the Hudson bay model to load data and make plot in R and with python
!split
===== Adding model complexity: Predator-Prey model from ecology =====
!bblock
The population dynamics of a simple predator-prey system is a
classical example shown in many biology textbooks when ecological
systems are discussed. The system contains all elements of the
scientific method:
* The set up of a specific hypothesis combined with
* the experimental methods needed (one can study existing data or perform experiments)
* analyzing and interpreting the data and performing further experiments if needed
* trying to extract general behaviors and extract eventual laws or patterns
* develop mathematical relations for the uncovered regularities/laws and test these by per forming new experiments
!eblock
!split
===== Case study from Hudson bay =====
!bblock
Lots of data about populations of hares and lynx collected from furs in Hudson Bay, Canada, are available. It is known that the populations oscillate. Why?
We shall demonstrate the scientific method by
o plotting the data
o derive a simple model for the population dynamics
o (fitting parameters in the model to the data)
o using the model predict the evolution other predator-pray systems
!eblock
!split
===== Hudson bay data =====
!bblock
% if FORMAT == 'ipynb':
Most mammalian predators rely on a variety of prey, which complicates mathematical modeling; however, a few predators have become highly specialized and seek almost exclusively a single prey species. An example of this simplified predator-prey interaction is seen in Canadian northern forests, where the populations of the lynx and the snowshoe hare are intertwined in a life and death struggle.
One reason that this particular system has been so extensively studied is that the Hudson Bay company kept careful records of all furs from the early 1800s into the 1900s. The records for the furs collected by the Hudson Bay company showed distinct oscillations (approximately 12 year periods), suggesting that these species caused almost periodic fluctuations of each other's populations. The table here shows data from 1900 to 1920.
% endif
|------------------------------------------------------|
| Year | Hares (x1000) | Lynx (x1000)|
|---------l-----------------------r--------------r------|
| 1900 | 30.0 | 4.0 |
| 1901 | 47.2 | 6.1 |
| 1902 | 70.2 | 9.8 |
| 1903 | 77.4 | 35.2 |
| 1904 | 36.3 | 59.4 |
| 1905 | 20.6 | 41.7 |
| 1906 | 18.1 | 19.0 |
| 1907 | 21.4 | 13.0 |
| 1908 | 22.0 | 8.3 |
| 1909 | 25.4 | 9.1 |
| 1910 | 27.1 | 7.4 |
| 1911 | 40.3 | 8.0 |
| 1912 | 57 | 12.3 |
| 1913 | 76.6 | 19.5 |
| 1914 | 52.3 | 45.7 |
| 1915 | 19.5 | 51.1 |
| 1916 | 11.2 | 29.7 |
| 1917 | 7.6 | 15.8 |
| 1918 | 14.6 | 9.7 |
| 1919 | 16.2 | 10.1 |
| 1920 | 24.7 | 8.6 |
|------------------------------------------------------|
!eblock
!split
===== Plotting the data =====
!bblock
@@@CODE src/plot_Hudson.py
!eblock
% if FORMAT != 'ipynb':
!split
===== Hares and lynx in Hudson bay from 1900 to 1920 =====
FIGURE: [fig/Hudson_Bay_data, width=700 frac=0.9]
% endif
!split
===== Why now create a computer model for the hare and lynx populations? =====
!bblock
% if FORMAT == 'ipynb':
We see from the plot that there are indeed fluctuations.
We would like to create a mathematical model that explains these
population fluctuations. Ecologists have predicted that in a simple
predator-prey system that a rise in prey population is followed (with
a lag) by a rise in the predator population. When the predator
population is sufficiently high, then the prey population begins
dropping. After the prey population falls, then the predator
population falls, which allows the prey population to recover and
complete one cycle of this interaction. Thus, we see that
qualitatively oscillations occur. Can a mathematical model predict
this? What causes cycles to slow or speed up? What affects the
amplitude of the oscillation or do you expect to see the oscillations
damp to a stable equilibrium? The models tend to ignore factors like
climate and other complicating factors. How significant are these?
% else:
* We see oscillations in the data
* What causes cycles to slow or speed up?
* What affects the amplitude of the oscillation or do you expect to see the oscillations damp to a stable equilibrium?
* With a model we can better *understand the data*
* More important: we can understand the ecology dynamics of
predator-pray populations
% endif
!eblock
!split
===== The traditional (top-down) approach =====
!bblock
The classical way (in all books) is to present the Lotka-Volterra equations:
!bt
\begin{align*}
\frac{dH}{dt} &= H(a - b L)\\
\frac{dL}{dt} &= - L(d - c H)
\end{align*}
!et
Here,
* $H$ is the number of preys
* $L$ the number of predators
* $a$, $b$, $d$, $c$ are parameters
Most books quickly establish the model and then use considerable space on
discussing the qualitative properties of this *nonlinear system of
ODEs* (which cannot be solved)
!eblock
!split
===== The ``new'' discrete bottom-up approach =====
!bblock The bottom-up approach
!bpop
* Start with experimental data and discuss the methods which have been used to collect the data, the assumptions, the electronic devices, the aims etc. That is, expose the students to the theory and assumptions behind the data that have been collected and motivate for the scientific method.
* Where appropriate the students should do the experiment(s) needed to collect the data.
* The first programming tasks are to read and visualize the data to see if there are patterns or regularities. This strengthens a research-driven intuition.
* Now we want to increase the understanding through modeling.
* Most of the biology lies in the *derivation* of the model. We shall
focus on an intuitive discrete approach that leads to difference
equations that can be programmed *and solved* directly.
!epop
!eblock
!split
===== Basic (computer-friendly) mathematics notation =====
!bblock
* Time points: $t_0,t_1,\ldots,t_m$
* Uniform distribution of time points: $t_n=n\Delta t$
* $H^n$: population of hares at time $t_n$
* $L^n$: population of lynx at time $t_n$
* We want to model the changes in populations, $\Delta H=H^{n+1}-H^n$
and $\Delta L=L^{n+1}-L^n$ during a general time interval $[t_{n+1},t_n]$
of length $\Delta t=t_{n+1}-t_n$
!eblock
!split
===== Basic dynamics of the population of hares =====
!bblock
The population of hares evolves due to births and deaths exactly as a bacteria population:
!bt
\[
\Delta H = a \Delta t H^n
\]
!et
However, hares have an additional loss in the population because
they are eaten by lynx.
All the hares and lynx can form
$H\cdot L$ pairs in total. When such pairs meet during a time
interval $\Delta t$, there is some
small probablity that the lynx will eat the hare.
So in fraction $b\Delta t HL$, the lynx eat hares. This
loss of hares and must be accounted for:
subtracted in the equation for hares:
!bt
\[ \Delta H = a\Delta t H^n - b \Delta t H^nL^n\]
!et
!eblock
!split
===== Basic dynamics of the population of lynx =====
!bblock
We assume that the primary growth for the lynx population depends on sufficient food for raising lynx kittens, which implies an adequate source of nutrients from predation on hares. Thus, the growth of the lynx population does not only depend of how many lynx there are, but on how many hares they can eat.
In a time interval $\Delta t HL$ hares and lynx can meet, and in a
fraction $b\Delta t HL$ the lynx eats the hare. All of this does not
contribute to the growth of lynx, again just a fraction of
$b\Delta t HL$ that we write as
$d\Delta t HL$. In addition, lynx die just as in the population
dynamics with one isolated animal population, leading to a loss
$-c\Delta t L$.
!eblock
!bblock
The accounting of lynx then looks like
!bt
\[ \Delta L = d\Delta t H^nL^n - c\Delta t L^n\]
!et
!eblock
!split
===== Evolution equations =====
!bblock
By writing up the definition of $\Delta H$ and $\Delta L$, and putting
all assumed known terms $H^n$ and $L^n$ on the right-hand side, we have
!bt
\[ H^{n+1} = H^n + a\Delta t H^n - b\Delta t H^n L^n \]
!et
!bt
\[ L^{n+1} = L^n + d\Delta t H^nL^n - c\Delta t L^n \]
!et
Note:
* These equations are ready to be implemented!
* But to start, we need $H^0$ and $L^0$ <linebreak>
(which we can get from the data)
* We also need values for $a$, $b$, $d$, $c$
!eblock
!split
===== Adapt the model to the Hudson Bay case =====
!bblock
* As always, models tend to be general - as here, applicable
to ``all'' predator-pray systems
* The critical issue is whether the *interaction* between hares and lynx
is sufficiently well modeled by $\hbox{const}HL$
* The parameters $a$, $b$, $d$, and $c$ must be
estimated from data
* Measure time in years
* $t_0=1900$, $t_m=1920$
!eblock
!split
===== The program =====
!bblock
@@@CODE src/Hudson_Bay.py
!eblock
% if FORMAT != 'ipynb':
!split
===== The plot =====
FIGURE: [fig/Hudson_Bay_sim, width=700 frac=0.9]
% else:
If we perform a least-square fitting, we can find optimal values for the parameters $a$, $b$, $d$, $c$. The optimal parameters are $a=0.4807$, $b=0.02482$, $d=0.9272$ and $c=0.02756$. These parameters result in a slightly modified initial conditions, namely $H(0) = 34.91$ and $L(0)=3.857$. With these parameters we are now ready to solve the equations and plot these data together with the experimental values.
% endif
Binary file not shown.
Binary file not shown.

After

Width:  |  Height:  |  Size: 52 KiB

Binary file not shown.
Binary file not shown.

After

Width:  |  Height:  |  Size: 64 KiB

+22
View File
@@ -0,0 +1,22 @@
Year,Hares (x1000),Lynx (x1000)
1900,30.0,4.0
1901,47.2,6.1
1902,70.2,9.8
1903,77.4,35.2
1904,36.3,59.4
1905,20.6,41.7
1906,18.1,19.0
1907,21.4,13.0
1908,22.0,8.3
1909,25.4,9.1
1910,27.1,7.4
1911,40.3,8.0
1912,57,12.3
1913,76.6,19.5
1914,52.3,45.7
1915,19.5,51.1
1916,11.2,29.7
1917,7.6,15.8
1918,14.6,9.7
1919,16.2,10.1
1920,24.7,8.6
1 Year Hares (x1000) Lynx (x1000)
2 1900 30.0 4.0
3 1901 47.2 6.1
4 1902 70.2 9.8
5 1903 77.4 35.2
6 1904 36.3 59.4
7 1905 20.6 41.7
8 1906 18.1 19.0
9 1907 21.4 13.0
10 1908 22.0 8.3
11 1909 25.4 9.1
12 1910 27.1 7.4
13 1911 40.3 8.0
14 1912 57 12.3
15 1913 76.6 19.5
16 1914 52.3 45.7
17 1915 19.5 51.1
18 1916 11.2 29.7
19 1917 7.6 15.8
20 1918 14.6 9.7
21 1919 16.2 10.1
22 1920 24.7 8.6
+43
View File
@@ -0,0 +1,43 @@
import numpy as np
import matplotlib.pyplot as plt
def solver(m, H0, L0, dt, a, b, c, d, t0):
"""Solve the difference equations for H and L over m years
with time step dt (measured in years."""
num_intervals = int(m/float(dt))
t = np.linspace(t0, t0 + m, num_intervals+1)
H = np.zeros(t.size)
L = np.zeros(t.size)
print 'Init:', H0, L0, dt
H[0] = H0
L[0] = L0
for n in range(0, len(t)-1):
H[n+1] = H[n] + a*dt*H[n] - b*dt*H[n]*L[n]
L[n+1] = L[n] + d*dt*H[n]*L[n] - c*dt*L[n]
return H, L, t
# Load in data file
data = np.loadtxt('Hudson_Bay.csv', delimiter=',', skiprows=1)
# Make arrays containing x-axis and hares and lynx populations
t_e = data[:,0]
H_e = data[:,1]
L_e = data[:,2]
# Simulate using the model
H, L, t = solver(m=20, H0=34.91, L0=3.857, dt=0.1,
a=0.4807, b=0.02482, c=0.9272, d=0.02756,
t0=1900)
# Visualize simulations and data
plt.plot(t_e, H_e, 'b-+', t_e, L_e, 'r-o', t, H, 'm--', t, L, 'k--')
plt.xlabel('Year')
plt.ylabel('Numbers of hares and lynx')
plt.axis([1900, 1920, 0, 140])
plt.title(r'Population of hares and lynx 1900-1920 (x1000)')
plt.legend(('H_e', 'L_e', 'H', 'L'), loc='upper left')
plt.savefig('Hudson_Bay_sim.pdf')
plt.savefig('Hudson_Bay_sim.png')
plt.show()
Binary file not shown.
Binary file not shown.

After

Width:  |  Height:  |  Size: 66 KiB

+12
View File
@@ -0,0 +1,12 @@
import numpy as np
t = np.linspace(0, 10, 21) # 20 intervals in [0, 10]
dt = t[1] - t[0]
N = np.zeros(t.size)
N[0] = 1
r = 0.5
for n in range(0, N.size-1, 1):
N[n+1] = N[n] + r*dt*N[n]
print 'N[%d]=%.1f' % (n+1, N[n+1])
+11
View File
@@ -0,0 +1,11 @@
0,100
600,140
1200,250
1800,360
2400,480
3000,820
3600,1300
4200,1700
4800,2900
5400,3900
6000,7000
1 0 100
2 600 140
3 1200 250
4 1800 360
5 2400 480
6 3000 820
7 3600 1300
8 4200 1700
9 4800 2900
10 5400 3900
11 6000 7000
+27
View File
@@ -0,0 +1,27 @@
import numpy as np
# Estimate r
data = np.loadtxt('ecoli.csv', delimiter=',')
t_e = data[:,0]
N_e = data[:,1]
i = 2 # Data point (i,i+1) used to estimate r
r = (N_e[i+1] - N_e[i])/(N_e[i]*(t_e[i+1] - t_e[i]))
print 'Estimated r=%.5f' % r
# Can experiment with r values and see if the model can
# match the data better
T = 1200 # cell can divide after T sec
t_max = 5*T # 5 generations in experiment
t = np.linspace(0, t_max, 1000)
dt = t[1] - t[0]
N = np.zeros(t.size)
N[0] = 100
for n in range(0, len(t)-1, 1):
N[n+1] = N[n] + r*dt*N[n]
import matplotlib.pyplot as plt
plt.plot(t, N, 'r-', t_e, N_e, 'bo')
plt.xlabel('time [s]'); plt.ylabel('N')
plt.legend(['model', 'experiment'], loc='upper left')
plt.show()
+27
View File
@@ -0,0 +1,27 @@
import numpy as np
data = np.loadtxt('ecoli.csv', delimiter=',')
t_experiment = data[:,0]
N_experiment = data[:,1]
def error(p):
r = p[0]
T = 1200 # cell can divide after T sec
t_max = 5*T # 5 generations in experiment
t = np.linspace(0, t_max, len(t_experiment))
dt = (t[1] - t[0])
N = np.zeros(t.size)
N[0] = 100
for n in range(0, len(t)-1, 1):
N[n+1] = N[n] + r*dt*N[n]
e = np.sqrt(np.sum((N - N_experiment)**2))/N[0] # error measure
e = abs(N[-1] - N_experiment[-1])/N[0]
print 'r=', r, 'e=',e
return e
from scipy.optimize import minimize
p = minimize(error, [0.0006], tol=1E-5)
print p
+19
View File
@@ -0,0 +1,19 @@
import numpy as np
from matplotlib import pyplot as plt
# Load in data file
data = np.loadtxt('Hudson_Bay.dat', delimiter=',', skiprows=1)
# Make arrays containing x-axis and hares and lynx populations
year = data[:,0]
hares = data[:,1]
lynx = data[:,2]
plt.plot(year, hares ,'b-+', year, lynx, 'r-o')
plt.axis([1900,1920,0, 100.0])
plt.xlabel(r'Year')
plt.ylabel(r'Numbers of hares and lynx ')
plt.legend(('Hares','Lynx'), loc='upper right')
plt.title(r'Population of hares and lynx from 1900-1920 (x1000)}')
plt.savefig('Hudson_Bay_data.pdf')
plt.savefig('Hudson_Bay_data.png')
plt.show()