Pineda krch cmb2011-slides

295 views
237 views

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
295
On SlideShare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
4
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Pineda krch cmb2011-slides

  1. 1. Cycles in finite populations —A reproducible seminar in three acts Mario Pineda-Krch October 31, 2011 1
  2. 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 reproducibleresearch)Act 3: Cycles at the edge of existence(Emergence of quasi-cycles in strongly destabilized ecosystems) 2
  3. 3. Act 1: The ghost of Fermat 3
  4. 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
  5. 5. What really happened? Reproducible results = Reproducible research 5
  6. 6. Reproducible research: It’s not the destination. It’s thejourney. 6
  7. 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. 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. 9. Journal article Reader 6 Processed data Raw data Computer simulations Computer codeAuthor Algorithms ? 9
  10. 10. Literate programmingA 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
  11. 11. Literate programming according to Donald Knuth Prose Weave Tangle Documentation Program 11
  12. 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. 13. Literate programming according to RThe evolution of the literate programming paradigm Prose Sweave Stangle Documentation Code 13
  14. 14. What really happens Prose Sweave Stangle Sweave Documentation Code Execute Integrate Results 14
  15. 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. 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.
  17. 17. Act 2: A tale of two cycles 17
  18. 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
  19. 19. Elton (1924) British Journal of Experimental Biology 19
  20. 20. Kendall et al. (1998) Ecology Letters 20
  21. 21. Fluctuating populations Lynx 60000 20000 0 1750 1800 1850 1900 Otter Years 10000 14000 18000 Population size 6000 1850 1860 1870 1880 1890 1900 1910 Wolverine Years 2500 1500 500 0 1750 1800 1850 1900
  22. 22. Explaining complex population dynamics using simplemodels 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
  23. 23. Rosenzweig-MacArthur predator-prey model (RMPP) dN N = rN 1 − K − 1 +awN NP dt dP = c 1 +awN NP − gP dt 23
  24. 24. The deterministic RMPP in R > ode.rmpp <- function(parms = stop(Missing parms!), x0 = stop(Missing x0!), tmax = stop(Missing tmax)){ det.rmpp=function(t, y, parms){ N=y[1] ; P=y[2] with(as.list(parms),{ dN = (b-d)*N*(1-N/K)-a/(1+w*N)*N*P dP = c*a/(1+w*N)*N*P-g*P out=c(dN, dP) list(out) }) } require(odesolve) time <- seq(0, tmax, by=1) pop <- c(N=x0[[N]]*0.75, P=x0[[P]]*1.25) res = as.data.frame(lsoda(pop, time, det.rmpp, parms)) return(ode.res = res) }
  25. 25. The stochastic RMPP in R > ssa.rmpp <- function(parms = stop(Missing parms!), x0 = stop(Missing x0!), tmax = stop(Missing tmax)){ command <- paste(../src/ssa_rmpp , parms[[b]], parms[[d]], parms[[K]], parms[[a]], parms[[w]], parms[[c]], parms[[g]], x0[[N]], x0[[P]], tmax, >../results/out.txt) system(command) res <- as.data.frame(read.csv(../results/out.txt, skip=1, header=TRUE)) return(ssa.res = res) }
  26. 26. Structure of simulation model rmpp.R ode.rmpp.R ssa.rmpp.R ssa_rmpp.c 26
  27. 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. 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
  29. 29. Plot results > layout(matrix(c(1,2), ncol=2)) > ymax <- max(c(ode.res$N, ode.res$P, ssa.res$N, ssa.res$P)) > ymin <- min(c(ode.res$N, ode.res$P, ssa.res$N, ssa.res$P)) > plot(N~time, ode.res, type=l, lwd=3, col=rgb(0,1,0,.75), xlab="Time", ylab="Population size", xlim=c(0, 250), ylim=c(ymin, ymax), bty=n) > points(P~time, ode.res, type=l, lwd=3, col=rgb(1,0,0,.75)) > title(Deterministic) > plot(N~time, ssa.res, type=l, lwd=3, col=rgb(0,1,0,.75), xlab="Time", ylab="", xlim=c(0, 250), ylim=c(ymin, ymax), bty=n) > points(P~time, ssa.res, type=l, lwd=3, col=rgb(1,0,0,.75)) > title(Stochastic) Deterministic Stochastic 1400 1400 1200 1200 Population size 1000 1000 800 800 600 600 400 400 0 50 100 150 200 250 0 50 100 150 200 250 Time Time Figure: Time series for RMPP model in stable node region (α = 0.5, β = 1, γ = 1.2).
  30. 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. 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. 32. Detecting periodic fluctuations in simulated timeseries 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. 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
  34. 34. Power spectraDetecting periodic fluctuations Node Focus Limit cycle 8 8 8 q q q q q q q qq q qqq qq qq q q qq q qq q q 6 6 6 q qq q qq q qq q qq q qq q qq q qq qq qq qq qq qq qqq qqq qq q q qq q q q q qq q q q qq q q qq qqq q qq q q q qq q q q q q q qq q qqqqq q q qq q qq q q q q qq q qq qq q q q qq qq q q q q qq q qq q q qq q log10(Power) qq q q qq q q qq q q q q qq q q q qq q qqq q q q q q q qq qq qqqq q qqq q q q qq q q q q q q qqq qqqqq q q q q q q q q q q q qq q qq q qq q q q q qqq qqq qq qqq qqqqq q qq qqq q qq q q q q q qq qq qqq q q q q q q q q qqq q q q q q qq qq qq qq qq q qq qqq q q qq q q q q q q q qqqqqqqq qq q q q q q q q qq qqqq qqqq qqqq q qqq q q q qq qq q q qqq qq qqqq q qqqq q qqqq qq q q q qqqqqq q q qqqqqq q qqq qq q q q q q qqqqqqq qq q q q q qqqqqqqq q qq q q qq q q q q q qqqqqqqqqqqqqqqqqq q q q qqqqq qqqqqqqqqq q q q qq q q q q q qq q q qq qq q q q qq q qq qqq qqq q q q qqq qq qqqqqq qqqq q qq qq q q q q q q qqq qqqqqqqq q q q q qqqqqqqqqqqqqqq qq qqq q q qqqqqqqqqqqqqqqqqqq q qq q qqqqqqq qqqqqqqqqq qq qqqqqqq qq q q qq q q qq q qq qqq q qqqqqqq q q q qqqqq q q q qq q q q qqqqqqqq q qqqqqqqqqqqqqqqq q q q qqqq qqq qqqqqq q qq 4 4 4 q q qq q q qq q q q q qqqqqqq q qqqqq q q q qqqqqqqqq qqqqqqqqqqqqqqqq q qqq qqqqqqqqq q q q qqqqq qqqqqqqqqqq qqq qqqqqqqqqqqqqqqqqqq q qq qq qqqqqqqqqqqq qqqq qqqqqq q q q q qq q qq qq q qq qq q qqq qqqq q qq q q q qqq q qqqq qq q q qqqqqqqqqqqqqqqqqq q q q qqqqq q q q qq qq q q qq qqqqqqqqqqqqq qqq qqq qqqqqqqqqqqqqq qqq qqqqqqqqqqqq q qqqqqqqqqqqq q q q qqqqqqqqqqqqqqqq q q q q q qq q q q q q qqq qq qqqqq q qqqq qqqqqqq q qqqqq q qq q q q q q q qqq qq q qq qqqqq q qq q q q qqqq qqqqqqqqqqqqqqqqqqq qqqq q qqqqqqqqqqq qqqqqqqqqqqqqq q qq qqqqqqqqqqqqqq q qqqqqqqqqqqqqq q q q q q qqqqq qq q q qqqqq q q qqq q q q qq q qq qqqq q q qqqqqqqqqq qq qqqqq q qqqqqqq q q qqq qq qqqqqqqqqqqqqq q qqqqqqqqqq q q qqqqqqqqqqqqqq q q qqqq q q qq qqqqqq q qqqqqqq qq qq q qq qq q qq q qq qq qqqqq q q qqqqq q q q q qqqqqqq qq qqqqq q q qq qqqqqqqqqqq q q q qq qqqqqqqqqqqqqqq q qq qqqqqqqqqqq q qqqqqqq q qq q q qqq qqqqqqqqqqqqqq q qqqqqqqqqq q q qqqqqqqqqqqqqq qqqqqqq q q qq q q q qq q qqqqqqqqqqqqqq qqqq qqqqqqqq qq q qq qq qq q qq qqqq q q q qqq q qq qqq qq q q qq q qqqqqqqqqqqqqqqqqqqqqqqqqqq q qqqqqqqq qqqqq q qqqqqqqqqq qqqqqqqqq qqqq q qqqqqqq q qq qq q q qqqq q qqq q qq q qqq qqq q qqq q qqqq q q qqqqq qq qqqqqqqqqqqqqqq qq q qqqqqqqqqqq q q qqqqqqqqqq qq qq qqqqqqqqqqqqqqq qqqq qqqqqqqq qqqqqqqq q q q qq q qq q q q qqqqq qqqqqqqqqqq q q qqqqq q qqqqqqqqqqq q qq qqqqqq q qq q q qqqqq q q qqqq q qqqqqqqqqq q qqq qqqqqqqqq q q qqq q q q q q qq qq qq qq qq qq qq q qq qqqq q qq q qq qqq q qq qqqqqqqqqqqq q qqqqqqqqq q qq qqqq q qq q qqqqqqqqqqqqq q q q qq qqqqqqqqq qqq qqq q q q q q qq q qq q qq q q qq q qq q q q q q qqqqqqqqqqqqqq qqqqqq qqqqqq qqqqq qqqqqqq q qqqqqqqqqq qqqqqqqqq qqqqq q qqqqqqqqqq qqqqqq qq qqqqqqq q qq qqq qqq qq qq q q qqqq qqq q q q qqqqqqqqqq q q qq qqqqqq q q q qqqqq q qqqq qqqqqq qq qqqqq qq q q qqqqqqqq q q q q q qqqq qqq q qqqq qqqqqq qqqqqqqq q qqqqqqq q q qqqqqqq q q q qqqqqq qqq q q q qqq q qqq q q qqq qq qq qq qq q qq q qq q qq qqqqq q qqqqqq qqq q qqqq qq qqqq qq qqqqqq q q qq qq q q qq qq qqqq qq qq qqqqqqqq q q qq q qqq q qqqqq q qq q q qqqqqqq q qq qq qq q q q q q qqq q q q q qqqq q q qqqqqqq qqq q q qqq q q qqq q q q q qqqqqq q q qqqqqq qq q qq q 2 2 2 q qqqqq q q qqq qqqq q qqqqq qq qq q q q q q qq qqqq q qqq qq q q qq qq q qqq q q q qqq q q qqq q q q qqqq qq q qq qq q qq qq q qq q qq q qqq qqq qq q q q q q qq q qq q q q qq q q 0 0 0 q −4 −3 −2 −1 −3.0 −2.5 −2.0 −1.5 −1.0 −0.5 −3.0 −2.5 −2.0 −1.5 −1.0 −0.5 log10(Cycle frequency) Evidence of periodicity: presence of dominant frequency peak 34
  35. 35. Marginal distributionDistinguishing between quasi-cycles and noisy limit cycles Node Focus Limit cycle 150 3000 200 2500 150 100 2000 Frequency 1500 100 1000 50 50 500 0 0 0 600 800 1000 1200 600 1000 1400 1800 0 500 1500 2500 Prey population size Evidence of limit cycle: bimodal distribution 35

×