The document summarizes a reproducible seminar on population cycles in finite populations presented in three acts. Act 1 introduces the concept of reproducible research and how it allows results to be independently verified. Act 2 demonstrates the existence of population cycles using a predator-prey model. Act 3 examines how cycles can emerge in destabilized ecosystems. The seminar is presented using literate programming techniques to integrate executable code, results, and documentation.
How to Troubleshoot Apps for the Modern Connected Worker
Pineda krch cmb2011-slides
1. Cycles in finite populations
—
A reproducible seminar in three acts
Mario Pineda-Krch
October 31, 2011
1
2. Act 1: The ghost of Fermat
(The what, why and how of reproducible research)
Act 2: A tale of two cycles
(Demonstrating the existence of quasi-cycles using reproducible
research)
Act 3: Cycles at the edge of existence
(Emergence of quasi-cycles in strongly destabilized ecosystems)
2
4. Irreproducible research
Randall J. LeVeque (2006)
“Scientific and mathematical journals are filled with pretty pictures
these days of computational experiments that the reader has no
hope of repeating. Even brilliant and well intentioned
computational scientists often do a poor job of presenting their
work in a reproducible manner. The methods are often very
vaguely defined, and even if they are carefully defined they would
normally have to be implemented from scratch by the reader in
order to test them. Most modern algorithms are so complicated
that there is little hope of doing this properly.”
Pierre de Fermat (1637)
“It is impossible to separate a cube into two cubes, or a fourth
power into two fourth powers, or in general, any power higher than
the second, into two like powers. I have discovered a truly
marvellous proof of this, which this margin is too narrow to
contain.”
4
7. Reproducible research: The What
LeVeque (2006):
“The idea of reproducible research in scientific computing is to
archive and make publicly available all of the codes used to create
the figures or tables in a paper in such a way that the reader can
download the codes and run them to reproduce the results.”
Wikipedia:
“Reproducibility is one of the main principles of the scientific
method, and refers to the ability of a test or experiment to be
accurately reproduced, or replicated, by someone else working
independently.”
8. Reproducible research: The Why
American Physical Society
“Science is the systematic enterprise of gathering knowledge about
the universe and organizing and condensing that knowledge into
testable laws and theories. The success and credibility of science
are anchored in the willingness of scientists to: Expose their ideas
and results to the independent testing and replication by others.
This requires the open exchange of data, procedure and materials.”
Reproducability = Transparency + Executability
8
9. Journal article
Reader
6
Processed data
Raw data
Computer simulations
Computer code
Author
Algorithms ?
9
10. Literate programming
A paradigm for reproducible research in computational sciences
“The idea is that you do not
document programs (after the
fact), but write documents
that contain the programs.”
— John Max Skaller
12. Literate programming systems
LP system Document formatting language Programming language Inventor(s) Year
WEB TEX Pascal Knuth 1992
CWEB TEX C/C++/Java Knuth & Levy 1993
FWEB L TEX
A C/C++/FORTRAN Krommes 1993
noweb TEX/L TEX/HTML/troff
A agnostic Ramsey 1999
Sweave L TEX
A R Leisch 2002
PyLit reStructuredText Python Milde 2005
Pweave L TEX/reST/Sphinx/Pandoc
A Python Pastell 2010
12
13. Literate programming according to R
The evolution of the literate programming paradigm
Prose
Sweave Stangle
Documentation Code
13
15. This research is reproducible!
These slides are prepared using Sweave.
These slides are executable (look for ).
The full project (source, code, results, etc.) will be available
at http://pineda-krch.com.
15
16. Implementing reproducible research
Attach code to publish results is good...,
executable manuscripts are better.
Adopt a habit of reproducibility, i.e. make it routine and
require it from others (students, postdocs, colleagues).
Keep reproducibility in computational research to the same
rigorous standard as reproducibility in mathematical proofs.
Demand reproducibility in your role as journal editor and
reviewer of manuscripts and grants applications.
18. Olaus Magnus (1555) Historia de Gentibus
First known depiction of of population cycles in Olaus Magnus’
Historia de Gentibus Septentrionalibus (History of the Northern
Peoples) (1555) shows lemmings falling from the sky with two
weasels with lemmings in their mouths.
18
22. Explaining complex population dynamics using simple
models
Classical Lotka-Volterra
Exponential growth in prey, linear (Type 1) functional response
in predator
Structurally unstable, mainly of historical interest
Lotka-Volterra
Logistic growth in prey, linear (Type 1) functional response in
predator
Does not cycle
Rosenzweig-MacArthur
Logistic growth in prey, non-linear (Type 2) functional
response in predator (i.e. satiation)
Cycles
27. Run a simulation in the stable node region
Set the parameters
> alpha <- 0.5
> beta <- 1
> gamma <- 1.2
> alpha; beta; gamma
[1] 0.5
[1] 1
[1] 1.2
Set equilibrium population size
> eq <- 1000
Set the length and the number of simulations
> tmax <- 10000
> n <- 1
27
28. Run a simulation in the stable node region
Run the simulation
> fn.node <- rmpp(alpha, beta, gamma, tmax, eq, n)
Data was saved in
> fn.node
[1] "../results/rmpp-alpha0.5-beta1-gamma1.2-eq1000-1.RData"
Loading the data
> load(fn.node)
Looking at the contents of the data file
> ls()
[1] "alpha" "beta" "d.lynx" "d.otter" "d.wolverin
[6] "eq" "fn" "fn.node" "gamma" "i"
[11] "n" "ode.res" "ode.rmpp" "parms" "rmpp"
[16] "ssa.res" "ssa.rmpp" "start.time" "tmax" "x0"
28
30. Run a simulation in the limit cycle region
Deterministic Stochastic
3000
3000
2000
2000
Population size
1000
1000
500
500
0
0
0 50 100 150 200 250 0 50 100 150 200 250
Time Time
Figure: Time series for RMPP model in limit cycle region (α = 0.5,
β = 1, γ = 3.5).
31. Run a simulation in the stable focus region
Deterministic Stochastic
1500
1500
Population size
1000
1000
500
500
0 50 100 150 200 250 0 50 100 150 200 250
Time Time
Figure: Time series for RMPP model in stable focus region α = 0.5,
β = 1, γ = 2.5).
32. Detecting periodic fluctuations in simulated time
series
Node
1200
1000
800
600
100 150 200 250 300 350
Focus
Years
1800
Population size
1400
1000
600
100 150 200 250 300 350
Limit cycle
Years
2500
1500
0 500
100 150 200 250 300 350
32
33. Autocorrelation Function (ACF)
Detecting periodic fluctuations
Node Focus Limit cycle
1.0
1.0
1.0
0.8
0.5
0.5
0.6
ACF
0.0
0.4
0.0
−0.5
0.2
−0.5
0.0
0 10 20 30 40 0 5 10 15 20 25 30 0 5 10 15 20 25 30
Lag
√
Evidence of periodicity if ACF(T) > 2/ tm where T is the lag of
the dominant frequency (first maximum), tm is the number of data
points in the time series.
33