This paper was converted on www.awesomepapers.org from LaTeX by an anonymous user.
Want to know more? Visit the Converter page.

Beyond the adiabatic limit in systems with fast environments:
a τ\tau-leaping algorithm

Ernesto Berríos-Caro ernesto.berrios@postgrad.manchester.ac.uk Theoretical Physics, Department of Physics and Astronomy, School of Natural Sciences, Faculty of Science and Engineering, The University of Manchester, Manchester M13 9PL, United Kingdom    Tobias Galla tobias.galla@ifisc.uib-csic.es Theoretical Physics, Department of Physics and Astronomy, School of Natural Sciences, Faculty of Science and Engineering, The University of Manchester, Manchester M13 9PL, United Kingdom Instituto de Física Interdisciplinar y Sistemas Complejos, IFISC (CSIC-UIB), Campus Universitat Illes Balears, E-07122 Palma de Mallorca, Spain
Abstract

We propose a τ\tau-leaping simulation algorithm for stochastic systems subject to fast environmental changes. Similar to conventional τ\tau-leaping the algorithm proceeds in discrete time steps, but as a principal addition it captures environmental noise beyond the adiabatic limit. The key idea is to treat the input rates for the τ\tau-leaping as (clipped) Gaussian random variables with first and second moments constructed from the environmental process. In this way, each step of the algorithm retains environmental stochasticity to sub-leading order in the time scale separation between system and environment. We test the algorithm on several toy examples with discrete and continuous environmental states, and find good performance in the regime of fast environmental dynamics. At the same time, the algorithm requires significantly less computing time than full simulations of the combined system and environment. In this context we also discuss several methods for the simulation of stochastic population dynamics in time-varying environments with continuous states.

I Introduction

The modelling of dynamical systems in biology and other disciplines necessarily requires simplifying assumptions and a level of coarse graining. If all processes we know about are included, then the model becomes so complicated that it cannot be simulated or analysed. Even if simulation or analysis is possible further study of such a model will rarely be enlightening. Excessive detail makes hard to identify the key mechanisms at work and to understand what model components are responsible for these mechanisms. At the same time, some element of realism must be maintained. The model must not be so stylised to miss the key ingredients and behaviour it is meant to capture. The principal challenge, therefore, is to find the right level of detail, given the intended purpose.

The choice between stochastic and deterministic modelling approaches is one aspect of this discussion. If more detailed stochastic models mark one end of the spectrum, then many traditional models in mathematical biology or chemistry sit at the opposite end. These models are often built on a small number of ordinary or partial differential equations (e.g. Murray (2002, 2003)). This deterministic approach is valid if one can assume that the same initial conditions will always lead to the same outcome. For many applications involving very large systems this is a perfectly sensible approach.

However, it is now also universally recognised that stochasticity in the time-evolution of many systems is key in shaping the outcome, see e.g. Goel and Richter-Dyn (2004); Ewens (2004); Traulsen and Hauert (2010). Consequently a number of analytical and computational methods has been developed for the study of stochastic systems. One focus is on systems with discrete interacting individuals. What these individuals represent depends on the context, they could be members of different species in population dynamics, individual animals or humans in models of an epidemic, or molecules in chemical reaction systems Goel and Richter-Dyn (2004); Castellano et al. (2009); Keeling and Rohani (2008); Kampen (2007).

One particular point of interest within this class of individual-based systems are models operating in a time-dependent environment. This environment is not part of the system proper, but its state has an effect on what happens in the system. In a model of a population of bacteria for example, the reproduction or death rates could depend on external conditions such as the availability of nutrients or the presence of toxins Acar et al. (2008); Patra and Klumpp (2015). In population dynamics, the carrying capacity could vary in time Wienand et al. (2017, 2018); Taitelbaum et al. (2020), and in epidemics the infection rate is subject to seasonal changes Black and McKane (2010). The focus of our paper is on such individual-based models in time-varying external environments.

Analytical approaches to stochastic systems with discrete individuals usually start from the chemical master equation. In limited cases direct solution is possible, for example using generating functions. However, this is the exception, and a number of approximation schemes have consequently been developed. These include Kramers–Moyal and system-size expansions, leading to Fokker–Planck equations and descriptions in terms of stochastic differential equations Kampen (2007); Gardiner (2004). These schemes sacrifice the granularity of a discrete-agent system, and instead describe the dynamics in terms of continuous densities. This approach can be successful in particular for large populations. Any particular event then only results in a small change in the composition of the population relative to its size. Individual-based approaches and descriptions based on deterministic differential equations been extended to models of population dynamics in switching environments, for a selection of work see Kussell and Leibler (2005); Kepler and Elston (2001); Thattai and Van Oudenaarden (2004); Swain et al. (2002); Assaf et al. (2013a); Duncan et al. (2015); Assaf et al. (2013b); Ashcroft et al. (2014); Wienand et al. (2017); West et al. (2018); Assaf et al. (2008); Hufton et al. (2019a).

There are however situations in which one would rather avoid giving up the discrete nature of the population. For example, granularity is crucial for extinction processes (the number of individuals of the species about to go extinct is small by definition). In other situations the population may not be large enough to warrant a description in terms of continuous densities. For example, copy numbers in genetic circuits can be of the order of tens to hundreds (see e.g. Eldar and Elowitz (2010)), and it is difficult to justify a continuum limit. It then becomes necessary to carry out numerical simulations of the discrete individual-based process. The method of choice is the Gillespie algorithm (Gillespie, 1976, 1977), generating a statistically accurate ensemble of sample paths of the continuous-time dynamics.

In most applications the rate of events scales with the size of the population so that each individual experiences an 𝒪(1){\cal O}(1) number of reactions per unit time. The Gillespie method then runs into difficulties when the population is large, and with it the number of reactions per unit time. The computational cost of generating sample paths to up the desirable end point can then become very high. Similarly, a time scale separation between the dynamics in the population and the environment may make simulations challenging. If the environment is very fast compared to the population, a significant number of environmental events needs to be executed between events in the population. This aggravates the above limitations for large populations, and simulations can become problematic even for intermediate population sizes. One possible approach to this consists of assuming that the environment is ‘infinitely’ fast compared to the population. This is known as quasi steady state approximation Bowen et al. (1963); Segel and Slemrod (1989), or the ‘adiabatic limit’ Lin and Buchler (2018a); Hufton et al. (2019a). For related work see also Newby and Bressloff (2010); Ashcroft et al. (2014); Bressloff (2016, 2017a, 2017b). If this limit is taken then the environmental dynamics can be ‘averaged out’, and effective reaction rates can be used for the population. While computationally convenient, this approach discards any stochasticity from the environmental process. This sets another limitation, in particular when it is not valid to assume that the environment is infinitely fast compared to the population.

The objective of this work is therefore to design and test an algorithm for systems with fast environmental dynamics, but which also captures some elements of the environmental noise. We call this discrete-time algorithm τ\tauFE – τ\tau-leaping for fast environments. It is built on the ideas of the conventional τ\tau-leaping algorithm (Gillespie, 2001), but with modifications such as to preserve elements of the stochasticity of the environmental process. To do this, we assume that the environment is fast compared to the population, but not infinitely fast. More precisely, in each step of the algorithm we take into account sub-leading contributions in the time-scale separation.

The key new element of our algorithm is how we deal with the environment. We do not take the adiabatic limit, instead we treat the reaction rates in the population as random variables during each step. The rates are drawn from a distribution at the beginning of each step, and then remain fixed during the time step. The distribution of rates can change from one step to the next, and is constructed to reflect statistical features of the original environmental dynamics.

Each step of the τ\tauFE algorithm consists of two parts: First a realisation of reaction rates is drawn from the appropriate distribution. Then a conventional τ\tau-leaping step is carried out with these rates. The core of our paper consists of the construction of the ‘appropriate distribution’ for the reaction rates. These ideas were introduced in a previous work Hufton et al. (2019b) for a simple case of a two-species birth-death process in an environment which can take two discrete states. In the present paper we develop this further. We develop and test a more general algorithm for environments with more than two discrete states. As we will show, the algorithm can also be extended to continuous environmental dynamics.

The remainder of the paper is organised as follows. In Sec. II we describe the general setup of the type of system we simulate. We also outline the general principles of the τ\tauFE algorithm. In Sec. III we then make the necessary preparations for the introduction of the algorithm. In particular, we compute the statistics of reaction rates which are fed into the conventional τ\tau-leaping step. We then describe the algorithm in detail. In Sec. IV, we test the τ\tauFE algorithm in different models with discrete environmental states. In Sec. V, we then describe how the τ\tauFE algorithm can be used when the environment takes continuous states. Specifically, we consider an Ornstein-Uhlenbeck process. In this context we also describe how known algorithms can be adapted to simulate continuous environments. Finally, we provide a discussion of our results and overall conclusions in Sec. VII.

II Model setup and general principles of the algorithm

II.1 Model definitions and notation

We look at systems composed of discrete individuals. We will refer to this synonymously as the ‘system proper’, or ‘the population’. Each of the individuals is of one of SS species (or types), labelled i=1,,Si=1,\dots,S. We write nin_{i} for the number of individuals of species ii in the population, and 𝐧=(n1,,nS)\mathbf{n}=(n_{1},\dots,n_{S}). The system evolves in an external environment, whose state we write as σ\sigma. These states are time dependent, and can either take discrete values or be continuous.

The dynamics in the population proceeds through reactions r=1,,Rr=1,\dots,R. Each of these reactions converts a number of individuals from one type into another. Time in the model is continuous, and we assume that the dynamics is Markovian. We then write Rr,σ(𝐧)R_{r,\sigma}(\mathbf{n}) for the rate of reaction rr if the environment is in state σ\sigma and the population in state 𝐧\mathbf{n}. The stoichiometric coefficient νr,i\nu_{r,i} indicates how the number of individuals of type ii changes when a reaction of type rr occurs. Each νr,i\nu_{r,i} is an integer, which can be negative, zero, or positive. We write 𝝂r=(νr,1,,νr,S){\mbox{\boldmath$\nu$}}_{r}=(\nu_{r,1},\dots,\nu_{r,S}). The rates Rr,σ(𝐧)R_{r,\sigma}(\mathbf{n}) and the stoichiometric coefficients fully specify the dynamics of the population when the environment is in state σ\sigma.

The state of the environment undergoes a Markovian stochastic process, governed by a master equation if states are discrete or by a stochastic differential equation in the case of continuous environmental states. These dynamics can depend on the state of the population 𝐧\mathbf{n}. If the environmental states are discrete we write qσσ(τ)q_{\sigma\to\sigma^{\prime}}(\tau) for the probability of finding the environment in state σ\sigma^{\prime} at a particular point in time, given that τ\tau units of time earlier it was in state σ\sigma. If the environment is continuos then qσσ(τ)q_{\sigma\to\sigma^{\prime}}(\tau) is a probability density for σ\sigma^{\prime} (at given σ\sigma). We call qσσ(τ)q_{\sigma\to\sigma^{\prime}}(\tau) the transition kernel of the environmental process. We write 𝝆{\mbox{\boldmath$\rho$}}^{*} for the stationary distribution of the environmental dynamics. For discrete environmental states the entries ρσ\rho^{*}_{\sigma} denote the probability of finding the system in state σ\sigma in the stationary state. For continuous environments ρσ\rho^{*}_{\sigma} is the stationary probability density for σ\sigma.

II.2 General principles of the τ\tau-leaping algorithm for systems in fast environments

A conventional reaction system (without external environment) is governed by a chemical master equation of the form

ddtP(𝐧,t)=\displaystyle\frac{\mathrm{d}}{\mathrm{d}t}P(\mathbf{n},t)=
r[Rr(𝐧𝝂r)P(𝐧𝝂r,t)Rr(𝐧)P(𝐧,t)].\displaystyle\sum_{r}\big{[}R_{r}(\mathbf{n}-{\mbox{\boldmath$\nu$}}_{r})P(\mathbf{n}-{\mbox{\boldmath$\nu$}}_{r},t)-R_{r}(\mathbf{n})P(\mathbf{n},t\big{)}]. (1)

The notation is as in Sec. II.1, the only difference is that there is no subscript σ\sigma, as there is no environment. Sample paths entail events (reactions) which can occur at any point in continuous time, separated by exponentially distributed random waiting times. In each such event the state of the system 𝐧\mathbf{n} changes, and accordingly the reaction rates Rr(𝐧)R_{r}(\mathbf{n}) can also change. Sample paths can be generated for example using the celebrated Gillespie algorithm (Gillespie, 1976, 1977).

The τ\tau-leaping algorithm for such conventional reaction systems is built around the idea of keeping reaction rates constant over finite time steps of length τ\tau Gillespie (2001). That is to say, if the state of the population is 𝐧\mathbf{n} at time tt, then the assumption is made that this state 𝐧\mathbf{n} and the rates Rr(𝐧)R_{r}(\mathbf{n}) do not change until the end of the time step. The algorithm does not account for potential changes of the rates as individual reactions occur, and instead directly ‘leaps’ to time t+τt+\tau. This is justified provided the so-called ‘leap condition’ is fulfilled Gillespie (2001): broadly speaking the time step τ\tau must be sufficiently small so that the state 𝐧\mathbf{n} in the continuous-time system does not change significantly in a time interval of length τ\tau.

Making the approximation of constant 𝐧\mathbf{n} in the time interval from tt to t+τt+\tau, the number of reactions of type rr that fire in this interval follows a Poissonian distribution with parameter τRr(𝐧)\tau R_{r}(\mathbf{n}). Accordingly, realisations of Poissonian random variables m1,,mRm_{1},\dots,m_{R} are drawn, and the corresponding numbers of each reactions are executed simultaneously. This generates a new state 𝐧\mathbf{n}^{\prime} at time t+τt+\tau, with entries ni=ni+r=1Rmrνi,rn_{i}^{\prime}=n_{i}+\sum_{r=1}^{R}m_{r}\nu_{i,r}. The process then repeats with updated rates Rr(𝐧)R_{r}(\mathbf{n}^{\prime}).

The idea of the τ\tau-leaping algorithm we introduce for systems in external environments is similar. As in the conventional algorithm we discretise time, and keep the composition of the population 𝐧\mathbf{n} fixed during each iteration. It is only updated at the end of each step. From now on we use Δt\Delta t for the duration of a step instead of τ\tau.

The difference to the conventional case is the external environment. If the environmental state space is discrete then switches of the environment can in principle be simulated in continuous time along with the other reactions (using Gillespie algorithm (Gillespie, 1976, 1977)). They can also be dealt with by means of the conventional τ\tau-leaping algorithm, again along with the other reactions. These are natural simulation approaches when the environment operates on a similar time scale as the reactions in the population. Not much can then be gained by distinguishing between environmental processes and the dynamics in the system proper.

If the environment is infinitely fast compared to the reactions in the population, then the environment reaches stationarity on very short time scales. One can average over environmental states, see for example Bowen et al. (1963); Segel and Slemrod (1989); Newby and Bressloff (2010); Bressloff and Newby (2014); Hufton et al. (2019b, a). If the environment is discrete, for example, we can use average rates

Rr(𝐧)σρσRr,σ(𝐧).R_{r}^{*}(\mathbf{n})\equiv\sum_{\sigma}\rho^{*}_{\sigma}R_{r,\sigma}(\mathbf{n}). (2)

In the case of continuous environments the sum is to be replaced with an integral. These rates are functions of 𝐧\mathbf{n} only, the environmental process has been averaged out. Noise from the environmental process plays no role in the dynamics if these average rates are used. This corresponds to making a quasi-stationary state approximation for the fast-moving environment Bowen et al. (1963); Segel and Slemrod (1989).

The aim of this paper is to go beyond this adiabatic limit, and to construct a τ\tau-leaping algorithm which captures some elements of extrinsic noise. We focus on the limit of a fast, but not infinitely fast environmental dynamics.

Broadly speaking the τ\tauFE algorithm is constructed around the idea of treating the reaction rates Rr(𝐧)R_{r}(\mathbf{n}) as stochastic variables in each discrete time step. These random variables represent the rates one obtains when averaging the environmental process over the time step Δt\Delta t. Assuming that the rate of change of the environment is finite these average rates will remain stochastic. In the limit of infinitely fast environments the deterministic limit in Eq. (2) is recovered, and there is no stochasticity from the environment.

To construct the random reaction rates for each step, we make an approximation: we use a Gaussian distribution for the rates, with means as in Eq. (2) and with variances and correlations derived from the original combined process of the population and environment. We describe this in detail in the next section.

III Construction of the τ\tauFE algorithm for systems with discrete environments

III.1 Preliminary analysis of the environmental process

Here we assume the environmental states are discrete, σ{1,,M}\sigma\in\{1,\dots,M\}. The dynamics of the environment is governed by the rates λAσσ(𝐧)\lambda A_{\sigma\to\sigma^{\prime}}(\mathbf{n}) for transitions from σ\sigma to σ\sigma^{\prime}. The factor λ\lambda is introduced to control the time-scale separation between reactions in the population and the switching of the environment. We use the notation 𝐀(𝐧)\mathbf{A}(\mathbf{n}) for the M×MM\times M matrix with elements Aσσ(𝐧)A_{\sigma\to\sigma^{\prime}}(\mathbf{n}). We also set Aσσ(𝐧)=σσAσσ(𝐧)A_{\sigma\to\sigma}(\mathbf{n})=-\sum_{\sigma^{\prime}\neq\sigma}A_{\sigma\to\sigma^{\prime}}(\mathbf{n}). The combined dynamics of population and environment are then described by the master equation

ddtP(𝐧,σ,t)=\displaystyle\frac{\mathrm{d}}{\mathrm{d}t}P(\mathbf{n},\sigma,t)=
r[Rr,σ(𝐧𝝂r)P(𝐧𝝂r,σ,t)Rr,σ(𝐧)P(𝐧,σ,t)]\displaystyle\sum_{r}\big{[}R_{r,\sigma}(\mathbf{n}-{\mbox{\boldmath$\nu$}}_{r})P(\mathbf{n}-{\mbox{\boldmath$\nu$}}_{r},\sigma,t)-R_{r,\sigma}(\mathbf{n})P(\mathbf{n},\sigma,t)\big{]}
+λσ[Aσσ(𝐧)P(𝐧,σ,t)Aσσ(𝐧)P(𝐧,σ,t)].\displaystyle+\lambda\sum_{\sigma^{\prime}}\big{[}A_{\sigma^{\prime}\to\sigma}(\mathbf{n})P(\mathbf{n},\sigma^{\prime},t)-A_{\sigma\to\sigma^{\prime}}(\mathbf{n})P(\mathbf{n},\sigma,t)\big{]}. (3)

The rates λAσσ(𝐧)\lambda A_{\sigma\to\sigma^{\prime}}(\mathbf{n}) can depend on the state of the population, 𝐧\mathbf{n}. This means that 𝐧\mathbf{n} and σ\sigma do not necessarily evolve in time independently. However, as mentioned above the state 𝐧\mathbf{n} of the system is kept constant during each τ\tau-leaping step. This in turn means that the transition rates for the environment also remain constant during each step.

We now focus on one such time step, starting at time tt and ending at t+Δtt+\Delta t. We assume that 𝐧\mathbf{n} remains constant during this time interval. For the remainder of Sec. III.1 we suppress the potential dependence of 𝐀\mathbf{A} on 𝐧\mathbf{n}, although it is always implied. We write ρσ(t)\rho_{\sigma}(t^{\prime}) for the probability that the environment is in state σ\sigma at time t[t,t+Δt]t\in[t,t+\Delta t]. We then have the master equation

d𝝆dt=λ𝐀𝝆\frac{\mathrm{d}{\mbox{\boldmath$\rho$}}}{\mathrm{d}t^{\prime}}=\lambda\mathbf{A}{\mbox{\boldmath$\rho$}} (4)

for the environmental dynamics. The stationary distribution 𝝆{\mbox{\boldmath$\rho$}}^{*} for the environment is the solution of 𝐀𝝆=0\mathbf{A}{\mbox{\boldmath$\rho$}}^{*}=0. If 𝐀\mathbf{A} depends on 𝐧\mathbf{n}, then ρ\rho^{*} will also be a function of 𝐧\mathbf{n}. Assuming that the environmental process is irreducible this stationary distribution is unique for any one 𝐧\mathbf{n}.

The stochastic matrix 𝐀\mathbf{A} has one zero eigenvalue, which we write as μ1=0\mu_{1}=0. The remaining eigenvalues are denoted by μ2,,μM\mu_{2},\dots,\mu_{M}. We then have μ2,,μM<0\mu_{2},\dots,\mu_{M}<0. The corresponding (right) eigenvalues are written as 𝐯1=𝝆\mathbf{v}_{1}={\mbox{\boldmath$\rho$}}^{*} (the eigenvector corresponding to eigenvalue 0), and 𝐯2,,𝐯M\mathbf{v}_{2},\dots,\mathbf{v}_{M} respectively for the remaining eigenvectors. These are all understood to be column vectors of length MM.

We note that the general solution of Eq. (4) can be written in the form

𝝆(t)=𝝆+=2Mceλμ(tt)𝐯,{\mbox{\boldmath$\rho$}}(t^{\prime})={\mbox{\boldmath$\rho$}}^{*}+\sum_{\ell=2}^{M}c_{\ell}e^{\lambda\mu_{\ell}(t^{\prime}-t)}\mathbf{v}_{\ell}, (5)

with coefficients cc_{\ell} determined by the initial condition at the beginning of the time step t=tt^{\prime}=t. More precisely these coefficients can be obtained from the linear system

=2Mc𝐯=𝝆(t)𝝆.\sum_{\ell=2}^{M}c_{\ell}\mathbf{v}_{\ell}={\mbox{\boldmath$\rho$}}(t)-{\mbox{\boldmath$\rho$}}^{*}. (6)

We remark that there are M1M-1 coefficients, cc_{\ell} (=2,,M\ell=2,\dots,M). The system in Eq. (6) technically consists of MM equations, but these are not independent due to normalisation of the probabilities on the right-hand side.

Calculating the probability qσσ(Δt)q_{\sigma\to\sigma^{\prime}}(\Delta t) to find the environment in state σ\sigma^{\prime} at the end of the time step if it was in σ\sigma at the beginning of the step is now mainly a matter of computing the coefficients cc_{\ell}. We write c,σc_{\ell,\sigma} for the value the coefficient cc_{\ell} takes when ρσ(t)=δσ,σ\rho_{\sigma^{\prime}}(t)=\delta_{\sigma^{\prime},\sigma} (i.e., when the system starts in state σ\sigma at the beginning of the step).

We then have

qσσ(Δt)=ρσ+=2Mc,σeλμΔtv,σ,q_{\sigma\to\sigma^{\prime}}(\Delta t)=\rho^{*}_{\sigma^{\prime}}+\sum_{\ell=2}^{M}c_{\ell,\sigma}e^{\lambda\mu_{\ell}\Delta t}v_{\ell,\sigma^{\prime}}, (7)

where v,σv_{\ell,\sigma^{\prime}} is the σ\sigma^{\prime}-entry of the eigenvector 𝐯\mathbf{v}_{\ell} of 𝐀\mathbf{A}.

If the matrix 𝐀\mathbf{A} depends on the population state 𝐧\mathbf{n}, the parameters μ,v,σ,\mu_{\ell},v_{\ell,\sigma^{\prime}}, and c,σc_{\ell,\sigma} can also depend on 𝐧\mathbf{n}. For simplicity of notation we have not included this potential dependence in the above equations.

III.2 Time-averaged reaction rates as random variables

The τ\tau-leaping algorithm proceeds in discrete time intervals of length Δt\Delta t. We continue to focus on one such interval [t,t+Δt][t,t+\Delta t]. The state of the population at the beginning of the step is 𝐧\mathbf{n} and we assume that this state does not change until the end of the interval. We do however take into account the fact that the state of environment σ\sigma can undergo changes in the interval from tt to t+Δtt+\Delta t. As a consequence, Rr,σ(𝐧)R_{r,\sigma}(\mathbf{n}) (at fixed 𝐧)\mathbf{n}) is also a function of time.

We then introduce the time-averaged quantities

Rr¯(𝐧)1Δttt+ΔtdtRr,σ(t)(𝐧),\overline{R_{r}}(\mathbf{n})\equiv\frac{1}{\Delta t}\int_{t}^{t+\Delta t}\mathrm{d}t~{}R_{r,\sigma(t)}(\mathbf{n}), (8)

noting that the time average is over the duration of the time step only as opposed to a long-term asymptotic time average. Given that the time step Δt\Delta t is finite (Δt<\Delta t<\infty) and assuming that the environment fluctuates with finite rates (λ<\lambda<\infty), the quantity Rr¯(𝐧)\overline{R_{r}}(\mathbf{n}) is a stochastic variable as it depends on the realisation of the environmental process. In one given time interval, the rates Rr¯(𝐧)\overline{R_{r}}(\mathbf{n}) for different rr will be correlated as they all derive from the same path of the environment. As we will show below, the fluctuations of the random variables Rr¯(𝐧)\overline{R_{r}}(\mathbf{n}) in any one time step are inversely proportional to λΔt\lambda\Delta t to leading order. In the limit λΔt\lambda\Delta t\to\infty the Rr¯(𝐧)\overline{R_{r}}(\mathbf{n}) become deterministic.

We assume that the distribution for σ\sigma at the beginning of the time step is the stationary distribution 𝝆{\mbox{\boldmath$\rho$}}^{*}. This is the case for example, if then environmental state is drawn from the stationary distribution at the beginning of the simulation. The distribution for σ(t)\sigma(t^{\prime}) is then also the stationary distribution at each time t[t,t+Δt]t^{\prime}\in[t,t+\Delta t]. Writing \left\langle{\dots}\right\rangle for the average over realisations of the environmental process, we then have

Rr¯(𝐧)=Rr(𝐧),\left\langle{\overline{R_{r}}(\mathbf{n})}\right\rangle=R_{r}^{*}(\mathbf{n}), (9)

with Rr(𝐧)R_{r}^{*}(\mathbf{n}) as in Eq. (2).

However, σ(t)\sigma(t^{\prime}) (t[t,t+Δt]t^{\prime}\in[t,t+\Delta t]) will generally be correlated with σ(t)\sigma(t). Neglecting these means to operate in the adiabatic limit. We would like to retain some of these correlations. In order to compute second moments R¯r(𝐧)R¯s(𝐧)\left\langle{\overline{R}_{r}(\mathbf{n})\overline{R}_{s}(\mathbf{n})}\right\rangle we first use Eq. (8). This leads to averages of the type Rr,σ(t1)(𝐧)Rs,σ(t2)(𝐧)\left\langle{R_{r,\sigma(t_{1})}(\mathbf{n})R_{s,\sigma(t_{2})}(\mathbf{n})}\right\rangle, where t1t_{1} and t2t_{2} are two times in the interval from tt to t+Δtt+\Delta t. The second moments can then be expressed in terms of qσσ()q_{\sigma\to\sigma^{\prime}}(\cdot) as follows

R¯r(𝐧)R¯s(𝐧)=\displaystyle\left\langle{\overline{R}_{r}(\mathbf{n})\overline{R}_{s}(\mathbf{n})}\right\rangle=
1Δt2σσtt+Δtdt1t1t1+Δtdt2{ρσqσσ(t2t1)\displaystyle\frac{1}{\Delta t^{2}}\sum_{\sigma\sigma^{\prime}}\int_{t}^{t+\Delta t}\mathrm{d}t_{1}\int_{t_{1}}^{t_{1}+\Delta t}\mathrm{d}t_{2}\Big{\{}\rho^{*}_{\sigma}q_{\sigma\to\sigma^{\prime}}(t_{2}-t_{1})
×[Rr,σ(𝐧)Rs,σ(𝐧)+Rr,σ(𝐧)Rs,σ(𝐧)]}.\displaystyle\quad\quad\times\big{[}R_{r,\sigma}(\mathbf{n})R_{s,\sigma^{\prime}}(\mathbf{n})+R_{r,\sigma^{\prime}}(\mathbf{n})R_{s,\sigma}(\mathbf{n})\big{]}\Big{\}}. (10)

Further details are given in Appendix A. Using Eq. (7) we find

R¯r(𝐧)R¯s(𝐧)Rr(𝐧)Rs(𝐧)=\displaystyle\left\langle{\overline{R}_{r}(\mathbf{n})\overline{R}_{s}(\mathbf{n})}\right\rangle-R_{r}^{*}(\mathbf{n})R_{s}^{*}(\mathbf{n})=
1Δt2σσ=2M{ρσc,σv,σ\displaystyle\frac{1}{\Delta t^{2}}\sum_{\sigma\sigma^{\prime}}\sum_{\ell=2}^{M}\bigg{\{}\rho^{*}_{\sigma}c_{\ell,\sigma}v_{\ell,\sigma^{\prime}}
×[Rr,σ(𝐧)Rs,σ(𝐧)+Rr,σ(𝐧)Rs,σ(𝐧)]\displaystyle\times\big{[}R_{r,\sigma}(\mathbf{n})R_{s,\sigma^{\prime}}(\mathbf{n})+R_{r,\sigma^{\prime}}(\mathbf{n})R_{s,\sigma}(\mathbf{n})\big{]}
×tt+Δtdt1t1t1+Δtdt2eλμ(t2t1)}.\displaystyle~{}~{}~{}~{}~{}~{}~{}~{}~{}~{}\times\int_{t}^{t+\Delta t}\mathrm{d}t_{1}\int_{t_{1}}^{t_{1}+\Delta t}\mathrm{d}t_{2}~{}e^{\lambda\mu_{\ell}(t_{2}-t_{1})}\bigg{\}}. (11)

For fixed {2,,M}\ell\in\{2,\dots,M\} the integral in the last expression evaluates to

tt+Δtdt1t1t1+Δtdt2eλμ(t2t1)=\displaystyle\int_{t}^{t+\Delta t}\mathrm{d}t_{1}\int_{t_{1}}^{t_{1}+\Delta t}\mathrm{d}t_{2}~{}e^{\lambda\mu_{\ell}(t_{2}-t_{1})}=
Δtλμ+1(λμ)2[eλμΔt1].\displaystyle-\dfrac{\Delta t}{\lambda\mu_{\ell}}+\frac{1}{(\lambda\mu_{\ell})^{2}}\left[e^{\lambda\mu_{\ell}\Delta t}-1\right]. (12)

For λΔt1\lambda\Delta t\gg 1 the first term dominates after inserting into Eq. (11), as also observed in Hufton et al. (2016). We are then left with

R¯r(𝐧)R¯s(𝐧)Rr(𝐧)Rs(𝐧)=\displaystyle\left\langle{\overline{R}_{r}(\mathbf{n})\overline{R}_{s}(\mathbf{n})}\right\rangle-R_{r}^{*}(\mathbf{n})R_{s}^{*}(\mathbf{n})=
1λΔtσσ=2M{1μRr,σ(𝐧)Rs,σ(𝐧)\displaystyle-\frac{1}{\lambda\Delta t}\sum_{\sigma\sigma^{\prime}}\sum_{\ell=2}^{M}\bigg{\{}\frac{1}{\mu_{\ell}}R_{r,\sigma}(\mathbf{n})R_{s,\sigma^{\prime}}(\mathbf{n})
×[ρσc,σv,σ+ρσc,σv,σ]}.\displaystyle~{}~{}~{}~{}\times\big{[}\rho^{*}_{\sigma}c_{\ell,\sigma}v_{\ell,\sigma^{\prime}}+\rho^{*}_{\sigma^{\prime}}c_{\ell,\sigma^{\prime}}v_{\ell,\sigma}\big{]}\bigg{\}}. (13)

The main challenge in implementing the τ\tauFE algorithm is then to find the average rates from Eq. (9) for all rr, and the second moments from Eq. (13) for any pair r,sr,s of reactions affected by the environment.

III.3 Description of the algorithm

Without loss of generality, we assume that only the rates for the reactions r=1,,Lr=1,\dots,L (LRL\leq R) depend on the environmental state σ\sigma.

The τ\tauFE algorithm with time step Δt\Delta t proceeds as follows:

  1. 1.

    Initiate the population in state 𝐧(0)\mathbf{n}(0). Set time to t=0t=0.

  2. 2.

    Compute Rr(𝐧)R^{*}_{r}(\mathbf{n}) for r=1,,Lr=1,\dots,L using Eq. (2), and the covariances Ξrs(𝐧)R¯r(𝐧)R¯s(𝐧)Rr(𝐧)Rs(𝐧)\Xi_{rs}(\mathbf{n})\equiv\left\langle{\overline{R}_{r}(\mathbf{n})\overline{R}_{s}(\mathbf{n})}\right\rangle-R_{r}^{*}(\mathbf{n})R_{s}^{*}(\mathbf{n}) using Eq. (13) for every pair r,s{1,,L}r,s\in\{1,\dots,L\}.

  3. 3.

    (i) First consider the reactions with rates dependent on the environment: Draw correlated Gaussian random numbers 1,,L\ell_{1},\dots,\ell_{L} such that r=Rr(𝐧)\left\langle{\ell_{r}}\right\rangle=R^{*}_{r}(\mathbf{n}), and rsrs=Ξrs(𝐧)\left\langle{\ell_{r}\ell_{s}}\right\rangle-\left\langle{\ell_{r}}\right\rangle\left\langle{\ell_{s}}\right\rangle=\Xi_{rs}(\mathbf{n}). If r<0\ell_{r}<0 for any r{1,,L}r\in\{1,\dots,L\} set r=0\ell_{r}=0.
     
    (ii) For the remaining reactions r{L+1,,R}r\in\{L+1,\dots,R\} set r=Rr(𝐧)\ell_{r}=R_{r}(\mathbf{n}). These are the reactions with rates independent of the environment.

  4. 5.

    Draw independent Poissonians random numbers mrm_{r}, r=1,,Rr=1,\dots,R, each with parameter rΔt\ell_{r}\Delta t.

  5. 6.

    Update the state of the population, 𝐧(t+Δt)=𝐧(t)+rmr𝝂r\mathbf{n}(t+\Delta t)=\mathbf{n}(t)+\sum_{r}m_{r}{\mbox{\boldmath$\nu$}}_{r}.

  6. 7.

    Increment time by Δt\Delta t and go to 2.

We note that the mean of the r\ell_{r} in step 3(i) is of order (λΔt)0(\lambda\Delta t)^{0}, and their variance of order (λΔt)1(\lambda\Delta t)^{-1}. Truncation of the r\ell_{r} will therefore only be required very rarely when λΔt1\lambda\Delta t\gg 1.

Evaluating the expressions in Eqs. (2) and (13) in step 2 requires eigenvalues μ\mu_{\ell} of the transition matrix 𝐀(𝐧)\mathbf{A}(\mathbf{n}) for the environment, the eigenvectors, 𝐯\mathbf{v}_{\ell} (including the stationary distribution 𝐯1=𝝆\mathbf{v}_{1}={\mbox{\boldmath$\rho$}}^{*}), and the coefficients c,σc_{\ell,\sigma} for all σ\sigma. If the environmental process is independent of the state of the population (the AσσA_{\sigma\to\sigma^{\prime}} are not functions of 𝐧\mathbf{n}), then these quantities do not depend on 𝐧\mathbf{n}, and only need to be calculated once at the beginning.

In Sec. IV we first test the τ\tauFE algorithm on different models with discrete environments. However that the algorithm can also be extended to the case of environmental dynamics with continuous states. This will be discussed in Sec. V.

IV Application of the τ\tauFE algorithm to models with discrete environmental states

We now consider three examples of systems with discrete environmental states.

The first example (Sec. IV.1) is a genetic circuit. The role of the environment is here played by a process of binding and unbinding to promoters of the genes described by the model. Gene regulatory systems can exhibit time scale separation as discussed for example in Gunawardena (2014); Buchler et al. (2003); Lin and Buchler (2018b). Mathematically the model describes a population with two types of individuals and an environment with two states (bound/unbound). The environmental dynamics depends on the state of the population.

The second example (Sec. IV.2) is a toy model with two species in the population and three environmental states. The environmental process in this example is independent of the state of the population.

Sec. IV.3 finally focuses on a bimodal genetic switch with two species in the population, and an environmental process with three states, and with rates which depend on the state of the population.

IV.1 Genetic circuit: two system-independent environments, two species

This system models the dynamics of two genes, which produce two different regulatory proteins: X (a transcription factor) and Y (an inhibitor that titrates XX into an inactive complex). Specifically, we use the activator-titration circuit described in Lin and Buchler (2018a). The reactions are as follows:

ΩβXX,ΩβY,σY,(σ=0,1)\displaystyle\emptyset\xrightarrow{\Omega\beta_{X}}X,\quad\emptyset\xrightarrow{\Omega\beta_{Y,\sigma}}Y,\quad(\sigma=0,1)
XδX,YδY,\displaystyle X\xrightarrow{\delta_{X}}\emptyset,\quad Y\xrightarrow{\delta_{Y}}\emptyset,
X+Yα/Ω,\displaystyle X+Y\xrightarrow{\alpha/\Omega}\emptyset,
E0λnXκY/ΩE1,and,E1λθYE0,\displaystyle E_{0}\xrightarrow{\lambda n_{X}\kappa_{Y}/\Omega}E_{1},\quad\text{and,}\quad E_{1}\xrightarrow{\lambda\theta_{Y}}E_{0}, (14)

where the EσE_{\sigma} denote states of the environment (σ=0,1)(\sigma=0,1). These two environmental states represent situations in which a transcription factor XX is bound to the promoter of gene YY (state E1E_{1}), or no transcription factor is bound (E0E_{0}), respectively. The first two reactions in Eq. (14) describe the production of the two proteins (XX and YY). The production rates are βX\beta_{X} and βY,σ\beta_{Y,\sigma}. The former is independent of the environmental state, the latter explicitly depends on σ\sigma (i.e., on the presence or absence of a bound transcription factor). The reactions in the second line of Eq. (14) describe degradation of XX and YY, and the reaction in the third line captures titration. The binding and unbinding processes of the transcription factor are described by the reactions in the last line. The parameter Ω\Omega in the reaction rates determines the typical number of particles in the system, for further details see Lin and Buchler (2018a). We write nXn_{X} for the number of XX-particles in the system, and similarly nYn_{Y} is the number of YY-particles. One finds nX,nY=𝒪(Ω)n_{X},n_{Y}={\cal O}(\Omega) in the stationary state.

Refer to caption
Figure 1: Simulation output for the model of the genetic-circuit in Eq. (14). Panel (a) shows a sample path obtained from Gillespie simulations of the full model. Panel (b) is a sample path from the τ\tauFE algorithm [λ=103\lambda=10^{3} in panels (a) and (b)]. Panels (c) and (d) show the stationary distributions of nX+nYn_{X}+n_{Y} and nXnYn_{X}-n_{Y}, respectively, for λ=103\lambda=10^{3}, while (e) and (f) are for λ=104\lambda=10^{4}. In each panel (c)–(f) we report the Jensen-Shannon divergence (JSD) between the distributions obtained using the two different simulation methods. Remaining parameters: Ω=103,βX=2,βY,0=0,βY,1=10,δX=δY=1,κY=1,θY=0.5,and α=10\Omega=10^{3},\beta_{X}=2,\beta_{Y,0}=0,\beta_{Y,1}=10,\delta_{X}=\delta_{Y}=1,\kappa_{Y}=1,\theta_{Y}=0.5,\text{and }\alpha=10. For the τ\tauFE we have used a time step Δt=0.1\Delta t=0.1.

Mathematically, the model consists of two species in the population (with numbers of particles nX,nYn_{X},n_{Y}), and two environmental states, σ=0,1\sigma=0,1. We therefore have S=2,M=2S=2,M=2. Eqs. (9) and (13) can be evaluated explicitly for this case, see also Hufton et al. (2019b). The only process affected by the state of the environment is the production of YY, with rate βY,σ\beta_{Y,\sigma}. This rate becomes a (clipped) Gaussian random variable in the τ\tauFE algorithm, with first moment

β¯Y=βY=θYβY,0+nXκYβY,1/ΩθY+nXκY/Ω,\left\langle{\overline{\beta}_{Y}}\right\rangle=\beta_{Y}^{*}=\dfrac{\theta_{Y}\beta_{Y,0}+n_{X}\kappa_{Y}\beta_{Y,1}/\Omega}{\theta_{Y}+n_{X}\kappa_{Y}/\Omega}, (15)

and with variance

σβYβY2\displaystyle\sigma_{\beta_{Y}\beta_{Y}}^{2} β¯Y2βY2\displaystyle\equiv\langle\bar{\beta}_{Y}^{2}\rangle-{\beta_{Y}^{*}}^{2}
=2nXκYθY/ΩλΔt(nXκY/Ω+θY)(βY,0βY,1)2.\displaystyle=\dfrac{2n_{X}\kappa_{Y}\theta_{Y}/\Omega}{\lambda\Delta t(n_{X}\kappa_{Y}/\Omega+\theta_{Y})}\left(\beta_{Y,0}-\beta_{Y,1}\right)^{2}. (16)

Further details of the derivation can be found in Appendix B.

Simulation results for this model are shown in Fig. 1. In panels (a) and (b) we illustrate typical sample paths obtained from Gillespie simulations of the full model (population and environment), and from the τ\tauFE algorithm, respectively. We also show the stationary distributions for the quantities nX+nYn_{X}+n_{Y} and nXnYn_{X}-n_{Y} as obtained from both simulation algorithms. The distributions in panels (c) and (d) are for λ=103\lambda=10^{3} (i.e., moderately fast environmental dynamics), there are then remaining discrepancies between the τ\tauFE algorithm and simulations of the full model. In panels (e) and (f) the time-scale separation is larger (λ=104\lambda=10^{4}). The agreement improves as indicated by the Jensen-Shannon divergence (JSD) Fuglede and Topsoe (2004); Lin (1991) given in the figure.

We note at this point that the average CPU time to run a sample path up to time t=103t=10^{3} with parameters as in Fig. 1 (e) and (f) is 2.942.94 seconds for the Gillespie algorithm, and 0.030.03 seconds for the τ\tauFE algorithm (with a time step Δt=0.1\Delta t=0.1). These average simulation times are obtained from ten runs. They indicate that the τ\tauFE algorithm can significantly increase efficiency while producing results of the quality shown in Fig. 1. We stress that our primary interest is the relative comparison of computing times, and not on absolute simulation times 111For completeness, we add that simulations were performed on a MacBook Pro (Mid 2014), with processor 2.6 GHz Dual-Core Inter Core i5, and memory 8 GB 1600 MHz DDR3..

IV.2 Birth-death process: three environments, two species

Next, we consider a two-species birth-death process subject to an external environment which can be in one of three different states. This is a toy model chosen for illustration and does not represent any specific natural system. However, it captures elements of models of population dynamics.

The species in the population are labeled AA and BB, and the environmental states σ=0,1,2\sigma=0,1,2. Particles of type AA are produced with rate Ωασ\Omega\alpha_{\sigma}, and particles of type BB with rate Ωβσ\Omega\beta_{\sigma}. The subscript σ\sigma indicates explicit dependence on the state of the environment. Particles are removed with constant per capita rates dAd_{A} and dBd_{B} respectively. The parameter Ω\Omega again sets the typical size of the population. We write nAn_{A} and nBn_{B} for the number of individuals of either species. The environmental states cycle stochastically through the sequence σ=0,1,2,0,\sigma=0,1,2,0,\dots, with rate constants λk1\lambda k_{1}, λk2\lambda k_{2} and λk0\lambda k_{0} for the three transitions. Mathematically, the reactions in this model are

ΩασA,ΩβσB,(σ=0,1,2)\displaystyle\emptyset\xrightarrow{\Omega\alpha_{\sigma}}A,\quad\emptyset\xrightarrow{\Omega\beta_{\sigma}}B,\quad(\sigma=0,1,2)
AdA,BdB,\displaystyle A\xrightarrow{d_{A}}\emptyset,\quad B\xrightarrow{d_{B}}\emptyset,
E0λk1E1,E1λk2E2,E2λk0E0,\displaystyle E_{0}\xrightarrow{\lambda k_{1}}E_{1},\quad E_{1}\xrightarrow{\lambda k_{2}}E_{2},\quad E_{2}\xrightarrow{\lambda k_{0}}E_{0}, (17)

where as before EσE_{\sigma} denotes the environment. The rates k0,k1,k_{0},k_{1}, and k2k_{2} are constant parameters, independent of the population state.

Details of the calculation of the average rates and their second moments can be found in Appendix C. The average production rates for the two types of particles are

α\displaystyle\alpha^{*} =\displaystyle= k0α0+k1α1+k2α2k0+k1+k2,\displaystyle\dfrac{k_{0}\alpha_{0}+k_{1}\alpha_{1}+k_{2}\alpha_{2}}{k_{0}+k_{1}+k_{2}},
β\displaystyle\beta^{*} =\displaystyle= k0β0+k1β1+k2β2k0+k1+k2,\displaystyle\dfrac{k_{0}\beta_{0}+k_{1}\beta_{1}+k_{2}\beta_{2}}{k_{0}+k_{1}+k_{2}}, (18)

while the covariance σαβ=σβαα¯β¯αβ\sigma_{\alpha\beta}=\sigma_{\beta\alpha}\equiv\langle\bar{\alpha}\bar{\beta}\rangle-\alpha^{*}\beta^{*} takes the form

σαβ\displaystyle\sigma_{\alpha\beta} =θ2λΔt{(α0α1)(β0β1)(3k02k0,1k0,2)\displaystyle=\dfrac{\theta^{2}}{\lambda\Delta t}\Big{\{}(\alpha_{0}-\alpha_{1})(\beta_{0}-\beta_{1})\left(3k_{0}^{2}-k_{0,1}k_{0,2}\right)
+(α1α2)(β1β2)(3k12k1,0k1,2)\displaystyle\quad+(\alpha_{1}-\alpha_{2})(\beta_{1}-\beta_{2})\left(3k_{1}^{2}-k_{1,0}k_{1,2}\right)
+(α0α2)(β0β2)(3k22k2,0k2,1)},\displaystyle\quad+(\alpha_{0}-\alpha_{2})(\beta_{0}-\beta_{2})\left(3k_{2}^{2}-k_{2,0}k_{2,1}\right)\Big{\}}, (19)

with

θ2k0k1k2(k0k1+k1k2+k2k0)3,\theta^{2}\equiv\dfrac{k_{0}k_{1}k_{2}}{(k_{0}k_{1}+k_{1}k_{2}+k_{2}k_{0})^{3}}, (20)

and kσ,σ=kσkσk_{\sigma,\sigma^{\prime}}=k_{\sigma}-k_{\sigma^{\prime}}, for σ,σ{0,1,2}\sigma,\sigma^{\prime}\in\{0,1,2\}. The variance σααα¯α¯(α)2\sigma_{\alpha\alpha}\equiv\langle\bar{\alpha}\bar{\alpha}\rangle-(\alpha^{*})^{2}, is obtained by replacing all instances of βσ\beta_{\sigma} on the right-hand side of Eq. (19) with ασ\alpha_{\sigma}. The analog σββ\sigma_{\beta\beta} is obtained similarly by replacing ασ\alpha_{\sigma} with βσ\beta_{\sigma}.

Refer to caption
Figure 2: Simulation output of the two-species birth-death process in an environment with three states [Eq. (17)]. Panels (a), (c), and (e) show the stationary distribution of nA+nBn_{A}+n_{B} obtained using the Gillespie algorithm for the full model, and the τ\tauFE algorithm. Data is shown for different values of λ\lambda. Panels (b), (d), and (f) show the stationary distribution of nAnBn_{A}-n_{B}. Parameters used: k0=k1=k2=1,Ω=20,dA=dB=0.1k_{0}=k_{1}=k_{2}=1,\Omega=20,d_{A}=d_{B}=0.1, α0=β0=β1=α2=0\alpha_{0}=\beta_{0}=\beta_{1}=\alpha_{2}=0, and α1=β2=1\alpha_{1}=\beta_{2}=1. In each panel (a)–(f) we report the Jensen-Shannon divergence (JSD) between the two distributions obtained from Gillespie simulations of the full model and from the τ\tauFE algorithm. Panels (g) and (h): Spectral densities SAA(ω)S_{AA}(\omega) and SAB(ω)S_{AB}(\omega) [Eq. (21)] obtained from simulations using the Gillespie algorithm (full line), the τ\tauFE algorithm (open circles), and from conventional τ\tau-leaping simulations of the model in the adiabatic limit (asterisks). Parameters in (g) and (h) are as in panels (e) and (f), i.e., λ=150\lambda=150. The time step for the τ\tauFE algorithm and for conventional τ\tau-leaping in the adiabatic limit is Δt=0.1\Delta t=0.1.

In Fig. 2 we report results from numerical simulations for this model, both from conventional Gillespie algorithm of the full systems of environment and population, and using the τ\tauFE algorithm. Panels (a)–(f) show the stationary distributions of nA+nBn_{A}+n_{B} and nAnBn_{A}-n_{B}. As seen from the data for example in panel (a) the τ\tauFE algorithm displays deviations from Gillespie simulations of the full model when the environmental process is not sufficiently fast. We quantify these deviations again through the Jensen–Shannon divergence between the two distributions. The deviations reduce as the time scale separation λ\lambda is increased, i.e., when the environmental process becomes faster relative to the dynamics within the population.

Refer to caption
Figure 3: Stationary distribution for the numbers of mRNA and protein molecules (nMn_{M} and nPn_{P}, respectively) in the model of a genetic switch [Eq. 17]. Data is shown for different values of λ\lambda and for simulations of the full model by means of the Gillespie algorithm, and the τ\tauFE algorithm. Parameters: N=2,Ω=50,b0=b1=1,b2=20,d=9.2,β=50,δ=1,k+=0.025,k=1N=2,\Omega=50,b_{0}=b_{1}=1,b_{2}=20,d=9.2,\beta=50,\delta=1,k_{+}=0.025,k_{-}=1. The stationary distribution is obtained from a long run up to time t=105t=10^{5}. For the τ\tauFE algorithm we use Δt=100/λ\Delta t=100/\lambda. For each of the three values of λ\lambda we report the Jensen-Shannon divergence (JSD) between the distributions obtained from the two simulation methods.

In order to examine if the τ\tauFE algorithm accurately reproduces dynamical features (i.e., properties of the system beyond the stationary distribution), we show spectral densities of the time series for nAn_{A} and nBn_{B} in Fig. 2(g) and (h). The spectral densities are defined as

SAA(ω)=|n^A(ω)|2,\displaystyle S_{AA}(\omega)=\langle|\hat{n}_{A}(\omega)|^{2}\rangle,
SAB(ω)=n^A(ω)n^B(ω),\displaystyle S_{AB}(\omega)=\langle\hat{n}_{A}^{\dagger}(\omega)\hat{n}_{B}(\omega)\rangle, (21)

where n^A(ω)\hat{n}_{A}(\omega) and n^B(ω)\hat{n}_{B}(\omega) are the Fourier transforms of nA(t)n_{A}(t) and nB(t)n_{B}(t), respectively. The dagger denotes complex conjugation. The data from the τ\tauFE algorithm (open symbols) in Fig. 2(g) and (h) compares well with spectra obtained from direct Gillespie simulations of the full model (solid lines). This shows the τ\tauFE method indeed captures the dynamics of nAn_{A} and nBn_{B}. We also provide a comparison against the spectral densities obtained from conventional τ\tau-leaping simulations in the adiabatic limit, i.e., simulations with constant rates α\alpha^{*} and β\beta^{*} for the production events [Eq. (18)]. These are shown as full markers in Fig. 2(g) and (h). One then finds more substantial systematic deviations. This is because environmental fluctuations are discarded in the adiabatic limit. The τ\tauFE algorithm on the other hand captures the stochasticity of the environment to sub-leading order in λ1\lambda^{-1} in each iteration step.

IV.3 Bimodal genetic switch: three system-state dependent environments, two species

We now consider a model studied in Lin et al. (2018); Hufton et al. (2019a), describing a single gene GG with a promoter site which can bind to a total of up to NN molecules of protein. The number of protein molecules bound, σ\sigma, plays the role of the environment in this setting. The rate for transitions from σ\sigma to σ+1\sigma+1 depends on the number of protein molecules. The reactions in this model can be summarised as follows,

Gσ+Pλkλk+/ΩGσ+1,\displaystyle G_{\sigma}+P\xrightleftharpoons[\lambda k_{-}]{\lambda k_{+}/\Omega}G_{\sigma+1}, forσ<N,\displaystyle\quad\text{for}\quad\sigma<N,
GσΩbσGσ+M,\displaystyle G_{\sigma}\xrightarrow{\Omega b_{\sigma}}G_{\sigma}+M,
M𝑑,M𝛽M+P,\displaystyle M\xrightarrow{d}\emptyset,\quad M\xrightarrow{\beta}M+P, P𝛿,\displaystyle\quad P\xrightarrow{\delta}\emptyset, (22)

where MM and PP refer to molecules of mRNA and protein, respectively. The production rate bσb_{\sigma} for mRNA depends on the number of protein molecules bound to the promoter. We refer to Lin et al. (2018); Hufton et al. (2019a) for further details. In the following we write nMn_{M} and nPn_{P} for the numbers of particles of either type. One interesting feature of this model is that the distribution of the protein and mRNA populations can become bimodal, as illustrated in Fig. 3. This leads to bistability, with trajectories transitioning between the two modes of the joint distribution of nPn_{P} and nMn_{M}. Hence, the model describes a genetic switch.

In this model only the production rate of mRNA molecules is affected by the state of the environment. The average mRNA-production rate is found as

b=k2b0+kk~+b1+k~+2b2k2+kk~++k~+2,b^{*}=\dfrac{k_{-}^{2}b_{0}+k_{-}\tilde{k}_{+}b_{1}+\tilde{k}_{+}^{2}b_{2}}{k_{-}^{2}+k_{-}\tilde{k}_{+}+\tilde{k}_{+}^{2}}, (23)

with k~+=k+nP/Ω\tilde{k}_{+}=k_{+}n_{P}/\Omega. The second moment of the production rate takes the form

σbb2\displaystyle\sigma_{bb}^{2} b¯2b2\displaystyle\equiv\langle\bar{b}^{2}\rangle-{b^{*}}^{2}
=θ2λΔt{(b0b1)2k(k2+k~+kk~+2)\displaystyle=\dfrac{\theta^{2}}{\lambda\Delta t}\Big{\{}(b_{0}-b_{1})^{2}k_{-}\left(k_{-}^{2}+\tilde{k}_{+}k_{-}-\tilde{k}_{+}^{2}\right)
+(b0b2)22kk~+(k+k~+)\displaystyle\quad+(b_{0}-b_{2})^{2}2k_{-}\tilde{k}_{+}\left(k_{-}+\tilde{k}_{+}\right)
+(b1b2)2k~+(k~+2+k~+kk2)},\displaystyle\quad+(b_{1}-b_{2})^{2}\tilde{k}_{+}\left(\tilde{k}_{+}^{2}+\tilde{k}_{+}k_{-}-k_{-}^{2}\right)\Big{\}}, (24)

with

θ2=2kk~+(k2+kk~++k~+2)3.\theta^{2}=\dfrac{2k_{-}\tilde{k}_{+}}{\left(k_{-}^{2}+k_{-}\tilde{k}_{+}+\tilde{k}_{+}^{2}\right)^{3}}. (25)

Details of the calculation leading to Eqs. (23) and (24) can be found in Appendix D.

Figure 3 shows the stationary joint distribution of the number of mRNA and protein molecules for different values of the time-scale separation parameter λ\lambda. The figure shows data from Gillespie simulations of the full model [panels (a)–(c)], and data from the τ\tauFE algorithm [panels (d)–(f)]. The τ\tauFE algorithm captures the distribution profile with two local maxima. For low values of λ\lambda (i.e., a relatively slow environmental process) the distribution obtained from τ\tauFE tends to be wider than those from the Gillespie algorithm. The agreement improves for faster environments, as indicated again by the Jensen–Shannon distances in Fig. 3.

Refer to caption
Figure 4: Sojourn times tt_{\ell} and tht_{\rm h} near the two modes of the bistable genetic switch (see also Fig. 3). Panels (a) and (b) show the distribution of the time spent in the vicinity of each mode (see text for details); data obtained from τ\tauFE algorithm is shown along with results from exact Gillespie simulations of the full model (λ=2000\lambda=2000). In each panel we report the Jensen–Shannon distance between the two distributions. Panels (c) and (d) show the mean sojourn times as a function of the time-scale parameter λ\lambda. The parameters are as in Fig. 3, the lower mode is (nM,nP)=(10,500)(n_{M},n_{P})=(10,500), and the upper mode (nM,nP)=(30,1800)(n_{M},n_{P})=(30,1800). For the τ\tauFE algorithm we use a time step of Δt=100/λ\Delta t=100/\lambda.

In Fig. 4, we show the distribution and means of the sojourn times tt_{\ell} and tht_{\rm h} near the lower and higher modes of the stationary distribution. More precisely this is the time between entering and leaving a designated region around each of the modes. The lower maximum of the stationary distribution is sharper than the upper maximum (Fig. 3). Accordingly, we have chosen a smaller region at the lower mode than at the upper mode. For the lower mode, we use the region 0nM200\leq n_{M}\leq 20, 0nP11000\leq n_{P}\leq 1100 which encloses the mode at (nM,nP)=(10,500)(n_{M},n_{P})=(10,500). For the higher mode we use the region 20nM8020\leq n_{M}\leq 80, 1100nP27001100\leq n_{P}\leq 2700 enclosing the mode at (nM,nP)=(30,1800)(n_{M},n_{P})=(30,1800).

The data shown in the figure is constructed from one long sample path (run until t=106t=10^{6}), recording the points in time at which the system enters or leaves either region. Gillespie simulations operate in continuous time and the τ\tauFE algorithm in discrete time. In order to remove any artefacts resulting from this difference, the same time resolution (0.050.05) is used in both algorithms for the measurement of arrival and departure times. Because the lower mode is sharper than the upper maximum and because the sizes of the two detection regions are different the sojourn time tt_{\ell} at the lower mode is found to be smaller than that at the higher mode, tht_{\rm h}.

The distributions of sojourn times in Figs. 4 (a) and (b) indicate that the τ\tauFE algorithm captures this dynamic quantity, provided the environmental process is sufficiently fast. This is confirmed in panels (c) and (d), where we show the mean sojourn times as a function of the relative speed λ\lambda of the environment compared to the population dynamics. As seen in both panels, the τ\tauFE algorithm generates accurate measurements of the mean sojourn times t\left\langle{t_{\ell}}\right\rangle and th\left\langle{t_{\rm h}}\right\rangle in the limit λ1\lambda\gg 1.

At the same time, stochastic effects due to the random environmental process are captured for large but finite λ\lambda. This can be seen in Fig. 4 (d): the mean sojourn time th\left\langle{t_{\rm h}}\right\rangle drops significantly as the environmental process becomes slower, and hence additional noise is injected into the population (there is no environmental noise in the adiabatic limit). While there are quantitative differences compared to exact simulations, the τ\tauFE algorithm captures this reduction of th\left\langle{t_{h}}\right\rangle. Panel (c) reveals that there are also limitations to the precision of the τ\tauFE algorithm. The mean sojourn time t\left\langle{t_{\ell}}\right\rangle near the lower mode is affected much less by a reduction of the time-scale separation parameter λ\lambda than the mean sojourn time at the upper mode. This indicates that the escape from this region is driven mostly by intrinsic noise rather than by environmental stochasticity. While the data from the two algorithms remains within approximately 10%10\% for sufficiently fast environmental dynamics (λ104\lambda\gtrsim 10^{4}) the τ\tauFE algorithm is unable to capture the small rise of t\left\langle{t_{\ell}}\right\rangle observed in Gillespie simulations for intermediate values of λ\lambda.

λ\lambda Gillespie τ\tauFE
1250 1.35 0.04
2500 1.89 0.08
5000 2.62 0.17
10000 4.30 0.31
20000 7.77 0.57
Table 1: Mean computation time (in seconds) required to simulate one sample path up to t=103t=10^{3} of the bimodal genetic-switch system defined in Eq. (22). Measurements are from ten independent sample runs, using Gillespie simulations of the full model, and the τ\tauFE algorithm respectively. Parameters are as in Fig. 3. For the τ\tauFE algorithm we set Δt=100/λ\Delta t=100/\lambda.

In Table 1 we compare the the computing time required for both the Gillespie algorithm and the τ\tauFE method for different values of λ\lambda. The data in the table is the CPU time required to generate one sample path up to time t=103t=10^{3}, averaged over ten runs. The model parameters are as in Figs. 3 and 4.

The full model comprises the reactions in the population and the environmental switching. The rates for the former reactions are independent of λ\lambda, the rates for the latter scale linearly in λ\lambda. Accordingly, one expects the computing time for Gillespie simulations of the full model to be linear in λ\lambda, with a non-zero intercept. The data in the table is consistent with this. We note that Gillespie algorithm does not require any time discretisation.

The running time for the τ\tauFE algorithm depends on the choice of the time step. The time step in turn affects the accuracy of the outcome. If Δt\Delta t is large, then τ\tauFE simulations are fast, but the approximation to the continuous-time full model becomes less good. On the other hand the time step must not be too small, as the construction of the algorithm requires sufficient averaging of the environmental process in each step [Eqs. (11)–(13)]. The time step for the τ\tauFE algorithm in Figs. 3 and 4, and in Table 1 is chosen inversely proportional to λ\lambda. This is to ensure that each time step captures a sufficient number of switches of the environmental state. Accordingly, we expect the computing time for the τ\tauFE algorithm to scale linearly in λ\lambda, with no intercept. Again, the running times we measured in our simulations are consistent with this expectation. Overall, Table  1 shows that the τ\tauFE algorithm is able to generate data of the accuracy as in Figs. 3 and 4 while reducing the computing effort approximately ten fold compared to full Gillespie simulations.

V Numerical simulation of continuous-environmental systems

V.1 Setup

We turn now to systems which are subject to an environment with continuous states. Specifically, we follow Assaf et al. (2013a) and assume that the environmental state σ\sigma follows an Ornstein–Uhlenbeck process (see also Roberts et al. (2015); Assaf et al. (2013b)),

dσdt=λ(mσ)+2λv2η(t),\frac{\mathrm{d}\sigma}{\mathrm{d}t}=\lambda(m-\sigma)+\sqrt{2\lambda v^{2}}\,\eta(t), (26)

where η(t)\eta(t) is Gaussian white noise of unit amplitude, in particular η(t)η(t)=δ(tt)\left\langle{\eta(t)\eta(t^{\prime})}\right\rangle=\delta(t-t^{\prime}). The parameter mm is the average value of σ\sigma in the long run, whilst vv controls the magnitude of noise. As before, the parameter λ>0\lambda>0 indicates how quickly the environment changes relative to the dynamics in the population; λ\lambda is the equivalent of 1/τc1/\tau_{c} in the notation of Assaf et al. (2013a).

The probability distribution of finding the environment in state σ\sigma at time tt, given that was in state σ\sigma^{\prime} at time tt^{\prime}, can be obtained from the Fokker–Planck equation for the Ornstein–Uhlenbeck process, and is given by (see e.g. Klebaner (2005); Risken (1996))

qσσ(tt)=12πv2(1e2λ(tt))\displaystyle q_{\sigma^{\prime}\to\sigma}(t-t^{\prime})=\sqrt{\dfrac{1}{2\pi v^{2}(1-e^{-2\lambda(t-t^{\prime})})}}
×exp[(σσeλ(tt)m(1eλ(tt)))22v2(1e2λ(tt))].\displaystyle\times\exp\left[-\frac{\left(\sigma-\sigma^{\prime}e^{-\lambda(t-t^{\prime})}-m\left(1-e^{-\lambda(t-t^{\prime})}\right)\right)^{2}}{2v^{2}\left(1-e^{-2\lambda(t-t^{\prime})}\right)}\right]. (27)

For tt\to\infty (and tt^{\prime} fixed) this quantity tends to the stationary distribution

ρσ=12πv2exp[(σm)22v2].\rho^{*}_{\sigma}=\sqrt{\dfrac{1}{2\pi v^{2}}}\exp\left[-\dfrac{\left(\sigma-m\right)^{2}}{2v^{2}}\right]. (28)

We note that it is not a requirement for the τ\tauFE algorithm that the environment follows an Ornstein–Uhlenbeck process. However, both functions qσσ(tt)q_{\sigma^{\prime}\to\sigma}(t-t^{\prime}) and ρσ\rho^{*}_{\sigma} are required, as discussed in more detail below.

We proceed to describe how the τ\tauFE algorithm can be implemented for models with continuous environments (Sec. V.2).

In the case of discrete environments, continuous-time sample paths of the full model can be generated using the conventional Gillespie algorithm. This is an exact procedure: the ensemble of these sample paths faithfully describes the statistics of the full model. In Sec. IV we have used this as a benchmark to test the τ\tauFE algorithm. We are not aware of any analogous exact simulation method for models of discrete populations in a stochastic environment with continuous states. In order to test the τ\tauFE algorithm we therefore compare outcomes against those from approximation methods to generate paths of the combined set of the population and the environment. Several such methods exist, we describe these in Sec. V.3. The tests of the τ\tauFE algorithm against the baseline of these methods are described in Sec. VI.

V.2 Implementation of the τ\tauFE algorithm for continuous environments

We proceed similar to discrete case in Sec. III, replacing the sums over σ\sigma in Eqs. (2) and (10) with integrals. We then have

Rr(𝐧)=dσρσRr,σ(𝐧),R_{r}^{*}(\mathbf{n})=\int_{-\infty}^{\infty}\mathrm{d}\sigma\rho^{*}_{\sigma}R_{r,\sigma}(\mathbf{n}), (29)

and the relation for the second moments turns into

R¯r(𝐧)R¯s(𝐧)=\displaystyle\left\langle{\overline{R}_{r}(\mathbf{n})\overline{R}_{s}(\mathbf{n})}\right\rangle=
1Δt2dσdσtt+Δtdt1t1t+Δtdt2\displaystyle\frac{1}{\Delta t^{2}}\int_{-\infty}^{\infty}\mathrm{d}\sigma\int_{-\infty}^{\infty}\mathrm{d}\sigma^{\prime}\int_{t}^{t+\Delta t}\mathrm{d}t_{1}\int_{t_{1}}^{t+\Delta t}\mathrm{d}t_{2}
×{ρσqσσ(t2t1)\displaystyle\times\Big{\{}\rho^{*}_{\sigma}q_{\sigma\to\sigma^{\prime}}(t_{2}-t_{1})
[Rr,σ(𝐧)Rs,σ(𝐧)+Rr,σ(𝐧)Rs,σ(𝐧)]}.\displaystyle\big{[}R_{r,\sigma}(\mathbf{n})R_{s,\sigma^{\prime}}(\mathbf{n})+R_{r,\sigma^{\prime}}(\mathbf{n})R_{s,\sigma}(\mathbf{n})\big{]}\Big{\}}. (30)

Depending on the form of the stationary distribution ρσ\rho^{*}_{\sigma}, the kernel qσσ(t2t1)q_{\sigma\to\sigma^{\prime}}(t_{2}-t_{1}) and the rates Rr,σ(𝐧)R_{r,\sigma}(\mathbf{n}) the integrals in Eqs. (29) and (30) can be carried out, and closed-form analytical expressions can be obtained. In Sec. VI we explore a number of different examples, further scenarios are also discussed Appendix F. Once the average rates and the second moments are calculated, the τ\tauFE algorithm is implemented as described in Sec. III.3.

V.3 Conventional simulation approaches for discrete populations in continuous environments

In this section we summarise ‘conventional’ approaches to simulating discrete Markovian systems subject to environmental dynamics with continuous states. By ‘conventional’ we mean methods which produce explicit (approximate) sample paths of the environmental process. This is in contrast to the τ\tauFE algorithm, which generates paths only of the system proper.

V.3.1 Gillespie algorithm with discretised environmental states (GADE)

This approach is based on a discretisation of the space of environmental states, time remains continuous. Once such a discretisation for the environmental states is carried out, the combined states of the population and environment are also discrete. Simulations can be carried out using the conventional Gillespie method. We will refer to this method as GADE (Gillespie approach with discretised environment).

The key step in this approach is to find an appropriate dynamics in the space of discretised environmental states. We describe this in the context of the Ornstein–Uhlenbeck process in Eq. (26). We discretise the environmental state into integer multiples of Δσ\Delta\sigma, i.e., the environment takes states ,2Δσ,Δσ,0,Δσ,2Δσ,\dots,-2\Delta\sigma,-\Delta\sigma,0,\Delta\sigma,2\Delta\sigma,\dots. Transitions from one state kΔσk\Delta\sigma can only occur to states (k±1)Δσ(k\pm 1)\Delta\sigma. The transition rates are constructed such that this discrete process recovers the continuous Ornstein–Uhlenbeck dynamics in the limit Δσ0\Delta\sigma\to 0. The details of the construction are described in Appendix E, we here only report the main outcome. Specifically, the rates to transition from state kΔσk\Delta\sigma to (k±1)Δσ(k\pm 1)\Delta\sigma can be chosen as

Tk±=λ2Δσ[±(mkΔσ)+2v2Δσ].T_{k}^{\pm}=\frac{\lambda}{2\Delta\sigma}\left[\pm(m-k\Delta\sigma)+\frac{2v^{2}}{\Delta\sigma}\right]. (31)

This process can then be simulated using the standard Gillespie algorithm, along with the events in the population. We note that the rates Tk±T_{k}^{\pm} need to be non-negative, i.e., we require |mkΔσ|<2v2/Δσ|m-k\Delta\sigma|<2v^{2}/\Delta\sigma, for all kk. In practice, this can be achieved by truncating the set of possible states kΔσk\Delta\sigma. More precisely, we disallow transitions out of the region {k:|mkΔσ|K}\{k:|m-k\Delta\sigma|\leq K\}, with a given cutoff KK. Provided that KK is sufficiently large truncations will only be required rarely. Once a cutoff KK is chosen we must require Δσ2v2/K\Delta\sigma\leq 2v^{2}/K to guarantee non-negativity of the Tk±T_{k}^{\pm}. The variance of the Ornstein–Uhlenbeck process for σ\sigma is given by v2v^{2} in the long run [Eq. (28)], so KvK\propto v is a sensible choice. This results in maximum value for Δσ\Delta\sigma which is also proportional to vv.

V.3.2 Discrete-time simulation with explicit environmental dynamics (DEED)

Approximate sample paths of the combined system of population and environment can also be generated in a discrete-time simulation. We refer to this as DEED (discrete-time simulation with explicit environmental dynamics). The time step Δt\Delta t needs to be sufficiently small to capture the details of the environmental process with characteristic time scale τc=λ1\tau_{c}=\lambda^{-1}. We therefore require Δtλ1\Delta t\lesssim\lambda^{-1}. One possible implementation is as follows:

  1. 1.

    Suppose we have arrived at time tt, and the state of the population is 𝐧(t)\mathbf{n}(t) and that of the environment σ(t)\sigma(t). Obtain σ(t+Δt)\sigma(t+\Delta t) from Eq. (26) using the Euler-Maruyama method Maruyama (1955).

  2. 2.

    Use σ(t)\sigma(t) and 𝐧(t)\mathbf{n}(t) to calculate the rates pr(t)=Δt×Rr,σ(t)[𝐧(t)]p_{r}(t)=\Delta t\times R_{r,\sigma(t)}[\mathbf{n}(t)] for r=1,,Rr=1,\dots,R.

  3. 3.

    Provided Δt\Delta t is small enough, the pr(t)p_{r}(t) are all less than one. To lowest order in Δt\Delta t they are the probabilities that a reaction of type rr occurs in the next Δt\Delta t. For each r=1,,Rr=1,\dots,R implement one reaction of this type with probability pr(t)p_{r}(t). With probability 1pr(t)1-p_{r}(t) no reaction of type rr occurs. Executing all reactions that fire, one obtains 𝐧(t+Δt)\mathbf{n}(t+\Delta t).

  4. 4.

    Increment time by Δt\Delta t, and go to step 1.

Step 3 disregards the possibility that a particular reaction fires multiple times during one time step. This is a valid approximation, provided that the pr(t)=Δt×Rr,σ(t)p_{r}(t)=\Delta t\times R_{r,\sigma(t)} are much smaller than one. As an alternative step 3 could be replaced by a conventional τ\tau-leaping step. The number of reactions of type rr that fire is then a Poissonian random variable with parameter pr(t)p_{r}(t).

V.3.3 Thinning algorithm by Lewis

A population subject to a dynamic external environment with continuous state space can also be simulated using the so-called thinning algorithm by Lewis Lewis and Shedler (1979). This algorithm generates a statistically faithful ensemble of sample paths for Markovian systems with discrete states and transition rates with explicit external time dependence.

In the context of our model the population is such a system. If the environmental dynamics is independent of the population then realisations σ(t)\sigma(t) for the environment can be generated in advance independently from the population. For instance, sample solutions of the Ornstein-Uhlenbeck process in Eq. (26) could be generated. Each such realisation σ(t)\sigma(t) then determines a realisation of time-dependent rates Rr(𝐧,t)Rr,σ(t)(𝐧)R_{r}(\mathbf{n},t)\equiv R_{r,\sigma(t)}(\mathbf{n}) for the population. The Lewis algorithm can then be used to produce sample paths for the population dynamics.

In practice, numerical approximation schemes are required to generate realisations for the environment. For example, Eq. (26) can be solved numerically using the Euler–Maruyama method, with time step Δt\Delta t. As discussed above this time step needs to be sufficiently small (Δtλ1\Delta t\lesssim\lambda^{-1}) to resolve the short-time features of the environmental process. The Lewis algorithm then uses this as an input and generates sample paths for the population in continuous time.

VI Application of the τ\tauFE to continuous-environmental models

In this section we test the τ\tauFE algorithm on a number of different examples of models with continuous environmental states. Simulation outcomes are compared against those from the algorithms described in Sec. V.3.

VI.1 Toy model: Population dynamics with production and removal rates proportional to σ2\sigma^{2}

Refer to caption
Figure 5: Simulation results for a production-removal process with rates b=βσ2b=\beta\sigma^{2} and d=δσ2d=\delta\sigma^{2} (Sec. VI.1), for the different algorithms described in Sec. V. Parameters used: β=1.1\beta=1.1 and δ=1.0\delta=1.0, m=1m=1, λ=103\lambda=10^{3}, and v2=5×104v^{2}=5\times 10^{-4}. Panel (a): mean value of the number of individuals as function of time, obtained from 10310^{3} runs. Panel (b): stationary distribution of the environmental state, ρσ\rho_{\sigma}^{*}, for the GADE method and the DEED approach (the τ\tauFE algorithm does not simulate the environment). The solid line in panel (b) is the analytical solution from Eq. (28). Panel (c): distribution of the number of particles nn in the population at time t=10t=10. Panel (d): spectral density [Eq. (21)] obtained from 10310^{3} runs. We use Δσ=103\Delta\sigma=10^{-3} for the GADE simulations, and Δt=1/(100λ)=105\Delta t=1/(100\lambda)=10^{-5} for DEED. For the τ\tauFE algorithm, we set Δt=10/λ=102\Delta t=10/\lambda=10^{-2}.

We first consider a production-removal process for a single species. The environmental state σ(t)\sigma(t) follows the Ornstein–Uhlenbeck process in Eq. (26). The corresponding transition kernel qσσ(τ)q_{\sigma\to\sigma^{\prime}}(\tau) is given in Eq. (27), and the stationary distribution ρσ\rho_{\sigma}^{*} in Eq. (28). The production rate in the population is assumed to be Rb,σ=βσ2R_{b,\sigma}=\beta\sigma^{2}, and the removal rate Rd,σ=δσ2R_{d,\sigma}=\delta\sigma^{2}. These are not chosen with any particular natural system in mind, instead this example serves as an illustration (see also Appendix F for similar calculations for two related examples).

From (29) we obtain

Rb\displaystyle R_{b}^{*} =\displaystyle= β(m2+v2),\displaystyle\beta(m^{2}+v^{2}),
Rd\displaystyle R_{d}^{*} =\displaystyle= δ(m2+v2).\displaystyle\delta(m^{2}+v^{2}). (32)

The second moments of the rates R¯b(n)\overline{R}_{b}(n) and R¯d(n)\overline{R}_{d}(n) can be calculated from Eq. (30). We find

R¯b(n)R¯d(n)Rb(n)Rd(n)=\displaystyle\left\langle{\overline{R}_{b}(n)\overline{R}_{d}(n)}\right\rangle-R_{b}^{*}(n)R_{d}^{*}(n)=
βδv2e2λΔtλ2Δt2[8m2eλΔt+\displaystyle\frac{\beta\delta v^{2}e^{-2\lambda\Delta t}}{\lambda^{2}\Delta t^{2}}\Big{[}8m^{2}e^{\lambda\Delta t}+
e2λΔt(8m2(λΔt1)+v2(2λΔt1))+v2].\displaystyle e^{2\lambda\Delta t}\left(8m^{2}(\lambda\Delta t-1)+v^{2}(2\lambda\Delta t-1)\right)+v^{2}\Big{]}. (33)

for the covariance. The expressions for the variances are similar, with suitable replacements βδβ2\beta\delta\to\beta^{2} and βδδ2\beta\delta\to\delta^{2} in the prefactor in Eq. (33). This covariance matrix and the means in Eq. (32) are then used in the τ\tauFE algorithm.

λ1\lambda^{-1} GADE DEED τ\tauFE
1×1021\times 10^{-2} 28.47 3.84 0.79 ×102\times 10^{-2}
5×1035\times 10^{-3} 53.20 7.88 0.16 ×101\times 10^{-1}
1×1031\times 10^{-3} 288.30 40.91 0.08
5×1045\times 10^{-4} 576.69 82.78 0.15
1×1041\times 10^{-4} 3022.47 397.63 0.79
Table 2: Mean computing time (in seconds) required for one simulation run of the model described in Sec. VI.1 until t=103t=10^{3}. Data is from ten independent runs, parameters are as in Figure 5, i.e., β=1.1,δ=1.0,m=1,\beta=1.1,\delta=1.0,m=1, and v2=5×104v^{2}=5\times 10^{-4}. For GADE we set Δσ=103\Delta\sigma=10^{-3}; for the DEED approach we set λΔt=1/100\lambda\Delta t=1/100; for the τ\tauFE algorithm we set λΔt=10\lambda\Delta t=10.

Figure 5 shows simulation results from the τ\tauFE algorithm, as well as from the GADE and DEED schemes (Secs. V.3.1 and V.3.2 respectively). Panel (a) shows that all simulation methods result in linear growth (parameters are such that β>δ\beta>\delta, i.e., the growth rate is always larger than the death rate). Panel (b) confirms that GADE and DEED both generate the correct statistics for the stationary distribution of the environmental process [the solid line is the Gaussian distribution in Eq. (28)]. In panel (c) we focus on a fixed time t=10t=10, and show that all three simulation methods results in very similar distributions for the number of individuals in the population nn at that time. Panel (d) finally shows a dynamic quantity, the Fourier spectrum S(ω)S(\omega) of the time series n(t)n(t), or equivalently the Fourier transform of the correlation function of nn. Again, all three simulation methods produce very similar results.

In Table 2 we compare the average computing time required by the different algorithms to generate a trajectory up to time t=103t=10^{3}. We show data for varying values of the typical time scale λ1\lambda^{-1} of the environmental process. GADE does not require any discretisation of time. For the DEED approach we use Δt=1/(100λ)\Delta t=1/(100\lambda). For the τ\tauFE method we choose Δt=10/λ\Delta t=10/\lambda. This is in-line with the requirements Δtλ1\Delta t\lesssim\lambda^{-1} for DEED, and Δtλ1\Delta t\gtrsim\lambda^{-1} for τ\tauFE. The choice of time steps will be discussed in further detail below.

The data in the table indicates that the simulation time scales approximately linearly with λ\lambda for all three algorithms tested, provided λ\lambda is sufficiently large. This is to be expected: The rates for the environmental events in the GADE simulations (Sec. V.3.1) scale as λ\lambda, and therefore dominate the events in the population for λ1\lambda\gg 1. Each typical Gillespie step then advances time by an amount proportional to λ1\lambda^{-1}, and 𝒪(λ){\cal O}(\lambda) such steps are required to reach the designated end time. A similar argument applies to the DEED algorithm (Sec. V.3.2) and for the τ\tauFE algorithm: For both of these we use time steps Δtλ1\Delta t\propto\lambda^{-1}, so again the number of iteration steps required scales as λ\lambda.

The key message from Table 2 is that, for the choice of time steps made in the table, the computing time required by the τ\tauFE algorithm is substantially lower than that for the other two simulation methods. Given the linear dependence on λ\lambda, this increase in efficiency can be extrapolated to environments operating on time scales faster than the smallest time scale shown in the table (i.e., to the range λ>104\lambda>10^{4}). We note that, due to the smaller time step, DEED produces a finer resolution of sample paths in time than τ\tauFE. When we make our comparison we have average macroscopic quantities in mind (such as those in Fig. 5), and not necessarily the generation of individual paths with the highest possible resolution in time.

We now briefly discuss the choice of time steps for the τ\tauFE method and for DEED. In principle, we could have increased or decreased the step for either method. This would then reduce or increase the computing time required to reach the designated end point. It might also affect the accuracy of the outcome. Our choice of Δt=10/λ\Delta t=10/\lambda for τ\tauFE is motivated by the good agreement with GADE in Fig. 5, noting that GADE does not require any discretisation of time. Similarly, for the example discussed below in Sec. VI.2 good agreement with analytical predictions is found for this choice, see the regime of small λ1\lambda^{-1} in Fig. 6. Our conclusion is therefore that the τ\tauFE algorithm is able to produce results of the accuracy as in Fig. 5 with computing times as reported in Table 2.

The DEED algorithm requires Δtλ1\Delta t\lesssim\lambda^{-1} to be able to resolve the environmental dynamics. Our choice Δt=1/(100λ)\Delta t=1/(100\lambda) in Table 2 is well below this requirement, and the algorithm can in principle be speed up by choosing a larger time step. If we were to exhaust the limit and used Δt=λ1\Delta t=\lambda^{-1} for DEED then this would reduce the computing time by about a factor of one hundred in Table 2. For for λ1=103\lambda^{-1}=10^{-3} this would mean a reduction from approximately 4040 seconds to 0.40.4 seconds per sample path. Using this larger time step also results in noticeable deviations in measurements of the quantities in Fig. 5 from continuous-time GADE simulations. But even if we accept this and use the hundred fold larger time step for DEED the τ\tauFE algorithm would remain approximately five times faster, requiring 0.080.08 seconds per sample path at λ1=103\lambda^{-1}=10^{-3}, see Table 2.

We have also conducted tests with Lewis’ thinning algorithm. To do this we have first generated sample paths of the Ornstein–Uhlenbeck process for the environment [Eq. (26)] using an Euler–Maruyama scheme. This is then fed into the Lewis’ algorithm for systems with time dependent rates. Given that the typical time scale of the environment is λ1\lambda^{-1}, the largest sensible time step for the Euler–Maruyama scheme is Δt=λ1\Delta t=\lambda^{-1}, similar to DEED. This choice minimises the computing time for the Lewis’ approach. We therefore use this time step to compare the efficiency of the Lewis’ approach with that of τ\tauFE. We find that the thinning algorithm is considerably slower than the τ\tauFE approach. For λ1=103\lambda^{-1}=10^{-3}, for example, we obtain a simulation time of approximately 1313 seconds per run up to t=103t=10^{3} compared to 0.080.08 seconds for τ\tauFE (see Table 2).

VI.2 Genetic switch with Hill-like regulatory function

As a final example we consider a model of protein production subject to a continuous environment discussed in Assaf et al. (2013a). The model entails positive feedback, in that the presence of protein has the potential to increase production of protein. There is one single species in the model (protein), we write the number of protein molecules as nn. We also define x=n/Ωx=n/\Omega, where Ω\Omega is again a model parameter setting the typical size of the system. The production rate of protein is given by

f(x,σ)=α0+(1α0+σ)Θ(xx0),f(x,\sigma)=\alpha_{0}+(1-\alpha_{0}+\sigma)\Theta(x-x_{0}), (34)

where 0<α0<10<\alpha_{0}<1 and x0>0x_{0}>0 are constants, and where Θ(x)\Theta(x) is the Heaviside function. Protein molecules also decay with unit rate. In the absence of environmental influence (σ0\sigma\equiv 0), the production rate is thus unity when x>x0x>x_{0}, and α0<1\alpha_{0}<1 when x<x0x<x_{0}. For σ0\sigma\equiv 0 the mean re-scaled number of protein follows the rate equation

x¯˙=f(x¯)x¯,\dot{\bar{x}}=f(\bar{x})-\bar{x}, (35)

where time is measured in units of generations. We choose α0<x0<1\alpha_{0}<x_{0}<1. Eq. (35) has three fixed points x1<x2<x3x_{1}^{*}<x_{2}^{*}<x_{3}^{*}, where x1=α0x_{1}^{*}=\alpha_{0} and x3=1x_{3}^{*}=1 are attractors, and x2=x0x_{2}^{*}=x_{0} is a repeller. Similar to Assaf et al. (2013a), we refer to x1x_{1}^{*} and x3x_{3}^{*} as the ‘low’ and ‘high’ states, respectively.

The environmental process σ(t)\sigma(t) modulates the production rate when x>x0x>x_{0}. As in Assaf et al. (2013a) we asssume that σ\sigma follows an Ornstein-Uhlenbeck process of the form given in Eq. (26). The noisy system has the potential to switch between the ‘high’ and ‘low’ states. To test the performance of the τ\tauFE algorithm, we focus on the mean switching time (MST) to transit from the high state to the low state. This time is studied and calculated in Assaf et al. (2013a), we denote it by τhighlow\left\langle{\tau_{\text{high}\rightarrow\text{low}}}\right\rangle. In simulations we start the system in the high state, and measure the first time the system reaches the low state.

Only the production of protein is affected by the state σ\sigma of the environment, we write Rprod,σ(𝐧)=f(x,σ)R_{{\rm prod},\sigma}(\mathbf{n})=f(x,\sigma), with ff as in Eq. (34). Inserting this in Eqs. (29) and (30), and after straightforward calculations, we obtain

Rprod(n)=α0+(1α0)Θ(n/Ωx0),R_{\rm prod}^{*}(n)=\alpha_{0}+(1-\alpha_{0})\Theta(n/\Omega-x_{0}), (36)

and the second moment

(R¯prod(n))2[Rprod(n)]2=\displaystyle\left\langle{(\overline{R}_{\rm prod}(n))^{2}}\right\rangle-[R_{\rm prod}^{*}(n)]^{2}=
2v2λ2Δt2[λΔt+(eλΔt1)]Θ(n/Ωx0).\displaystyle\dfrac{2v^{2}}{\lambda^{2}\Delta t^{2}}\left[\lambda\Delta t+(e^{-\lambda\Delta t}-1)\right]\Theta(n/\Omega-x_{0}). (37)
Refer to caption
Figure 6: Mean switching time (MST) from the high to the low state in the model described in Sec. VI.2. For the τ\tauFE algorithm we used Δt=10/λ\Delta t=10/\lambda, for GADE Δσ=0.01\Delta\sigma=0.01, and for DEED Δt=104\Delta t=10^{-4}. Theory curves are from Eqs. (8) and (10) in Assaf et al. (2013a). Model parameters are as in the top right panel of Fig. 2 in Assaf et al. (2013a) (Ω=5000,v=0.1,α0=0.01,x0=0.93\Omega=5000,v=0.1,\alpha_{0}=0.01,x_{0}=0.93).

In Fig. 6 we show the MST measured in simulations using the different approaches described in in Sec. V. Assaf et al. Assaf et al. (2013a) report non-monotonous behaviour of the MST as a function of τc=λ1\tau_{c}=\lambda^{-1}. As seen in Fig. 6 the τ\tauFE algorithm reproduces this behaviour. For fast environmental dynamics (low λ1\lambda^{-1}) the MST obtained from the τ\tauFE algorithm is in good agreement with measurements obtained from the other simulation methods, and with the analytical approximations from Assaf et al. (2013a). The agreement extends over several decades of values of τc=λ1\tau_{c}=\lambda^{-1}.

At the same time we observe that the τ\tauFE algorithm requires significantly less computing time than the GADE or DEED approaches. For λ1=101\lambda^{-1}=10^{-1} for example, we measured an average computing time of 2×1032\times 10^{-3} seconds to generate one run of the system up to time 10310^{3} with the τ\tauFE algorithm (Δt=10/λ\Delta t=10/\lambda). GADE required 0.6740.674 seconds, and DEED 4.24.2 seconds (for a time step Δt=104\Delta t=10^{-4}).

We note that we have implemented DEED as described in Sec. V.3.2. In particular at most one reaction of each type can fire in each time step (step 3 of the algorithm). This requires a sufficiently small time step Δt\Delta t to ensure pr(t)<1p_{r}(t)<1 for all rr. This is achieved by our choice Δt=104\Delta t=10^{-4}. Alternatively step 3 of the DEED algorithm could be replaced by a (conventional) τ\tau-leaping step. Larger choices of the time step Δt\Delta t are then possible, up to the limit of Δtλ1\Delta t\approx\lambda^{-1} to ensure that the environmental dynamics are captured appropriately. Focusing on λ1=101\lambda^{-1}=10^{-1} we expect that increasing the time step by a factor of a thousand (from 10410^{-4} to 10110^{-1}) would reduce the simulation time by at most a factor of a thousand for a τ\tau-leaping version of DEED. This would result in a computing time of approximately 4×1034\times 10^{-3} for one simulation run up to t=103t=10^{3} instead of the 4.24.2 seconds reported for DEED in the previous paragraph. This is comparable with the CPU time required by the τ\tauFE algorithm (2×1032\times 10^{-3} seconds), but would resolve environmental fluctuations with lower accuracy. For example one observes systematic deviations for the stationary distribution of the environment in Fig. 5(b).

VII Discussion and conclusions

In summary, we have presented τ\tauFE, a variant of the τ\tau-leaping stochastic simulation algorithm for systems subject to fast environmental dynamics. Just like conventional τ\tau-leaping the algorithm operates in discrete time. The rates of the reactions in the system proper are treated as constant during each time step, and the numbers of different reactions firing in one step have Poissonian statistics.

The key difference compared to conventional τ\tau-leaping is the external environment. In the full continuous-time model reaction rates which depend on the environmental state fluctuate in time even when the state of the population does not change. An adiabatic approximation would consist of assuming an infinitely fast environment and of replacing the reaction rates by their means with respect to the stationary distribution of the environmental process. This is justified if the relaxation time scale of the environmental process is infinitely shorter than the time step of the simulation.

The τ\tauFE algorithm goes beyond this approximation, and is based on time averages of reaction rates over the finite time step. For finite speeds of the environment these average rates are random variables. If the environmental dynamics is fast we can make a Gaussian approximation. The rates feeding into the τ\tau-leaping step are clipped Gaussian random numbers designed to retain the first and second moments of the actual environmental dynamics. It is important to note that this not the same as drawing an environmental state σ\sigma from the stationary distribution ρσ\rho^{*}_{\sigma}, and then using the rates Rr,σ(𝐧)R_{r,\sigma}(\mathbf{n}) for the next τ\tau-leaping step. Instead, the covariance matrix of the rates R¯r(𝐧)\overline{R}_{r}(\mathbf{n}) in Eq. (8) is calculated as described in Eqs. (10) for discrete environments, and in Eq. (30) for continuous environmental states.

The choice of time step for the τ\tauFE algorithm requires careful consideration. On the one hand the time step must be long enough to justify the averaging procedure over the environmental dynamics and the Gaussian assumption for the reaction rates in the τ\tau-leaping step. Broadly speaking λΔt\lambda\Delta t must be sufficiently large (λΔt1\lambda\Delta t\gg 1). At the same time the so-called leap condition for the τ\tau-leaping part of the algorithm must be fulfilled (Gillespie, 2001). This means that the state of the system must not change significantly in each iteration step, as a constant state 𝐧\mathbf{n} of the population is an assumption made in setting up the τ\tau-leaping. Mathematically, this means that the change of the number of particles in the system in a time step must be much smaller than the typical number of particles in the system. Assuming that the stoichiometric coefficients do not scale with the system size Ω\Omega this means that Δt×Rr,σ(𝐧)\Delta t\times R_{r,\sigma}(\mathbf{n}) must be much smaller than Ω\Omega. Noting that Rr,σ(𝐧)R_{r,\sigma}(\mathbf{n}) is of order Ω\Omega in many applications we thus require that Δt\Delta t is much smaller than one. For λ1\lambda\gg 1 and Δt\Delta t proportional to λ1\lambda^{-1} this condition is often relatively easy to meet in practice.

We have tested the τ\tauFE algorithm on a number of systems with discrete and continuous environments. This includes examples of systems which can be addressed analytically and models motivated by applications in biology. Our tests focus on stationary distributions, but also dynamic features such as Fourier spectra of fluctuations or first-passage time distributions. In all cases we have tested the τ\tauFE method produces good agreement with results from conventional simulation methods in the regime of fast environmental dynamics. This is the regime for which τ\tauFE is designed. Naturally, quantitative deviations are found when the time scales of the environmental dynamics and system proper are insufficiently separated.

We stress that τ\tauFE goes beyond simulations in the adiabatic limit, and is able to capture the dependence of macroscopic observables on the time scale separation, provided this dependence is sufficiently strong [see e.g. Figs. 4(d) and 6)]. At the same time our analysis also reveals limitations of the algorithm. If the dependence of observables on the time scale separation is weak such as in Fig. 4(c), then τ\tauFE may not be able to fully resolve these dependencies. When the environment is fast the quantitative agreement with simulations of the full system is however still within approximately 10%10\% in the example in Fig. 4(c).

The computing time required for the τ\tauFE algorithm to generate sample paths up to a designated end time is proportional to the inverse time step. The time step on the other hand is typically a multiple of the characteristic time scale λ1\lambda^{-1} of the environmental dynamics. This means that the computational effort scales approximately linearly in the time scale separation λ\lambda. In all cases we have tested we found that τ\tauFE is considerably more efficient for the measurement of macroscopic quantities than alternative simulation algorithms.

In summary, we think the τ\tauFE algorithm has passed the initial selection of tests presented in this paper. It provides an promising approach to probing the regime of fast environmental dynamics, and captures effects induced by extrinsic noise beyond the adiabatic limit. The algorithm is particularly valuable for systems in which the regime of intermediate time scale separation can be accessed with conventional simulation methods. The accuracy of the τ\tauFE algorithm can then be assessed in this regime (an example can be found in Fig. 6). If the comparison is favourable, then it is justified to use τ\tauFE in the regime of increasing time scale separation.

Acknowledgements

We would like to thank Yen Ting Lin (Los Alamos) for useful discussions and feedback on earlier versions of the manuscript. EBC acknowledges a President’s Doctoral Scholarship (The University of Manchester). TG acknowledges funding from the Spanish Ministry of Science, Innovation and Universities, the Agency AEI and FEDER (EU) under the grant PACSS (RTI2018-093732-B-C22), and the Maria de Maeztu program for Units of Excellence in R&D (MDM-2017-0711).

References

  • Murray (2002) J. D. Murray, Mathematical Biology I. An Introduction, 3rd ed., Interdisciplinary Applied Mathematics, Vol. 17 (Springer, New York, 2002).
  • Murray (2003) J. D. Murray, Mathematical Biology II: Spatial Models and Biomedical Applications, Interdisciplinary Applied Mathematics, Vol. 18 (Springer New York, 2003).
  • Goel and Richter-Dyn (2004) N. S. Goel and N. Richter-Dyn, Stochastic Models in Biology (The Blackburn Press, 2004).
  • Ewens (2004) W. Ewens, Mathematical Population Genetics 1 (Springer-Verlag, New York, 2004).
  • Traulsen and Hauert (2010) A. Traulsen and C. Hauert, “Stochastic evolutionary game dynamics,” in Reviews of Nonlinear Dynamics and Complexity (Wiley-VCH Verlag GmbH and Co. KGaA, 2010) pp. 25–61.
  • Castellano et al. (2009) C. Castellano, S. Fortunato,  and V. Loreto, Reviews of Modern Physics 81, 591 (2009).
  • Keeling and Rohani (2008) M. J. Keeling and P. Rohani, Modeling Infectious Diseases in Humans and Animals (Princeton University Press, 2008).
  • Kampen (2007) N. V. Kampen, Stochastic processes in physics and chemistry (North Holland, 2007).
  • Acar et al. (2008) M. Acar, J. T. Mettetal,  and A. Van Oudenaarden, Nature Genetics 40, 471 (2008).
  • Patra and Klumpp (2015) P. Patra and S. Klumpp, Physical Biology 12, 046004 (2015).
  • Wienand et al. (2017) K. Wienand, E. Frey,  and M. Mobilia, Physical Review Letters 119, 158301 (2017).
  • Wienand et al. (2018) K. Wienand, E. Frey,  and M. Mobilia, Journal of The Royal Society Interface 15, 20180343 (2018).
  • Taitelbaum et al. (2020) A. Taitelbaum, R. West, M. Assaf,  and M. Mobilia, Physical Review Letters 125, 048105 (2020).
  • Black and McKane (2010) A. J. Black and A. J. McKane, Journal of Theoretical Biology 267, 85 (2010).
  • Gardiner (2004) C. W. Gardiner, Handbook of stochastic methods for physics, chemistry and the natural sciences, 3rd ed., Springer Series in Synergetics, Vol. 13 (Springer-Verlag, Berlin, 2004).
  • Kussell and Leibler (2005) E. Kussell and S. Leibler, Science 309, 2075 (2005).
  • Kepler and Elston (2001) T. B. Kepler and T. C. Elston, Biophysical Journal 81, 3116 (2001).
  • Thattai and Van Oudenaarden (2004) M. Thattai and A. Van Oudenaarden, Genetics 167, 523 (2004).
  • Swain et al. (2002) P. S. Swain, M. B. Elowitz,  and E. D. Siggia, Proceedings of the National Academy of Sciences (USA) 99, 12795 (2002).
  • Assaf et al. (2013a) M. Assaf, E. Roberts, Z. Luthey-Schulten,  and N. Goldenfeld, Physical Review Letters 111, 058102 (2013a).
  • Duncan et al. (2015) A. Duncan, S. Liao, T. Vejchodskỳ, R. Erban,  and R. Grima, Physical Review E 91, 042111 (2015).
  • Assaf et al. (2013b) M. Assaf, M. Mobilia,  and E. Roberts, Physical Review Letters 111, 238101 (2013b).
  • Ashcroft et al. (2014) P. Ashcroft, P. M. Altrock,  and T. Galla, Journal Royal Society Interface 11, 20140663 (2014).
  • West et al. (2018) R. West, M. Mobilia,  and A. M. Rucklidge, Physical Review E 97, 022406 (2018).
  • Assaf et al. (2008) M. Assaf, A. Kamenev,  and B. Meerson, Physical Review E 78, 041123 (2008).
  • Hufton et al. (2019a) P. G. Hufton, Y. T. Lin,  and T. Galla, Physical Review E 99, 032122 (2019a).
  • Eldar and Elowitz (2010) A. Eldar and M. Elowitz, Nature 467, 167 (2010).
  • Gillespie (1976) D. T. Gillespie, Journal of Computational Physics 22, 403 (1976).
  • Gillespie (1977) D. T. Gillespie, The Journal of Physical Chemistry 81, 2340 (1977).
  • Bowen et al. (1963) J. Bowen, A. Acrivos,  and A. Oppenheim, Chemical Engineering Science 18, 177 (1963).
  • Segel and Slemrod (1989) L. A. Segel and M. Slemrod, SIAM Review 31, 446 (1989).
  • Lin and Buchler (2018a) Y. T. Lin and N. E. Buchler, Journal of The Royal Society Interface 15, 20170804 (2018a).
  • Newby and Bressloff (2010) J. M. Newby and P. C. Bressloff, Bulletin of Mathematical Biology 72, 1840 (2010).
  • Bressloff (2016) P. C. Bressloff, Physical Review E 94, 042129 (2016).
  • Bressloff (2017a) P. C. Bressloff, Physical Review E 95, 012124 (2017a).
  • Bressloff (2017b) P. C. Bressloff, Physical Review E 95, 012138 (2017b).
  • Gillespie (2001) D. T. Gillespie, The Journal of Chemical Physics 115, 1716 (2001).
  • Hufton et al. (2019b) P. G. Hufton, Y. T. Lin,  and T. Galla, Physical Review E 99, 032121 (2019b).
  • Bressloff and Newby (2014) P. C. Bressloff and J. M. Newby, Physical Review E 89, 042701 (2014).
  • Hufton et al. (2016) P. G. Hufton, Y. T. Lin, T. Galla,  and A. J. McKane, Physical Review E 93, 052119 (2016).
  • Gunawardena (2014) J. Gunawardena, The FEBS Journal 281, 473 (2014).
  • Buchler et al. (2003) N. E. Buchler, U. Gerland,  and T. Hwa, Proceedings of the National Academy of Sciences (USA) 100, 5136 (2003).
  • Lin and Buchler (2018b) Y. T. Lin and N. E. Buchler, Journal Royal Society Interface 15 (2018b).
  • Fuglede and Topsoe (2004) B. Fuglede and F. Topsoe, in International Symposium on Information Theory, 2004. Proceedings. (2004) p. 31.
  • Lin (1991) J. Lin, IEEE Transactions on Information Theory 37, 145 (1991).
  • Note (1) For completeness, we add that simulations were performed on a MacBook Pro (Mid 2014), with processor 2.6 GHz Dual-Core Inter Core i5, and memory 8 GB 1600 MHz DDR3.
  • Lin et al. (2018) Y. T. Lin, P. G. Hufton, E. J. Lee,  and D. A. Potoyan, PLOS Computational Biology 14, 1 (2018).
  • Roberts et al. (2015) E. Roberts, S. Be’er, C. Bohrer, R. Sharma,  and M. Assaf, Physical Review E 92, 062717 (2015).
  • Klebaner (2005) F. C. Klebaner, Introduction to stochastic calculus with applications (World Scientific Publishing Company, Singapore, 2005).
  • Risken (1996) H. Risken, in The Fokker-Planck Equation (Springer, 1996) pp. 63–95.
  • Maruyama (1955) G. Maruyama, Rendiconti del Circolo Matematico di Palermo 4, 48 (1955).
  • Lewis and Shedler (1979) P. W. Lewis and G. S. Shedler, Naval Research Logistics Quarterly 26, 403 (1979).

Appendix A Second moments of rates

In this Appendix we calculate the second moments of the quantities R¯r(𝐧)\overline{R}_{r}(\mathbf{n}) (r=1,,Rr=1,\dots,R) defined in Eq. (8). Without loss of generality we assume that the time interval in question starts at t=0t=0, the end point is then Δt\Delta t. Assuming the space of environmental states is discrete, we have

R¯r(𝐧)R¯s(𝐧)\displaystyle\left\langle{\overline{R}_{r}(\mathbf{n})\overline{R}_{s}(\mathbf{n})}\right\rangle =\displaystyle= 1Δt20Δtdt10Δtdt2Rr,σ(t1)(𝐧)Rs,σ(t2)(𝐧)\displaystyle\frac{1}{\Delta t^{2}}\int_{0}^{\Delta t}\mathrm{d}t_{1}\int_{0}^{\Delta t}\mathrm{d}t_{2}\left\langle{R_{r,\sigma(t_{1})}(\mathbf{n})R_{s,\sigma(t_{2})}(\mathbf{n})}\right\rangle (38)
=\displaystyle= 1Δt20Δtdt1t1Δtdt2Rr,σ(t1)(𝐧)Rs,σ(t2)(𝐧)+1Δt20Δtdt2t2Δtdt1Rr,σ(t1)(𝐧)Rs,σ(t2)(𝐧)\displaystyle\frac{1}{\Delta t^{2}}\int_{0}^{\Delta t}\mathrm{d}t_{1}\int_{t_{1}}^{\Delta t}\mathrm{d}t_{2}\left\langle{R_{r,\sigma(t_{1})}(\mathbf{n})R_{s,\sigma(t_{2})}(\mathbf{n})}\right\rangle+\frac{1}{\Delta t^{2}}\int_{0}^{\Delta t}\mathrm{d}t_{2}\int_{t_{2}}^{\Delta t}\mathrm{d}t_{1}\left\langle{R_{r,\sigma(t_{1})}(\mathbf{n})R_{s,\sigma(t_{2})}(\mathbf{n})}\right\rangle
=\displaystyle= 1Δt2σσ0Δtdt1t1Δtdt2ρσqσσ(t2t1)Rr,σ(𝐧)Rs,σ(𝐧)\displaystyle\frac{1}{\Delta t^{2}}\sum_{\sigma\sigma^{\prime}}\int_{0}^{\Delta t}\mathrm{d}t_{1}\int_{t_{1}}^{\Delta t}\mathrm{d}t_{2}~{}\rho^{*}_{\sigma}q_{\sigma\to\sigma^{\prime}}(t_{2}-t_{1})R_{r,\sigma}(\mathbf{n})R_{s,\sigma^{\prime}}(\mathbf{n})
+1Δt2σσ0Δtdt2t2Δtdt1ρσqσσ(t1t2)Rr,σ(𝐧)Rs,σ(𝐧)\displaystyle+\frac{1}{\Delta t^{2}}\sum_{\sigma\sigma^{\prime}}\int_{0}^{\Delta t}\mathrm{d}t_{2}\int_{t_{2}}^{\Delta t}\mathrm{d}t_{1}~{}\rho^{*}_{\sigma^{\prime}}q_{\sigma^{\prime}\to\sigma}(t_{1}-t_{2})R_{r,\sigma}(\mathbf{n})R_{s,\sigma^{\prime}}(\mathbf{n})
=\displaystyle= 1Δt2σσ0Δtdt1t1Δtdt2ρσqσσ(t2t1)Rr,σ(𝐧)Rs,σ(𝐧)\displaystyle\frac{1}{\Delta t^{2}}\sum_{\sigma\sigma^{\prime}}\int_{0}^{\Delta t}\mathrm{d}t_{1}\int_{t_{1}}^{\Delta t}\mathrm{d}t_{2}~{}\rho^{*}_{\sigma}q_{\sigma\to\sigma^{\prime}}(t_{2}-t_{1})R_{r,\sigma}(\mathbf{n})R_{s,\sigma^{\prime}}(\mathbf{n})
+1Δt2σσ0Δtdt1t1Δtdt2ρσqσσ(t2t1)Rr,σ(𝐧)Rs,σ(𝐧).\displaystyle+\frac{1}{\Delta t^{2}}\sum_{\sigma\sigma^{\prime}}\int_{0}^{\Delta t}\mathrm{d}t_{1}\int_{t_{1}}^{\Delta t}\mathrm{d}t_{2}~{}\rho^{*}_{\sigma}q_{\sigma\to\sigma^{\prime}}(t_{2}-t_{1})R_{r,\sigma^{\prime}}(\mathbf{n})R_{s,\sigma}(\mathbf{n}).

In the first step we have applied the definition of the over-bar average [Eq. (8)]. In the third step we have carried out the average over realisations of the environmental process. In the last step we have renamed t1t2t_{1}\leftrightarrow t_{2} and σσ\sigma\leftrightarrow\sigma^{\prime} in the second term. Therefore

R¯r(𝐧)R¯s(𝐧)\displaystyle\left\langle{\overline{R}_{r}(\mathbf{n})\overline{R}_{s}(\mathbf{n})}\right\rangle =\displaystyle= 1Δt2σσ0Δtdt1t1Δtdt2ρσqσσ(t2t1)[Rr,σ(𝐧)Rs,σ(𝐧)+Rr,σ(𝐧)Rs,σ(𝐧)].\displaystyle\frac{1}{\Delta t^{2}}\sum_{\sigma\sigma^{\prime}}\int_{0}^{\Delta t}\mathrm{d}t_{1}\int_{t_{1}}^{\Delta t}\mathrm{d}t_{2}~{}\rho^{*}_{\sigma}q_{\sigma\to\sigma^{\prime}}(t_{2}-t_{1})\big{[}R_{r,\sigma}(\mathbf{n})R_{s,\sigma^{\prime}}(\mathbf{n})+R_{r,\sigma^{\prime}}(\mathbf{n})R_{s,\sigma}(\mathbf{n})\big{]}. (39)

Up to a shift of the start point of the time step, this is identical to Eq. (10).

As explained in Section V.2, the sums over σ\sigma become integrals when the environment takes continuous states. We then find Eq. (30).

When the environmental space is discrete, we can use Eq. (7) and find

R¯r(𝐧)R¯s(𝐧)\displaystyle\left\langle{\overline{R}_{r}(\mathbf{n})\overline{R}_{s}(\mathbf{n})}\right\rangle =1Δt2σσ0Δtdt1t1Δtdt2ρσρσ[Rr,σ(𝐧)Rs,σ(𝐧)+Rr,σ(𝐧)Rs,σ(𝐧)]\displaystyle=\frac{1}{\Delta t^{2}}\sum_{\sigma\sigma^{\prime}}\int_{0}^{\Delta t}\mathrm{d}t_{1}\int_{t_{1}}^{\Delta t}\mathrm{d}t_{2}~{}\rho^{*}_{\sigma}\rho^{*}_{\sigma^{\prime}}\big{[}R_{r,\sigma}(\mathbf{n})R_{s,\sigma^{\prime}}(\mathbf{n})+R_{r,\sigma^{\prime}}(\mathbf{n})R_{s,\sigma}(\mathbf{n})\big{]}
+1Δt2σσ=2M0Δtdt1t1Δtdt2ρσc,σv,σeλμ(t2t1)[Rr,σ(𝐧)Rs,σ(𝐧)+Rr,σ(𝐧)Rs,σ(𝐧)]\displaystyle+\frac{1}{\Delta t^{2}}\sum_{\sigma\sigma^{\prime}}\sum_{\ell=2}^{M}\int_{0}^{\Delta t}\mathrm{d}t_{1}\int_{t_{1}}^{\Delta t}\mathrm{d}t_{2}~{}\rho^{*}_{\sigma}c_{\ell,\sigma}v_{\ell,\sigma^{\prime}}e^{-\lambda\mu_{\ell}(t_{2}-t_{1})}\big{[}R_{r,\sigma}(\mathbf{n})R_{s,\sigma^{\prime}}(\mathbf{n})+R_{r,\sigma^{\prime}}(\mathbf{n})R_{s,\sigma}(\mathbf{n})\big{]}
=Rr,avg(𝐧)Rs,avg(𝐧)\displaystyle=R_{r,\rm avg}(\mathbf{n})R_{s,\rm avg}(\mathbf{n})
+1Δt2σσ=2Mρσc,σv,σ[Rr,σ(𝐧)Rs,σ(𝐧)+Rr,σ(𝐧)Rs,σ(𝐧)]0Δtdt1t1Δtdt2eλμ(t2t1).\displaystyle+\frac{1}{\Delta t^{2}}\sum_{\sigma\sigma^{\prime}}\sum_{\ell=2}^{M}\rho^{*}_{\sigma}c_{\ell,\sigma}v_{\ell,\sigma^{\prime}}\big{[}R_{r,\sigma}(\mathbf{n})R_{s,\sigma^{\prime}}(\mathbf{n})+R_{r,\sigma^{\prime}}(\mathbf{n})R_{s,\sigma}(\mathbf{n})\big{]}\int_{0}^{\Delta t}\mathrm{d}t_{1}\int_{t_{1}}^{\Delta t}\mathrm{d}t_{2}~{}e^{\lambda\mu_{\ell}(t_{2}-t_{1})}. (40)

Appendix B Further details for systems with two species and two environmental states

The case of two species and two environmental states (S=2,M=2S=2,M=2) was studied in Hufton et al. (2019b), and a simple version of the τ\tauFE algorithm was presented for this restricted case. We assume σ\sigma switches from state 0 to state 11 with rate λk1\lambda k_{1}, and from 11 to 0 with rate λk0\lambda k_{0}. The environmental transition matrix then becomes

𝐀=(k1k0k1k0),\mathbf{A}=\left(\begin{array}[]{cc}-k_{1}&k_{0}\\ k_{1}&-k_{0}\end{array}\right), (41)

whose eigenvalues are μ1=0\mu_{1}=0 and μ2=(k0+k1)\mu_{2}=-(k_{0}+k_{1}). The respective eigenvectors take the form

𝐯1=𝝆=1k0+k1(k0k1)and𝐯2=(11),\mathbf{v}_{1}={\mbox{\boldmath$\rho$}}^{*}=\frac{1}{k_{0}+k_{1}}\left(\begin{array}[]{c}k_{0}\\ k_{1}\end{array}\right)\quad\text{and}\quad\mathbf{v}_{2}=\left(\begin{array}[]{c}1\\ -1\end{array}\right), (42)

where 𝝆{\mbox{\boldmath$\rho$}}^{*} has been normalised to represent the stationary distribution for σ\sigma. The coefficients c2,0c_{2,0} and c2,1c_{2,1} are obtained from Eq. (6), for the initial conditions 𝝆(0)=(1,0){\mbox{\boldmath$\rho$}}(0)=(1,0) and 𝝆(0)=(0,1){\mbox{\boldmath$\rho$}}(0)=(0,1). We find

c2,0=k1k0+k1andc2,1=k0k0+k1.c_{2,0}=\frac{k_{1}}{k_{0}+k_{1}}\quad\text{and}\quad c_{2,1}=\frac{-k_{0}}{k_{0}+k_{1}}. (43)

Putting all together in Eq. (13), and after straightforward calculations we arrive at

ΞrsR¯r(𝐧)R¯s(𝐧)Rr(𝐧)Rs(𝐧)=θ2λΔt[Rr,1(𝐧)Rr,0(𝐧)][Rs,1(𝐧)Rs,0(𝐧)],\displaystyle\Xi_{rs}\equiv\left\langle{\overline{R}_{r}(\mathbf{n})\overline{R}_{s}(\mathbf{n})}\right\rangle-R_{r}^{*}(\mathbf{n})R_{s}^{*}(\mathbf{n})=\frac{\theta^{2}}{\lambda\Delta t}\left[R_{r,1}(\mathbf{n})-R_{r,0}(\mathbf{n})\right]\left[R_{s,1}(\mathbf{n})-R_{s,0}(\mathbf{n})\right], (44)

where θ2=2k0k1/(k0+k1)3\theta^{2}=2k_{0}k_{1}/(k_{0}+k_{1})^{3}. The indices rr and ss stand for reactions affected by the environment. As explained in Section III.3, to simulate the τ\tauFE algorithm we need to draw correlated Gaussian random numbers R¯r\overline{R}_{r} with means

Rr(𝐧)=k0Rr,0+k1Rr,0k0+k1,R^{*}_{r}(\mathbf{n})=\dfrac{k_{0}R_{r,0}+k_{1}R_{r,0}}{k_{0}+k_{1}}, (45)

for r=1,2r=1,2, and covariance matrix

𝚺=(Ξ11Ξ12Ξ21Ξ22).\mathbf{\Sigma}=\left(\begin{array}[]{cc}\Xi_{11}&\Xi_{12}\\ \Xi_{21}&\Xi_{22}\end{array}\right). (46)

One way to do this is by drawing independent Gaussian random numbers z1z_{1} and z2z_{2} with mean zero and unit variance, and then to set

(R¯1(𝐧)R¯2(𝐧))=(R1(𝐧)R2(𝐧))+𝐂(z1z2),\left(\begin{array}[]{c}\overline{R}_{1}(\mathbf{n})\\ \overline{R}_{2}(\mathbf{n})\end{array}\right)=\left(\begin{array}[]{c}R_{1}^{*}(\mathbf{n})\\ R_{2}^{*}(\mathbf{n})\end{array}\right)+\mathbf{C}\left(\begin{array}[]{c}z_{1}\\ z_{2}\end{array}\right), (47)

with a matrix 𝐂\mathbf{C} that fulfils 𝐂𝐂T=𝚺\mathbf{C}\mathbf{C}^{T}=\mathbf{\Sigma}, where TT denotes the transpose. This matrix is not unique. We use

𝐂=𝚺θ2/(λΔt){[R1,1(𝐧)R1,0(𝐧)]2+[R2,1(𝐧)R2,0(𝐧)]2}.\mathbf{C}=\dfrac{\mathbf{\Sigma}}{\sqrt{\theta^{2}/(\lambda\Delta t)\left\{\left[R_{1,1}(\mathbf{n})-R_{1,0}(\mathbf{n})\right]^{2}+\left[R_{2,1}(\mathbf{n})-R_{2,0}(\mathbf{n})\right]^{2}\right\}}}. (48)

Appendix C Birth-death process with two species and three environmental states

In the example in Sec. IV.2 we have the following transition matrix for the environmental process

𝐀=(k10k0k1k200k2k0).\mathbf{A}=\left(\begin{array}[]{ccc}-k_{1}&0&k_{0}\\ k_{1}&-k_{2}&0\\ 0&k_{2}&-k_{0}\end{array}\right). (49)

The eigenvalues of this matrix are

μ1=0,μ2=12(k0+k1+k2+Γ),and,μ3=12(k0+k1+k2Γ),\mu_{1}=0,\quad\mu_{2}=-\frac{1}{2}\left(k_{0}+k_{1}+k_{2}+\Gamma\right),\quad\text{and},\quad\mu_{3}=-\frac{1}{2}\left(k_{0}+k_{1}+k_{2}-\Gamma\right), (50)

with Γ=k02+k12+k222(k0k1+k1k2+k2k0)\Gamma=\sqrt{k_{0}^{2}+k_{1}^{2}+k_{2}^{2}-2(k_{0}k_{1}+k_{1}k_{2}+k_{2}k_{0})}. The associated eigenvectors take the form

𝐯1=𝝆=1k0k1+k1k2+k2k0(k2k0k0k1k1k2),\mathbf{v}_{1}={\mbox{\boldmath$\rho$}}^{*}=\frac{1}{k_{0}k_{1}+k_{1}k_{2}+k_{2}k_{0}}\left(\begin{array}[]{c}k_{2}k_{0}\\ k_{0}k_{1}\\ k_{1}k_{2}\end{array}\right), (51)

and

𝐯2=((k0+k1k2+Γ)/(2k2)(k0k1k2Γ)/(2k2)1),𝐯3=((k0+k1k2Γ)/(2k2)(k0k1k2+Γ)/(2k2)1).\mathbf{v}_{2}=\left(\begin{array}[]{c}(-k_{0}+k_{1}-k_{2}+\Gamma)/(2k_{2})\\ (k_{0}-k_{1}-k_{2}-\Gamma)/(2k_{2})\\ 1\end{array}\right),\quad\quad\mathbf{v}_{3}=\left(\begin{array}[]{c}(-k_{0}+k_{1}-k_{2}-\Gamma)/(2k_{2})\\ (k_{0}-k_{1}-k_{2}+\Gamma)/(2k_{2})\\ 1\end{array}\right). (52)

Using Eq. (6) and three sets of initial conditions (each concentrated on one environmental state) we find

c2,0=k1k2(k0+k1+k2Γ)2Γ(k0k1+k1k2+k2k0),c3,0=k1k2(k0+k1+k2+Γ)2Γ(k0k1+k1k2+k2k0),c_{2,0}=\dfrac{k_{1}k_{2}\left(k_{0}+k_{1}+k_{2}-\Gamma\right)}{2\Gamma(k_{0}k_{1}+k_{1}k_{2}+k_{2}k_{0})},\quad c_{3,0}=-\dfrac{k_{1}k_{2}\left(k_{0}+k_{1}+k_{2}+\Gamma\right)}{2\Gamma(k_{0}k_{1}+k_{1}k_{2}+k_{2}k_{0})}, (53)

as well as

c2,1=k2(k0(k1+2k2)+k1(k1+k2+Γ))2Γ(k0k1+k1k2+k2k0),c3,1=k2(k0(k1+2k2)+k1(k1+k2Γ))2Γ(k0k1+k1k2+k2k0),c_{2,1}=-\dfrac{k_{2}\left(k_{0}(k_{1}+2k_{2})+k_{1}\left(-k_{1}+k_{2}+\Gamma\right)\right)}{2\Gamma(k_{0}k_{1}+k_{1}k_{2}+k_{2}k_{0})},\quad c_{3,1}=\dfrac{k_{2}\left(k_{0}(k_{1}+2k_{2})+k_{1}\left(-k_{1}+k_{2}-\Gamma\right)\right)}{2\Gamma(k_{0}k_{1}+k_{1}k_{2}+k_{2}k_{0})}, (54)

and finally

c2,2=k0(k12k22+k0(k1+k2)+k1Γ+k2Γ)2Γ(k0k1+k1k2+k2k0),c3,2=k0(k12+k22k0(k1+k2)+k1Γ+k2Γ)2Γ(k0k1+k1k2+k2k0).c_{2,2}=\dfrac{k_{0}\left(-k_{1}^{2}-k_{2}^{2}+k_{0}(k_{1}+k_{2})+k_{1}\Gamma+k_{2}\Gamma\right)}{2\Gamma(k_{0}k_{1}+k_{1}k_{2}+k_{2}k_{0})},\quad c_{3,2}=\dfrac{k_{0}\left(k_{1}^{2}+k_{2}^{2}-k_{0}(k_{1}+k_{2})+k_{1}\Gamma+k_{2}\Gamma\right)}{2\Gamma(k_{0}k_{1}+k_{1}k_{2}+k_{2}k_{0})}. (55)

Putting all together in Eqs. (2) and (13) and after further tedious but straightforward calculations, we arrive at the expressions in Eqs. (18) and (19).

In order to draw the correlated Gaussian random numbers α¯\bar{\alpha} and β¯\bar{\beta} required for the τ\tau-leaping step, we proceed as in Appendix B. We construct the covariance matrix 𝚺\mathbf{\Sigma} [Eq. (46)] and then find a matrix 𝐂\mathbf{C} such that 𝐂𝐂T=𝚺\mathbf{C}\mathbf{C}^{T}=\mathbf{\Sigma}. We then draw independent Gaussian random numbers z1z_{1} and z2z_{2} with mean zero and unit variance, and use an expresion analogous to that in Eq. (47) to obtain α¯\bar{\alpha} and β¯\bar{\beta}. The matrix 𝐂\mathbf{C} we use is

𝐂=A(σαα+Bσαβ11σββ+Bσαβ),\mathbf{C}=A\left(\begin{array}[]{cc}\dfrac{\sigma_{\alpha\alpha}+B}{\sigma_{\alpha\beta}}&1\\ 1&\dfrac{\sigma_{\beta\beta}+B}{\sigma_{\alpha\beta}}\end{array}\right), (56)

with σαα\sigma_{\alpha\alpha} and σαβ\sigma_{\alpha\beta} as given in Eq. (19), and

A=σαβσαα+σββ+B,A=\dfrac{\sigma_{\alpha\beta}}{\sqrt{\sigma_{\alpha\alpha}+\sigma_{\beta\beta}+B}}, (57)

and

B=3k0k1k2λΔt(k0k1+k1k2+k2k0)2×|α0(β2β1)+α1(β0β2)+α2(β1β0)|.\displaystyle B=\dfrac{\sqrt{3}k_{0}k_{1}k_{2}}{\lambda\Delta t(k_{0}k_{1}+k_{1}k_{2}+k_{2}k_{0})^{2}}\times\lvert\alpha_{0}(\beta_{2}-\beta_{1})+\alpha_{1}(\beta_{0}-\beta_{2})+\alpha_{2}(\beta_{1}-\beta_{0})\rvert. (58)

Appendix D Bimodal genetic switch

For the model in Sec. IV.3 the rates of the environmental transitions depend on the number of proteins nPn_{P} in the population. We assume that nPn_{P} remains constant during each τ\tau-leaping step. The environmental transition matrix then becomes

𝐀=(k~+k0k~+k~+kk0k~+k),\mathbf{A}=\left(\begin{array}[]{ccc}-\tilde{k}_{+}&k_{-}&0\\ \tilde{k}_{+}&-\tilde{k}_{+}-k_{-}&k_{-}\\ 0&\tilde{k}_{+}&-k_{-}\end{array}\right), (59)

with k~+=k+nP/Ω\tilde{k}_{+}=k_{+}n_{P}/\Omega. The eigenvalues of this matrix are

μ1=0,μ2=kk~+kk~+,μ3=kk~++kk~+,\displaystyle\mu_{1}=0,\quad\mu_{2}=-k_{-}-\tilde{k}_{+}-\sqrt{k_{-}\tilde{k}_{+}},\quad\mu_{3}=-k_{-}-\tilde{k}_{+}+\sqrt{k_{-}\tilde{k}_{+}}, (60)

while the associated eigenvectors take the form

𝐯1=𝝆=1k2+kk~++k~+2(k2kk~+k~+2),\mathbf{v}_{1}={\mbox{\boldmath$\rho$}}^{*}=\frac{1}{k_{-}^{2}+k_{-}\tilde{k}_{+}+\tilde{k}_{+}^{2}}\left(\begin{array}[]{c}k_{-}^{2}\\ k_{-}\tilde{k}_{+}\\ \tilde{k}_{+}^{2}\end{array}\right),
𝐯2=(k/k~+(kk~+)/k~+1),and,𝐯3=(k/k~+(kk~+)/k~+1).\displaystyle\mathbf{v}_{2}=\left(\begin{array}[]{c}\sqrt{k_{-}/\tilde{k}_{+}}\\ \left(-\sqrt{k_{-}}-\sqrt{\tilde{k}_{+}}\right)/\sqrt{\tilde{k}_{+}}\\ 1\end{array}\right),\quad\text{and,}\quad\mathbf{v}_{3}=\left(\begin{array}[]{c}-\sqrt{k_{-}/\tilde{k}_{+}}\\ \left(\sqrt{k_{-}}-\sqrt{\tilde{k}_{+}}\right)/\sqrt{\tilde{k}_{+}}\\ 1\end{array}\right). (67)

Applying Eq. (6) for different initial conditions as above, we obtain

c2,0=k~+3/22k(k+kk~++k~+),c3,0=k~+3/22k(kkk~++k~+),c_{2,0}=\dfrac{\tilde{k}_{+}^{3/2}}{2\sqrt{k_{-}}\left(k_{-}+\sqrt{k_{-}\tilde{k}_{+}}+\tilde{k}_{+}\right)},\quad c_{3,0}=-\dfrac{\tilde{k}_{+}^{3/2}}{2\sqrt{k_{-}}\left(k_{-}-\sqrt{k_{-}\tilde{k}_{+}}+\tilde{k}_{+}\right)}, (68)

as well as

c2,1=k~++kk~+2(k+kk~++k~+),c3,1=k~+kk~+2(kkk~++k~+),c_{2,1}=-\dfrac{\tilde{k}_{+}+\sqrt{k_{-}\tilde{k}_{+}}}{2\left(k_{-}+\sqrt{k_{-}\tilde{k}_{+}}+\tilde{k}_{+}\right)},\quad c_{3,1}=-\dfrac{\tilde{k}_{+}-\sqrt{k_{-}\tilde{k}_{+}}}{2\left(k_{-}-\sqrt{k_{-}\tilde{k}_{+}}+\tilde{k}_{+}\right)}, (69)

and finally

c2,2=k2(k+kk~++k~+),c3,2=k2(kkk~++k~+).c_{2,2}=-\dfrac{k_{-}}{2\left(k_{-}+\sqrt{k_{-}\tilde{k}_{+}}+\tilde{k}_{+}\right)},\quad c_{3,2}=-\dfrac{k_{-}}{2\left(k_{-}-\sqrt{k_{-}\tilde{k}_{+}}+\tilde{k}_{+}\right)}. (70)

Putting this together in Eqs. (2) and (13) and after straightforward calculations, we arrive at the expressions in Eqs. (23) and (24).

Since only one reaction is affected by the environmental state, it is only necessary to drawn one Gaussian random number with mean bb^{*} and variance σbb\sigma_{bb} in each step of the τ\tauFE algorithm, with bb^{*} and σbb\sigma_{bb} given in Eqs. (23) and (24) respectively.

Appendix E Gillespie algorithm with discretised environmental dynamics (GADE)

In this Appendix we briefly describe the constructions of the rates given in Eq. (31). They define a continuous-time dynamics on a discrete state space approximating the Ornstein–Uhlenbeck process in Eq. (26).

Matching the first moments of movements. We first look at the mean drift of σ\sigma, i.e., the mean change of σ\sigma per unit time. Suppose the environment is in a given state σ\sigma. The mean drift in the Ornstein–Uhlenbeck process [Eq. (26)] is then λ(mσ)\lambda(m-\sigma).

Suppose now the above discrete-σ\sigma process is in state σ=kΔσ\sigma=k\Delta\sigma. Then σ\sigma increases to σ+Δσ\sigma+\Delta\sigma with rate Tk+T_{k}^{+} and decreases to σΔσ\sigma-\Delta\sigma with rate TkT_{k}^{-}. The expected change (per unit time) is therefore Δσ×(Tk+Tk)\Delta\sigma\times(T_{k}^{+}-T_{k}^{-}).

We conclude that we need to impose

Δσ×(Tk+Tk)=λ(mkΔσ).\Delta\sigma\times(T_{k}^{+}-T_{k}^{-})=\lambda(m-k\Delta\sigma). (71)

Matching the variance of movements. Next we look at the variance of movements of σ\sigma. For the Ornstein–Uhlenbeck process in Eq. (26) the second moment of movements (per unit time) is given by 2λv22\lambda v^{2}. In the discrete-σ\sigma process, the second moment of movements is (Δσ)2×(Tk++Tk)(\Delta\sigma)^{2}\times(T_{k}^{+}+T_{k}^{-}). To match the Ornstein–Uhlenbeck process, we then need to impose

(Δσ)2×(Tk++Tk)=2λv2.(\Delta\sigma)^{2}\times(T_{k}^{+}+T_{k}^{-})=2\lambda v^{2}. (72)

Overall solution. Simultaneously solving Eqs. (71) and (72) for Tk+T_{k}^{+} and TkT_{k}^{-} we arrive at Eq. (31).

Appendix F Additional examples of production-removal processes in continuous environments

In this Appendix we include results for the variances and covariances R¯r(n)R¯s(n)Rr(𝐧)Rs(n)\left\langle{\overline{R}_{r}(n)\overline{R}_{s}(n)}\right\rangle-R_{r}^{*}(\mathbf{n})R_{s}^{*}(n) for two further exemplar systems in which the environment follows the Ornstein–Uhlenbeck process in Eq. (26). We set m=0m=0 for both examples. Both systems describe production and removal dynamics of a single species. In the first example, production and removal rates are proportional to σ\sigma when σ>0\sigma>0 and zero otherwise. In the second example the rates are each proportional to |σ||\sigma|. These examples are not used in the main paper, we report them here for completeness, as they may prove useful for future applications of the τ\tauFE algorithm.

F.1 Rates Rr,σ(n)=αrσΘ(σ)R_{r,\sigma}(n)=\alpha_{r}\sigma\Theta(\sigma)

We look at the example Rr,σ(n)=αrσΘ(σ)R_{r,\sigma}(n)=\alpha_{r}\sigma\Theta(\sigma), where Θ(σ)\Theta(\sigma) is the Heaviside function, Θ(σ)=1\Theta(\sigma)=1 for σ>0\sigma>0 and Θ(σ)=0\Theta(\sigma)=0 otherwise. For m=0m=0, we find

Rr(n)=αrvπ,R_{r}^{*}(n)=\alpha_{r}\dfrac{v}{\sqrt{\pi}}, (73)

and

R¯r(n)R¯s(n)Rr(n)Rs(n)=\displaystyle\left\langle{\overline{R}_{r}(n)\overline{R}_{s}(n)}\right\rangle-R_{r}^{*}(n)R_{s}^{*}(n)=
αrαsv224πΔt2{1λ2[24π(λΔt1)π2+12log2(2)]+\displaystyle\quad\frac{\alpha_{r}\alpha_{s}v^{2}}{24\pi\Delta t^{2}}\Bigg{\{}\dfrac{1}{\lambda^{2}}\left[24\pi\left(\lambda\Delta t-1\right)-\pi^{2}+12\log^{2}(2)\right]+
4eλΔtλ2[3(6e2λΔt1+π)4eλΔtlog(e2λΔt1+eλΔt)+6tan1(1e2λΔt1)]\displaystyle\quad\dfrac{4e^{-\lambda\Delta t}}{\lambda^{2}}\left[3\left(6\sqrt{e^{2\lambda\Delta t}-1}+\pi\right)-4e^{\lambda\Delta t}\log\left(\sqrt{e^{2\lambda\Delta t}-1}+e^{\lambda\Delta t}\right)+6\tan^{-1}\left(\frac{1}{\sqrt{e^{2\lambda\Delta t}-1}}\right)\right]
32λ2Re(isin1(eλΔt))6[1λ2log2(1e2λΔt+1)+4Δtλlog(1e2λΔt+1)\displaystyle\quad-\dfrac{32}{\lambda^{2}}\text{Re}\left(i\sin^{-1}\left(e^{\lambda\Delta t}\right)\right)-6\bigg{[}\dfrac{1}{\lambda^{2}}\log^{2}\left(\sqrt{1-e^{-2\lambda\Delta t}}+1\right)+\dfrac{4\Delta t}{\lambda}\log\left(\sqrt{1-e^{-2\lambda\Delta t}}+1\right)
4Δtlog(2)λlog(4)λ2log(1e2λΔt+1)4Δtλtanh1(eλΔte2λΔt1)\displaystyle\quad-\dfrac{4\Delta t\log(2)}{\lambda}-\dfrac{\log(4)}{\lambda^{2}}\log\left(\sqrt{1-e^{-2\lambda\Delta t}}+1\right)-\dfrac{4\Delta t}{\lambda}\tanh^{-1}\left(e^{-\lambda\Delta t}\sqrt{e^{2\lambda\Delta t}-1}\right)
2λ2Li2(12(11e2λΔt))+log2(2)λ2+2Δt2]24},\displaystyle\quad-\dfrac{2}{\lambda^{2}}\text{Li}_{2}\left(\frac{1}{2}\left(1-\sqrt{1-e^{-2\lambda\Delta t}}\right)\right)+\dfrac{\log^{2}(2)}{\lambda^{2}}+2\Delta t^{2}\bigg{]}-24\Bigg{\}}, (74)

where Re(\cdot) denotes the real part, and Li2()\text{Li}_{2}(\cdot) is the polylogarithm of order 2.

F.2 Rates Rr,σ(n)=αr|σ|R_{r,\sigma}(n)=\alpha_{r}|\sigma|

For this case (and setting again m=0m=0), we find

Rr(n)=αr2vπ,R_{r}^{*}(n)=\alpha_{r}\dfrac{2v}{\sqrt{\pi}}, (75)

and

R¯r(n)R¯s(n)Rr(𝐧)Rs(n)=\displaystyle\left\langle{\overline{R}_{r}(n)\overline{R}_{s}(n)}\right\rangle-R_{r}^{*}(\mathbf{n})R_{s}^{*}(n)=
αrαsv26πΔt2{12Δtλ[2log(1e2λΔt+1)+2tanh1(1e2λΔt)+π+log(4)]\displaystyle\quad\frac{\alpha_{r}\alpha_{s}v^{2}}{6\pi\Delta t^{2}}\Bigg{\{}\dfrac{12\Delta t}{\lambda}\left[-2\log\left(\sqrt{1-e^{-2\lambda\Delta t}}+1\right)+2\tanh^{-1}\left(\sqrt{1-e^{-2\lambda\Delta t}}\right)+\pi+\log(4)\right]
+1λ2[72eλΔte2λΔt16log2(12(1e2λΔt+1))+24eλΔttan1(1e2λΔt1)\displaystyle\quad+\dfrac{1}{\lambda^{2}}\Bigg{[}72e^{-\lambda\Delta t}\sqrt{e^{2\lambda\Delta t}-1}-6\log^{2}\left(\frac{1}{2}\left(\sqrt{1-e^{-2\lambda\Delta t}}+1\right)\right)+24e^{-\lambda\Delta t}\tan^{-1}\left(\frac{1}{\sqrt{e^{2\lambda\Delta t}-1}}\right)
48tanh1(eλΔte2λΔt1)+12Li2(12(11e2λΔt))π212π+12log2(2)]\displaystyle\quad-48\tanh^{-1}\left(e^{-\lambda\Delta t}\sqrt{e^{2\lambda\Delta t}-1}\right)+12\text{Li}_{2}\left(\frac{1}{2}\left(1-\sqrt{1-e^{-2\lambda\Delta t}}\right)\right)-\pi^{2}-12\pi+12\log^{2}(2)\Bigg{]}
12(Δt2+2)}.\displaystyle\quad-12\left(\Delta t^{2}+2\right)\Bigg{\}}. (76)