dynamic systems using r for systems understanding
play

Dynamic Systems Using R for Systems Understanding A Dynamic - PowerPoint PPT Presentation

Introduction Methods Lab model Ecosystem model Outlook Summary Dynamic Systems Using R for Systems Understanding A Dynamic Approach Evolution of systems in time (or / and space) Growth of organisms (and of my children), Thomas Petzoldt


  1. Introduction Methods Lab model Ecosystem model Outlook Summary Dynamic Systems Using R for Systems Understanding A Dynamic Approach Evolution of systems in time (or / and space) ◮ Growth of organisms (and of my children), Thomas Petzoldt & Karline Soetaert ◮ Economy, traffic, financial markets, Technische Universit¨ at Dresden ◮ Chemical reactions, spread of diseases, Institute of Hydrobiology Dresden, Germany ◮ Movement of planets, stars, the universe. thomas.petzoldt@tu-dresden.de Centre for Estuarine and Marine Ecology (CEME) Description Netherlands Institute of Ecology (NIOO-KNAW) Yerseke, The Netherlands ◮ Empirical with“pure statistics”(input-output, black box), k.soetaert@nioo.knaw.nl ◮ Mechanistic (what’s going on within the system): 18 th August 2011 ◮ Single objects (= agents, automata, individuals), ◮ Populations and pools ( − → differential equations). Introduction Methods Lab model Ecosystem model Outlook Summary Introduction Methods Lab model Ecosystem model Outlook Summary Differential equations in R: why and how Dynamic systems Why numerical solutions? ◮ difficult to forecast in brain − → weather, stock market ◮ Not all systems have an analytical solution, ◮ non-linearity, indirect effects, feedback loops, oscillations, ◮ Numerical solutions allow discrete forcings, events, ... ◮ dampening or autocatalytic amplification? ◮ If standard tool for statistics, why additional software for dynamic → stability, chaos, crash? − simulations? Modelling How in R? ◮ Systems understanding: most important processes, ◮ odesolve (Setzer, 2001): ◮ Simulate experiments before wasting time and money, → two ODE solvers (lsoda, rk4), − ◮ deSolve (Soetaert, Petzoldt, Setzer, 2009): ◮ Design experiments (and management) for best outcome, and improve statistical significance. → comprehensive set of solvers (ODE, DAE, PDE, DDE). − ◮ Note: odesolve is deprecated, use deSolve!

  2. Introduction Methods Lab model Ecosystem model Outlook Summary Introduction Methods Lab model Ecosystem model Outlook Summary Real systems need more than ODEs → additional features More additional features Example problem Type In R? algebraic constraints DAE (1) Plotting is made easy with high-level plotting functions (diff. algebraic eq.) ◮ plot -, image - and hist - methods (S3) time and space PDE (partial diff. eq.) (1,2,3) ◮ plotting multiple senarios simultaneously time delays DDE (delay diff. eq) (1) ◮ adding observed data time dependent external control forcing functions (1) ◮ “movie-like”output abrupt changes of states (externally triggered) events (1) Time-consuming models can be part R/part compiled code abrupt changes of states ◮ as fast as entire model in compiled code (depending on state of the system) roots + events (1) ◮ input - output handling as flexible as entire model in R identify parameters sensitivity, calibration (4) (1) deSolve – (2) rootSolve – (3) ReacTran – (4) FME Introduction Methods Lab model Ecosystem model Outlook Summary Introduction Methods Lab model Ecosystem model Outlook Summary Case studies Cultures and growth experiments ◮ physiological properties of organisms (e.g. growth rate), ◮ test of environmental factors (temperature, pH, salinity, toxicity), ◮ production of biomass, pharmaceuticals, beer, wine, whiskey . . . Experimentalists’ questions to the modeller ◮ Determine optimal conditions for getting: ◮ statistically significant effects in an experiment. ◮ maximum yield of a product with minimum costs. ◮ Determine physiological parameters after the experiment. Batch and chemostat cultures ... ◮ are very easy in R, ◮ but what with other reactors like“semi-batch” ?

  3. Introduction Methods Lab model Ecosystem model Outlook Summary Introduction Methods Lab model Ecosystem model Outlook Summary Substrate dependent growth in a batch Substrate limited growth model Equations R Code library(deSolve) r · S batch <- function(time, y, parms){ f ( S ) = ks + S with(as.list(c(y, parms)), { dS dt = − 1 f <- r * S / (ks + S) Y · f ( S ) · N dS <- - 1/Y * f * N dN dN <- f * N dt = f ( S ) · N return(list(c(dS, dN))) }) } ◮ initial values, parameters, y <- c(S = 10, N = 1e4) time steps, parms <- c(r=1, ks=5, Y=1e6, S0=10) ◮ numerical solution, times <- seq(0, 20, 0.1) ◮ visualization. out <- ode(y, times, batch, parms) plot(out) ◮ cells grow until substrate (e.g. phosphorus) is exhausted. Introduction Methods Lab model Ecosystem model Outlook Summary Semicontinuous culture (Semibatch II) Semicontinuous culture (Semibatch I) etime <- seq(5, 20, 5) # time points to triger events eventfun <- function(t, y, parms) { # event function Discontinuous operation not trivial for ODE solvers with(as.list(c(y, parms)), { ◮ Use very small time steps? → inefficient return(c(D * S0 + (1-D) * S, (1-D) * N)) # D = dilution rate }) ◮ Use loops to glue separate solutions together?? → programming } ◮ Good news: recent deSolve supports events! out <- ode(y, times, batch, parms, events = list(func = eventfun, time = etime))

  4. Introduction Methods Lab model Ecosystem model Outlook Summary Introduction Methods Lab model Ecosystem model Outlook Summary Semicontinuous culture III: Turbidostat mode Matter turnover and transport in a polluted river * * * * cells L-¹ Cell Number: N ◮ Dilute culture when cell number N exceeds critical number (Detected with photometric or turbidity measurement). ◮ Use root-finding properties of the deSolve solvers. crit <- 0.9e7 # critical cell number that triggers dilution event ◮ What are the main sources and effects of pollution? rootfun <- function (t, y, pars) return(crit - y[2]) ◮ What can be done to improve water quality? out <- ode(y, times, batch, parms, events = list(func = eventfun, root = TRUE), rootfun = rootfun) Introduction Methods Lab model Ecosystem model Outlook Summary Introduction Methods Lab model Ecosystem model Outlook Summary Matter turnover and transport in a polluted river Transport, Processes, Stoichiometry Y ( x , n ): State matrix T ( x , n ): Transport matrix P ( x , k ) = f ( Y , c ): Process matrix V ( k , n ): Stoichiometry matrix with: n : number of state variables (e.g. chemical species) k : number of processes x : space coordinate (here: river kilometers in 1D) ◮ Many processes in reality . . . c : constants (model parameters in nonlinear functions) ◮ . . . let’s look at two processes for demonstation basic principles: 1. oxygen consumtion by biological ammonia oxidation (nitrification) 2. oxygen exchange between atmosphere and water (re-aeration)

  5. Introduction Methods Lab model Ecosystem model Outlook Summary Core elements of the river model Transport, Processes, Stoichiometry Transport (package ReacTran) tran <- cbind( tran.1D(C = NH4, D = D, v = v, C.up = NH4up, C.down = NH4dwn, A = A, dx = Grid)$dC, tran.1D(C = NO3, D = D, v = v, C.up = NO3up, C.down = NO3dwn, A = A, dx = Grid)$dC, tran.1D(C = O2 , D = D, v = v, C.up = O2up, C.down = O2dwn, A = A, dx = Grid)$dC ) change = transport + processes · stoichiometry Stoichiometry matrix stoich <- matrix(c( # NH4 NO3 O2 0, 0, 1, # reaeration -1, +1, -4.57 # nitrification ), nrow = 2, byrow = TRUE) Y ′ = T + P · V Process equations proc <- cbind( k2 * (O2sat - O2), # re-aeration  y ′ y ′  rMax * O2/(O2 + kO2) * NH4 # nitrification t 1 , 1 t 1 , n p 1 , 1 p 1 , k v 1 , 1 v 1 , n       1 , 1 1 , n . . . . . . . . . . . . y ′ y ′ ) t 2 , 1 t 2 , n p 2 , 1 p 2 , k v 2 , 1 v 2 , n  2 , 1 2 , n  . . .  =  +  . . .   . . .   . . .     ·      . . . . . . . . . . . . . . . . . . . . . . . . . . . . y ′ y ′ t x , 1 t x , n p x , 1 p x , k v k , 1 v k , n State equation x , 1 x , n . . . . . . . . . . . . dY <- tran + proc %*% stoich Introduction Methods Lab model Ecosystem model Outlook Summary Full scale case studies Full scale case studies Outcome of the river model At TU Dresden (Germany), Anna-Maria Ertel At CEME (The Netherlands) , Roger Nzigou image(out1D) # + some tuning to produce figure below and Sabine Hacker use such models is using such a model to establish nutrient to analyse pollution turnover and bacteria budgets for the Girone Estuary transport in the Western Bug River (Ukraine) e p o r u E n i s Belarus r e e l l d Photo removed o m r e v R i Ukraine Poland Photo removed More about the Western Bug project, see: Ertel et al. (2011) Env Earth Sci DOI 10.1007/s12665-011-1289-0 See also: nitrification1D_ani.html

Recommend


More recommend