update on how to read data
This commit is contained in:
@@ -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">'Hudson_Bay.dat'</span>, delimiter<span style="color: #666666">=</span><span style="color: #BA2121">','</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">'b-+'</span>, year, lynx, <span style="color: #BA2121">'r-o'</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'Year'</span>)
|
||||
plt<span style="color: #666666">.</span>ylabel(<span style="color: #BA2121">r'Numbers of hares and lynx '</span>)
|
||||
plt<span style="color: #666666">.</span>legend((<span style="color: #BA2121">'Hares'</span>,<span style="color: #BA2121">'Lynx'</span>), loc<span style="color: #666666">=</span><span style="color: #BA2121">'upper right'</span>)
|
||||
plt<span style="color: #666666">.</span>title(<span style="color: #BA2121">r'Population of hares and lynx from 1900-1920 (x1000)}'</span>)
|
||||
plt<span style="color: #666666">.</span>savefig(<span style="color: #BA2121">'Hudson_Bay_data.pdf'</span>)
|
||||
plt<span style="color: #666666">.</span>savefig(<span style="color: #BA2121">'Hudson_Bay_data.png'</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 "new" 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 "all" 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">"""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."""</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">'Init:'</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">'Hudson_Bay.csv'</span>, delimiter<span style="color: #666666">=</span><span style="color: #BA2121">','</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">'b-+'</span>, t_e, L_e, <span style="color: #BA2121">'r-o'</span>, t, H, <span style="color: #BA2121">'m--'</span>, t, L, <span style="color: #BA2121">'k--'</span>)
|
||||
plt<span style="color: #666666">.</span>xlabel(<span style="color: #BA2121">'Year'</span>)
|
||||
plt<span style="color: #666666">.</span>ylabel(<span style="color: #BA2121">'Numbers of hares and lynx'</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'Population of hares and lynx 1900-1920 (x1000)'</span>)
|
||||
plt<span style="color: #666666">.</span>legend((<span style="color: #BA2121">'H_e'</span>, <span style="color: #BA2121">'L_e'</span>, <span style="color: #BA2121">'H'</span>, <span style="color: #BA2121">'L'</span>), loc<span style="color: #666666">=</span><span style="color: #BA2121">'upper left'</span>)
|
||||
plt<span style="color: #666666">.</span>savefig(<span style="color: #BA2121">'Hudson_Bay_sim.pdf'</span>)
|
||||
plt<span style="color: #666666">.</span>savefig(<span style="color: #BA2121">'Hudson_Bay_sim.png'</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 --------------- -->
|
||||
|
||||
Reference in New Issue
Block a user