Theory for the optimal detection of time-varying signals in cellular sensing systems

Living cells often need to measure chemical concentrations that vary in time. To this end, they deploy many resources, e.g. receptors, downstream signaling molecules, time and energy. Here, we present a theory for the optimal design of a large class of sensing systems that need to detect time-varying signals, a receptor driving a push-pull network. The theory is based on the concept of the dynamic input-output relation, which describes the mapping between the current ligand concentration and the average receptor occupancy over the past integration time. This concept is used to develop the idea that the cell employs its push-pull network to estimate the receptor occupancy and then uses this estimate to infer the current ligand concentration by inverting the dynamic input-output relation. The theory reveals that the sensing error can be decomposed into two terms: the sampling error in the estimate of the receptor occupancy and the dynamical error that arises because the average ligand concentration over the past integration time may not reflect the current ligand concentration. The theory generalizes the design principle of optimal resource allocation previously identified for static signals, which states that in an optimally designed sensing system the three fundamental resource classes of receptors and their integration time, readout molecules, and energy are equally limiting so that no resource is wasted. However, in contrast to static signals, receptors and power cannot be traded freely against time to reach a desired sensing precision: there exists an optimal integration time that maximizes the sensing precision, which depends on the number of receptors, the receptor correlation time, and the correlation time and variance of the input signal. Applying our theory to the chemotaxis system of Escherichia coli indicates that this bacterium has evolved to optimally sense shallow gradients.


Introduction
Living cells continually have to respond and adapt to changes in their environment. They often do so on a timescale that is comparable to that of the environmental variations. Examples are cells that during their development differentiate in response to time-varying morphogen gradients (Durrieu et al., 2018) or cells that navigate through their environment (Tostevin and ten Wolde, 2009;Sartori and Tu, 2011;Long et al., 2016). These cells shape, via their movement, the statistics of the input signal, such that the timescale of the input fluctuations becomes comparable to that of the response. In all these cases, it is important to understand how accurately the cell can estimate chemical concentrations that vary in time.
Cells measure chemical concentrations via receptors on their surface. These measurements are inevitably corrupted by the stochastic arrival of the ligand molecules by diffusion and by the stochastic binding of the ligand to the receptor. Wiener and Kolmogorov (Extrapolation, 1950;Kolmogorov, 1992) and Kalman, 1960 have developed theories for the optimal strategy to estimate signals in the presence of noise. Their filtering theories have been employed widely in engineering, and in recent years they have also been applied to cell signaling. They have been used to show that time integration can improve the sensing of time-varying signals by reducing receptor noise, although it cannot remove this input noise completely because of signal distortion (Andrews et al., 2006;Hinczewski and Thirumalai, 2014;Becker et al., 2015). It has been shown that circadian systems can adapt their response to the statistics of the input signal, as predicted by Kalman filtering theory (Husain et al., 2019). Moreover, Wiener-Kolmogorov filtering theory has been employed to derive the optimal topology of the cellular network depending on the statistics of the input signal (Becker et al., 2015). Negative feedback and incoherent feedforward, which are common motifs in cell signaling (Alon, 2007), make it possible to predict future signal values via signal extrapolation, which is useful when the past signal contains information about the future in addition to the current signal (Becker et al., 2015).
The precision of sensing depends not only on the topology of the cellular sensing network but also on the resources required to build and operate it. Receptors and time are needed to take the concentration measurements (Berg and Purcell, 1977), downstream molecules are necessary to store the ligand-binding states of the receptor in the past, and energy is required to store these states reliably (Govern and Ten Wolde, 2014a). Many studies have addressed the question how receptors and time limit the precision of sensing static concentrations that do not vary on the timescale of cellular response (Berg and Purcell, 1977;Bialek and Setayeshgar, 2005;Wang et al., 2007;Rappel and Levine, 2008;Endres and Wingreen, 2009;Hu et al., 2010;Mora and Wingreen, 2010;Govern and Ten Wolde, 2012;Mehta and Schwab, 2012;Govern and Ten Wolde, 2014a;Govern and Ten Wolde, 2014b;Kaizu et al., 2014;Ten Wolde et al., 2016;Mugler et al., 2016;Fancher and Mugler, 2017). In addition, progress has been made in understanding how the number of readout molecules and energy set the precision of sensing static signals (Mehta and Schwab, 2012;Govern and Ten Wolde, 2014a;Govern and Ten Wolde, 2014b). Yet, what the resource requirements for sensing time-varying signals are is a wide open question. In particular, it is not known how the number of receptor and readout molecules, time, and power required to maintain a desired sensing precision depend on the strength and the timescale of the input fluctuations.
In this article, we present a theory for the optimal design of cellular sensing systems as set by resource constraints and the dynamics of the input signal. The theory applies to one of the most common motifs in cell signaling, a receptor that drives a push-pull network, which consists of a cycle of protein activation and deactivation (Goldbeter and Koshland, 1981, see Figure 1). These systems are omnipresent in prokaryotic and eukaryotic cells (Alon, 2007). Examples are GTPase cycles, as in the Ras system, phosphorylation cycles, as in MAPK cascades, and two-component systems like the chemotaxis system of Escherichia coli. Push-pull networks constitute a simple exponential filter (Hinczewski and Thirumalai, 2014;Becker et al., 2015), in which the current output depends on the current and past input (with past input values contributing to the output with a weight that decays exponentially with time back into the past). Wiener-Kolmogorov filtering theory (Extrapolation, 1950;Kolmogorov, 1992) shows that these networks are optimal for estimating signals that are memoryless (Becker et al., 2015), meaning that the past input does not contain information that The time-varying ligand concentration is modeled as a memoryless (Markovian) signal with mean L, variance s 2 L , and correlation time t L ¼ l À1 . A free ligand molecule L (light blue circle) can bind at rate k 1 to a free receptor R (magenta protein) on the cell membrane (black line), forming the complex RL, and unbind at rate k 2 from RL. The correlation time of the receptor state is t c . The complex RL catalyzes the phosphorylation reaction, driven by adenosine triphosphate (ATP) conversion, of a downstream readout from the unphosphorylated (inactive) state x to the phosphorylated (active) state x Ã , with rate k f . The phosphorylated readout then spontaneously decays to the x state with rate k r . Microscopic reverse reactions of each signaling pathway are represented by dashed arrows. The relaxation time of the push-pull network is t r . (b) Free-energy landscape of a readout molecule across the activation/deactivation reactions. Fuel turnover, provided by ATP conversion, drives the activation (phosphorylation) reaction characterized by the forward rate k f and its microscopic reverse rate k Àf (green arrows). Associated with this activation reaction is a free-energy drop The deactivation pathway corresponds to the spontaneous release of the inorganic phosphate; it is characterized by the rate k r and its microscopic reverse k Àr (blue arrows) and corresponds to a free-energy drop is not already present in the current input. These networks are useful because they act as low-pass filters, removing the high-frequency receptor-ligand-binding noise (Andrews et al., 2006;Hinczewski and Thirumalai, 2014;Becker et al., 2015). Push-pull networks thus enable the cell to employ the mechanism of time integration, in which the cell infers the concentration not from the instantaneous number of ligand-bound receptors, but rather from the average receptor occupancy over an integration time (Berg and Purcell, 1977). Our theory gives a unified description in terms of all the cellular resources, protein copies, time, and energy, that are necessary to implement this mechanism of time integration. It does not address the sensing strategy of maximum-likelihood estimation (Endres and Wingreen, 2009;Mora and Wingreen, 2010;Lang et al., 2014;Hartich and Seifert, 2016;Ten Wolde et al., 2016) or Bayesian filtering (Mora and Nemenman, 2019). While filtering theories are powerful tools for predicting the optimal topology and response dynamics of the cellular sensing network (Andrews et al., 2006;Hinczewski and Thirumalai, 2014;Becker et al., 2015), they do not naturally reveal the resource requirements for sensing. Our theory therefore employs the sampling framework of Govern and Ten Wolde, 2014a and extends it here to time-varying signals. This framework is based on the observation that the cell estimates the current ligand concentration not from the current number of active readout molecules directly, but rather via the receptor: the cell uses its push-pull network to estimate the receptor occupancy from which the ligand concentration is then inferred (see Figure 2). To elucidate the resource requirements for time integration, the push-pull network is viewed as a device that employs the mechanism of time integration by discretely sampling, rather than continuously integrating, the state of the receptor via collisions of the readout molecules with the receptor proteins (see Figure 2). During each collision, the ligand-binding state of the receptor protein is copied into the activation state of (c) Figure 2. The precision of estimating a time-varying ligand concentration L. (a) The cell estimates the current ligand concentration L ¼ LðtÞ by estimating the average receptor occupancy p t r over the past integration time t r and by inverting the dynamic input-output relation p t r ðLÞ (black solid line). The latter describes the mapping between the current concentration LðtÞ of the time-varying signal and the average receptor occupancy p t r over the past t r , see also (b); it depends on the timescale t L of the input signal and hence differs from the conventional static input-output relation pðL s Þ, which describes the mapping between the average receptor occupancy and a static ligand concentration L s that does not vary in time (gray solid line).
The squared error in the estimate of the concentration ðdLÞ 2 ¼ s 2 pt r =g 2 L!pt r depends on the variance s 2 pt r in the estimate of the average receptor occupancyp t r and the dynamic gaing L!pt r , which is the slope of p t r ðLÞ. Only in the limit t c ; t r ( t L , does p t r ðLÞ reduce to (the linearized form of) pðL s Þ and does the dynamic gaing L!pt r become the static gain g L!p , which is the slope of pðL s Þ at the average ligand concentration L. The input distribution, shown in blue, has width s L . (b) The average receptor occupancy p t r over the past integration time t r is estimated via the downstream network, which is modeled as a device that discretely samples the ligand-binding state of the receptor via its readout molecules x (Govern and Ten Wolde, 2014a); the fraction of modified readout molecules provides an estimate of p t r . The sensing error has two contributions (Equation 6): sampling error and dynamical error. The sampling error arises from the error in the estimate of p t r that is due to the stochasticity of the sampling process; it depends on the number of samples, their independence, and their accuracy. (c) The dynamical error arises because the current ligand concentration LðtÞ is estimated via the average receptor occupancy p t r over the past integration time t r : the latter depends on the ligand concentration in the past t r , which will, in general, deviate from the current concentration. Two different input trajectories (L 1 in blue, L 2 in green) ending at time t at the same value LðtÞ (red dot) lead to different estimates of LðtÞ due to their different average receptor occupancy (p t r ;1 >p t r ;2 ) in the past t r .
the readout molecule (Ouldridge et al., 2017). The readout molecules thus constitute samples of the receptor state, and the fraction of active readout molecules provides an estimate of the average receptor occupancy. The readout activation states have, however, a finite lifetime, which means that this is an estimate of the (running) average receptor occupancy over this lifetime, which indeed sets the receptor integration time t r . The cell can estimate the current ligand concentration L from this estimate of the average receptor occupancy p t r over the past integration time t r because there is a unique one-to-one mapping between p t r and L. This mapping p t r ðLÞ is the dynamic input-output relation and differs from the conventional static input-output relations used to describe the sensing of static concentrations that do not vary on the timescale of the response (Berg and Purcell, 1977;Bialek and Setayeshgar, 2005;Kaizu et al., 2014;Ten Wolde et al., 2016) in that it depends not only on the response time of the system but also on the dynamics of the input signal.
Our theory reveals that the sensing error can be decomposed into two terms, which each depend on collective variables that reveal the resource requirements for sensing. One term, the sampling error, describes the sensing error that arises from the finite accuracy by which the receptor occupancy is estimated. This error depends on the number of receptor samples, as set by the number of receptors, readout molecules, and the integration time; their independence, as given by the receptor-sampling interval and the timescale of the receptor-ligand-binding noise; and their reliability, as determined by how much the system is driven out of thermodynamic equilibrium via fuel turnover. The other term is the dynamical error and is determined by how much the concentration in the past integration time reflects the current concentration that the cell aims to estimate; it depends on the integration time and timescale of the input fluctuations.
Our theory gives a comprehensive view on the optimal design of a cellular sensing system. Firstly, it reveals that the resource allocation principle of Govern and Ten Wolde, 2014a can be generalized to time-varying signals. There exist three fundamental resource classes -receptors and their integration time, readout molecules, and power and integration time -which each fundamentally limit the accuracy of sensing; and, in an optimally designed system, each resource class is equally limiting so that none of them is in excess and thus wasted. However, in contrast to sensing static signals, time cannot be freely traded against the number of receptors and the power to achieve a desired sensing precision: there exists an optimal integration time that maximizes the sensing precision, which arises as a trade-off between the sampling error and dynamical error. Together with the resource allocation principle, it completely specifies, without any adjustable parameters, the optimal design of the system in terms of its resources protein copies, time, and energy.
Our theory also makes a number of specific predictions. The optimal integration time decreases as the number of receptors is increased because this allows for more instantaneous measurements. Moreover, the allocation principle reveals that when the input varies more rapidly both the number of receptors and the power must increase to maintain a desired sensing precision, while the number of readout molecules does not.
Finally, we apply our theory to the chemotaxis system of E. coli. This bacterium searches for food via a run-and-tumble strategy (Berg and Brown, 1972), yielding a fluctuating input signal. In small gradients, the timescale of these input fluctuations is set by the typical run time of the bacterium, which is on the order of a few seconds (Berg and Brown, 1972;Taute et al., 2015), while the strength of these fluctuations is determined by the steepness of the gradient. Interestingly, experiments have revealed that E. coli can sense extremely shallow gradients, with a length scale of approximately 10 4 mm (Shimizu et al., 2010), raising the question how accurately E. coli can measure the concentration and whether this is sufficient to determine whether during a run it has changed, even in these shallow gradients. To measure the concentration, the chemotaxis system employs a push-pull network to filter out the high-frequency receptor-ligand-binding noise (Sartori and Tu, 2011). Applying our theory to this system predicts that the measured integration time, on the order of 100 ms (Sourjik and Berg, 2002), is not only sufficient to enable navigation in these shallow gradients but also necessary. This suggests that this system has evolved to optimally sense shallow concentration gradients.

Theory: model
We consider a single cell that needs to sense a time-varying ligand concentration LðtÞ (see Figure 1a). The ligand concentration dynamics is modeled as a stationary memoryless, or Markovian, signal specified by the mean (total) ligand concentration L, the variance s 2 L , and the correlation time t L ¼ l À1 , which determines the timescale on which input fluctuations decay. It obeys Gaussian statistics (Tostevin and ten Wolde, 2010). The concentration is measured via R T receptor proteins on the cell surface, which independently bind the ligand (Ten Wolde et al., 2016) RL. The correlation time of the receptor state, which is the timescale on which fluctuations in the number of ligand-bound receptors regresses to the mean, is given by t c ¼ 1=ðk 1 L þ k 2 Þ (Berg and Purcell, 1977;Bialek and Setayeshgar, 2005;Kaizu et al., 2014;Ten Wolde et al., 2016). It determines the timescale on which independent concentration measurements can be made. The ligand-binding state of the receptor is read out via a push-pull network (Goldbeter and Koshland, 1981). The most common scheme is phosphorylation fueled by the hydrolysis of adenosine triphosphate (ATP) (see Figure 1b). The receptor, or an enzyme associated with it such as CheA in E. coli, catalyzes the modification of the readout, x þ RL þ ATP * ) x Ã þ RL þ ADP. The active readout proteins x Ã can decay spontaneously or be deactivated by an enzyme, such as CheZ in E. coli, x Ã * ) x þ Pi. Inside the living cell the system is maintained in a non-equilibrium steady state by keeping the concentrations of ATP, adenosine diphosphate (ADP), and inorganic phosphate (Pi) constant. We absorb their concentrations and the activities of the kinase and, if applicable, phosphatase in the (de)phosphorylation rates, coarse-graining the (de)modification reactions into instantaneous second- x. This system has a relaxation time t r ¼ 1=½ðk f þ k Àf ÞRL þ k r þ k Àr (Govern and Ten Wolde, 2014a), which describes how fast fluctuations in x Ã relax. It determines how long x Ã can carry information on the ligand-binding state of the receptor; t r thus sets the integration time of the receptor state.

Theory: inferring concentration from receptor occupancy
The central idea of our theory is illustrated in Figure 2a: the cell employs the push-pull network to estimate the average receptor occupancy p t r over the past integration time t r . It then uses this estimatep t r to infer the current concentration L via the dynamic input-output relation p t r ðLÞ, which provides a one-to-one mapping between p t r and L.

Dynamic input-output relation
The mapping p t r ðLÞ is the dynamic input-output relation. It gives the average receptor occupancy over the past integration time t r , given that the current value of the input signal is L ¼ LðtÞ (see Figure 2a). Here, the average is not only over the noise in receptor-ligand binding and readout activation ( Figure 2b) but also over the subensemble of past input trajectories that each end at the same current concentration L (Figure 2c; Tostevin and ten Wolde, 2010;Hilfinger and Paulsson, 2011;Bowsher et al., 2013). In contrast to the conventional static input-output relation pðL s Þ, which gives the average receptor occupancy p for a steady-state ligand concentration L s that does not vary in time, the dynamic input-output relation takes into account the dynamics of the input and the finite response time of the system. It depends on all timescales in the problem: the timescale of the input, t L , the receptor-ligand correlation time t c , and the integration time t r . Only when

Sensing error
Linearizing the dynamic input-output relation p t r ðLÞ around the mean ligand concentration L (see Figure 2a) and using the rules of error propagation, the expected error in the concentration estimate is (1) Here, s 2 pt r is the variance in the estimatep t r of the average receptor occupancy over the past t r , given that the current input signal is L (see Figure 2a). The quantityg L!pt r is the dynamic gain, which is the slope of the dynamic input-output relation p t r ðLÞ; it determines how much an error in the estimate of p t r propagates to that in L. Equation 1 generalizes the expression for the error in sensing static concentrations (Berg and Purcell, 1977;Bialek and Setayeshgar, 2005;Wang et al., 2007;Mehta and Schwab, 2012;Kaizu et al., 2014;Govern and Ten Wolde, 2014a;Ten Wolde et al., 2016) to that of time-varying concentrations.

Signal-to-noise ratio
Together with the distribution of input states, the sensing error ðdLÞ 2 determines how many distinct signal values the cell can resolve. The latter is quantified by the signal-to-noise ratio (SNR), which is defined as Here, s 2 L is the variance of the ligand concentration LðtÞ; because the system is stationary and time invariant, we can omit the argument in LðtÞ and write L ¼ LðtÞ. The variance s 2 L is a measure for the total number of input states, such that the SNR gives the number of distinct ligand concentrations the cell can measure. Using Equation 1, it is given by The SNR also yields the mutual information Iðx Ã ; LÞ ¼ 1=2 lnð1 þ SNRÞ between the input L and output x Ã (Tostevin and ten Wolde, 2010).

Readout system samples receptor state
Receptor time averaging is typically conceived as a scheme in which the receptor state is averaged via the mathematical operation of an integral: p t r ¼ 1=t r R t r 0 pðt 0 Þdt 0 . Yet, readout proteins are discrete components that interact with the receptor in a discrete and stochastic fashion. To derive the dynamic gaing L!pt r and error in estimating p t r , s 2 pt r (Equation 3), we therefore view the push-pull network as a device that discretely samples the receptor state (see Figure 2b; Govern and Ten Wolde, 2014a). The principle is that cells employ the activation reaction x þ RL ! x Ã þ RL to store the state of the receptor in stable chemical modification states of the readout molecules. Readout molecules that collide with a ligand-bound receptor are modified, while those that collide with an unbound receptor are not ( Figure 2b). The readout molecules serve as samples of the receptor at the time they were created, and collectively they encode the history of the receptor: the fraction of samples that correspond to ligand-bound receptors is the cell's estimate for p t r . Indeed, this is the discrete and stochastic implementation of the mechanism of time integration. The effective number of independent samples depends not only on the creation of samples, x þ RL ! x Ã þ RL, but also on their decay and accuracy. Samples decay via the deactivation reaction x Ã ! x, which means that they only provide information on the receptor occupancy over the past t r . In addition, both the activation and the deactivation reaction can happen in their microscopic reverse direction, which corrupts the coding, that is, the mapping between the ligand-binding states of the receptor proteins and the activation states of the readout molecules. Energy is needed to break time reversibility and protect the coding. Furthermore, for time-varying signals, we also need to recognize that the samples correspond to the ligand concentration over the past integration time t r , which will in general differ from the current concentration L that the cell aims to estimate (see Figure 2c). While a finite t r is necessary for time integration, it will, as we show below, also lead to a systematic error in the estimate of the concentration that the cell cannot reduce by taking more receptor samples.
This analysis reveals that the dynamic gain is (see Appendix 1) Only when t L ) t r ; t c is the average ligand concentration over the ensemble of trajectories ending at dLðtÞ equal to the current concentration dLðtÞ ( Figure 2c) and doesg L!pt r become equal to its maximal value, the static gain g L!p ¼ pð1 À pÞ=L, where p is the average receptor occupancy averaged over all values of dLðtÞ. The analysis also reveals that the error in p t r can be written as (see Appendix 1, Equation 29) where s 2; samp pt r is a statistical error due to the stochastic sampling of the receptor and s 2; dyn pt r is a systematic error arising from the dynamics of the input, as elucidated in Figure 2b, c.

Central result
To know how the error s 2 pt r in the estimate of p t r propagates to the error ðdLÞ 2 in the estimate of the current ligand concentration, we divide s 2 pt r by the dynamic gaing L!pt r given by Equation 4 (see Equation 1). For the full system, the reversible push-pull network, this yields via Equation 3 the central result of our article, the SNR in terms of the total number of receptor samples, their independence, their accuracy, and the timescale on which they are generated: This expression shows that the sensing error SNR À1 can be decomposed into two distinct contributions, which each have a clear interpretation: the sampling error, arising from the stochasticity in the sampling of the receptor state, and the dynamical error, arising from the dynamics of the input.
When the timescale of the ligand fluctuations t L is much longer than the receptor correlation time t c and the integration time t r , t L ) t r ; t c , the dynamical error reduces to zero and only the sampling error remains. Here, N eff is the total number of effective samples and N I is the number of these that are independent (Govern and Ten Wolde, 2014a). For the full system, they are given by The quantity _ n ¼ k f pR T x À k Àf pR T x Ã is the net flux of x around the cycle of activation and deactivation, with R T the total number of receptor proteins and x and x Ã the average number of inactive and active readout molecules, respectively. It equals the rate at which x is modified by the ligand-bound receptor; the quantity _ n=p is thus the sampling rate of the receptor, be it ligand bound or not. Multiplied with the relaxation rate t r , it yields the total number of receptor samples N obtained during t r . However, not all these samples are reliable. The effective number of samples is N eff ¼ qN, where 0<q<1 quantifies the quality of the sample. Here, b ¼ 1=ðk B TÞ is the inverse temperature, D 1 and D 2 are the free-energy drops over the activation and deactivation reaction, respectively, with D ¼ D 1 þ D 2 the total drop, determined by the fuel turnover (see Figure 1b). If the system is in thermodynamic equilibrium, D 1 ¼ D 2 ¼ D ¼ 0, q ! 0 and the system cannot sense because the ligand-binding state of the receptor is equally likely to be copied into the correct modification state of the readout as into the incorrect one. In contrast, if the system is strongly driven out of equilibrium and D 1 ; D 2 ! ¥, then, during each receptor-readout interaction, the receptor state is always copied into the correct activation state of the readout; the sample quality parameter q thus approaches unity and N eff ! N. Yet, even when all samples are reliable, they may contain redundant information on the receptor state. The factor f I is the fraction of the N eff samples that are independent. It reaches unity when the receptor sampling interval D ¼ 2t r =ðN eff =R T Þ becomes larger than the receptor correlation time t c .
When the number of samples becomes very large, N I ; N eff ! ¥, the sampling error reduces to zero. However, the sensing error still contains a second contribution, which, following Bowsher et al., 2013, we call the dynamical error. This contribution only depends on timescales. It arises from the fact that the samples encode the receptor history and hence the ligand concentration over the past t r , which will, in general, deviate from the quantity that the cell aims to predict -the current concentration L. This contribution yields a systematic error, which cannot be eliminated by increasing the number of receptor samples, their independence, or their accuracy. It can only be reduced to zero by making the integration time t r much smaller than the ligand timescale t L (assuming t c is typically much smaller than t r ; t L ). Only in this regime will the ligand concentration in the past t r be similar to the current concentration and can the latter be reliably inferred from the receptor occupancy, provided the latter has been estimated accurately by taking enough samples.
Importantly, the dynamics of the input signal not only affects the sensing precision via the dynamical error but also via the sampling error. This effect is contained in the prefactor of the sampling error, ð1 þ t c =t L Þ 2 ð1 þ t r =t L Þ 2 , which has its origin in the dynamic gaing L!pt r (Equation 4). It determines how the sampling error s 2;samp pt r in the estimate of p t r propagates to the error in the estimate of L (see Equation 3). Only when t c ; t r ( t L can the readout system closely track the input signal and doesg L!pt r reach its maximal value, the static gain g L!p , thus minimizing the error propagation from p t r to L.

Fundamental resources
We can use Equation 6 to identify the fundamental resources for cell sensing (Govern and Ten Wolde, 2014a) and derive Pareto fronts that quantify the trade-offs between the maximal sensing precision and these resources. A fundamental resource is a (collective) variable Q i that, when fixed to a constant, puts a non-zero lower bound on SNR À1 , no matter how the other variables are varied.
It is thus mathematically defined as MIN Qi¼const SNR À1 À Á ¼ f ðconstÞ>0: To find these collective variables, we numerically or analytically minimized SNR À1 , constraining (combinations of) variables yet optimizing over the other variables. This reveals that the SNR is bounded by (see Appendix 2) Equations 8 and 9 show that the fundamental resources are the number of receptors R T , the integration time t r , the number of readouts X T , and the power _ w ¼ _ nD. Figure 3a, b illustrates that R T ; t r ; X T ; _ w are indeed fundamental: the sensing precision is bounded by the limiting resource and cannot be enhanced by increasing another resource. Panel (a) shows that when X T is small, the maximum mutual information I max cannot be increased by raising R T : no matter how many receptors the system has, the sensing precision is limited by the pool of readout molecules and only increasing this pool can raise I max . Yet, when X T is large, I max becomes independent of X T . In this regime, the number of receptors R T limits the number of independent concentration measurements and only increasing R T can raise I max . Similarly, panel (b) shows that when the power _ w is limiting, I max cannot be increased by R T but only by increasing _ w. Clearly, the resources receptors, readout molecules, and energy cannot compensate each other: the sensing precision is bounded by the limiting resource.
Importantly, while for sensing static concentrations the products R T t r =t c and _ wt r are fundamental (Govern and Ten Wolde, 2014a), for time-varying signals R T , _ w, and t r separately limit sensing. Consequently, neither receptors R T nor power _ w can be traded freely against time t r to reach a desired precision, as is possible for static signals. In line with the predictions of signal filtering theories (Extrapolation, 1950;Kolmogorov, 1992;Kalman, 1960), there exists an optimal integration time t r opt that maximizes the sensing precision (Andrews et al., 2006;Hinczewski and Thirumalai, 2014;Becker et al., 2015;Monti et al., 2018b;Mora and Nemenman, 2019). Interestingly, its value depends on which of the resources R T , X T , and _ w is limiting (Figure 3c-f). We now discuss these three regimes in turn. Berg and Purcell, 1977 pointed out that cells can reduce the sensing error by either increasing the number of receptors or taking more measurements per receptor via the mechanism of time integration. However, Equation 8 reveals that for sensing time-varying signals time integration can never eliminate the sensing error completely, as predicted also by filtering theories (Extrapolation, 1950;Kolmogorov, 1992;Kalman, 1960). Equation 8 shows that in the Berg-Purcell regime, where receptors and their integration time are limiting and h ¼ R T t r =t c , the sensing precision does not depend on R T t r =t c , as for static signals (Govern and Ten Wolde, 2014a), but on R T and t r separately, such that an optimal integration time t r opt emerges that maximizes the sensing precision (see Figure 3c). Increasing t r improves the mechanism of time integration by increasing the number of . Receptors R T , readout molecules X T , and _ w fundamentally limit sensing, and there exists an optimal integration time t r that depends on which of the resources is limiting. (a, b) R T , X T , and _ w are fundamental resources, with no trade-offs between them. Plotted is the maximum mutual information I max ¼ 1=2 lnð1 þ SNR max Þ, obtained by minimizing Equation 6 over p and t r , for different combinations of (a) X T and R T in the irreversible limit q ! 1 and (b) _ w and R T for two different values of D. The sensing precision is bounded by the limiting resource, R T (solid gray lines, Equation

Receptors
(c) I max as a function of t r for different values of R T in the Berg-Purcell limit (q ! 1 and X T ! ¥). There exists an optimal integration time t r opt that maximizes the sensing precision; t r opt decreases with R T . (d) In this limit, t r opt depends non-monotonically on the receptor-ligand correlation time t c : it first increases with t c to sustain time-averaging, but then drops when t r opt =t c becomes of order unity and time-averaging is no longer effective (see inset). (e) t r opt as a function of X T for different values of R T . When X T <R T , time averaging is not possible and the optimal system is an instantaneous responder, t r opt ! 0; when X T ) R T , the system reaches the Berg-Purcell regime in which I max is limited by R T rather than X T (see panel a). (f) t r opt and X T as a function of _ w. When the power _ w~X T =t r is limiting, the sampling error dominates and t r opt equals t L to maximize X T , minimizing the sampling error; t r opt then decreases to trade part of the decrease in the sampling error for a reduction in the dynamical error such that both decrease; when the sampling interval D~t r R T =X T becomes comparable to t c , in the region marked by the yellow bar, the sampling error is no longer limited by X T , such that t r now limits both sources of error; the two sources can therefore no longer be decreased simultaneously by increasing _ w~X T =t r ; the system has entered the Berg-Purcell regime, where t r opt is determined by R T rather than _ w (see panel b). Parameter values unless specified: t c =t L ¼ 10 À2 ; s L =L T ¼ 10 À2 . independent samples per receptor, t r =t c , thus reducing the sampling error (Equation 6). However, increasing t r raises the dynamical error. Moreover, it lowers the dynamical gaing L!pt r , which increases the propagation of the error in the estimate of the receptor occupancy to that of the ligand concentration. The optimal integration time t r opt arises as a trade-off between these three factors. Figure 3c also shows that the optimal integration time t r opt decreases with the number of receptors R T . The total number of independent concentration measurements is the number of independent measurements per receptor, t r =t c , times the number R T of receptors, N I ¼ R T t r =t c . As R T increases, less measurements t r =t c per receptor have to be taken to remove the receptor-ligandbinding noise, explaining why t r opt decreases as R T increases -time integration becomes less important.
Interestingly, t r opt depends non-monotonically on the receptor-ligand correlation time t c (Figure 3d). When t c increases at fixed t r , the receptor samples become more correlated. To keep the mechanism of time integration effective, t r must increase with t c . However, to avoid too strong signal distortion the cell compromises on time integration by decreasing the ratio t r =t c (see inset). When t r becomes too large, the benefit of time integration no longer pays off the cost of signal distortion. Now not only the ratio t r =t c decreases but also t r itself. The sensing system switches to a different strategy: it no longer employs time integration but becomes an instantaneous sensor.

Readout molecules
To implement time integration, the cell needs to store the receptor states in the readout molecules. When the number of readout molecules X T is limiting, the sensing precision is given by Equation 8 with h ¼ X T . This bound is saturated when t r ! 0. This is in marked contrast to the non-zero optimal integration t r opt in the Berg-Purcell regime (see Figure 3c).
To elucidate the non-trivial behavior of t r opt , Figure 3e shows t r opt as a function of X T . When X T is smaller than R T , the average number of samples per receptor is less than unity. In this regime, the system cannot time integrate the receptor, and to minimize signal distortion t r opt » 0. Yet, when X T is increased, the likelihood that two or more readout molecules provide a sample of the same receptor molecule rises, and time averaging becomes possible. Yet to obtain receptor samples that are independent, the integration time t r must be increased to make the sampling interval D~t r R T =X T larger than the receptor correlation time t c . As X T and hence the total number of samples N are increased further, the number of samples that are independent, N I , only continues to rise when t r increases with X T further. However, while this reduces the sampling error, it also increases the dynamical error. When the decrease in the sampling error no longer outweighs the increase in the dynamical error, t r opt and the mutual information no longer change with X T (see Figure 3a). The system has entered the Berg-Purcell regime in which t r opt and the mutual information are given by the optimization of Equation 8 with h ¼ R T t r =t c (gray dashed line). In this regime, increasing X T merely adds redundant samples: the number of independent samples remains N I ¼ R T t r opt =t c .

Power
Time integration relies on copying the ligand-binding state of the receptor into the chemical modification states of the readout molecules (Mehta and Schwab, 2012;Govern and Ten Wolde, 2014a). This copy process correlates the state of the receptor with that of the readout, which requires work input (Ouldridge et al., 2017).
The free-energy D provided by the fuel turnover drives the readout around the cycle of modification and demodification (Figure 1). The rate at which the fuel molecules do work is the power _ w ¼ _ nD, and the total work performed during the integration time t r is w _ wt r . This work is spent on taking samples of receptor molecules that are bound to ligand because only they can modify the readout. The total number of effective samples of ligand-bound receptors during t r is pN eff (Equation 7), which means that the work per effective sample of a ligand-bound receptor is w=ðpN eff Þ ¼ D=q (Govern and Ten Wolde, 2014a).
To understand how energy limits the sensing precision, we can distinguish between two limiting regimes (Govern and Ten Wolde, 2014a). When D>4k B T, the quality parameter q ! 1 (Equation 7) and the work per sample of a ligand-bound receptor is w=ðpN eff Þ ¼ D (Govern and Ten Wolde, 2014a). In this irreversible regime, the SNR bound is given by Equation 8 with h ¼ _ wt r =ðD=4Þ. The power limits the sensing accuracy not because it limits the reliability of each sample but because it limits the rate _ n ¼ _ w=D at which the receptor is sampled. When D<4k B T, the system enters the quasi-equilibrium regime in which the quality parameter q ! bD=4 (see Equation 7, noting that in the optimal system D 1 ¼ D 2 ¼ D=2). The sensing bound is now given by Equation 8 with h ¼ b _ wt r , which is larger than h ¼ _ wt r =ðD=4Þ in the irreversible regime (where D>4k B T). The quasi-equilibrium regime minimizes the sensing error for a given power constraint (Figure 3b) because this regime maximizes the number of effective measurements per work input pN eff =w ¼ q=D ¼ b=4 (Govern and Ten Wolde, 2014a).
While the sensing precision for a given power and time constraint is higher in the quasi-reversible regime, more readout molecules are required to store the concentration measurements in this regime. Noting that the flux _ n ¼ f ð1 À f ÞX T q=t r ¼ _ w=D, it follows that in the irreversible regime (q ! 1) the number of readout molecules consuming energy at a rate _ w is while in the quasi-equilibrium regime (q ! D=4) it is Since in the quasi-equilibrium regime D<4k B T, X qeq T >X irr T . Equation 8 shows that the sensing precision is fundamentally bounded not by the work w ¼ _ wt r , as observed for static signals (Govern and Ten Wolde, 2014a), but rather by the power _ w and the integration time t r separately such that an optimal integration time t r opt emerges. Figure 3f shows how t r opt depends on _ w. Since the system cannot sense without any readout molecules, in the lowpower regime the system maximizes X T subject to the power constraint _ w~X T =t r (see Equations 10 and 11) by making t r as large as possible, which is the signal correlation time t L -increasing t r opt further would average out the signal itself. As _ w is increased, X T rises and the sampling error decreases. When the sampling error becomes comparable to the dynamical error (Equation 6), the system starts to trade a further reduction in the sampling error for a reduction in the dynamical error by decreasing t r opt . The sampling error and dynamical error are now reduced simultaneously by increasing X T and decreasing t r opt . This continues until the sampling interval D~R T t r =X T becomes comparable to the receptor correlation time t c , as marked by the yellow bar. Beyond this point, D<t c and the sampling error is no longer limited by X T but rather by t r since t r bounds the number of independent samples per receptor, t r =t c . The system has entered the Berg-Purcell regime, where t r opt is determined by the trade-off between the dynamical error and the sampling error as set by the maximum number of independent samples, R T t r =t c (Figure 3c).

Optimal design
In sensing time-varying signals, a trade-off between time averaging and signal tracking is inevitable. Moreover, the optimal integration time depends on which resource is limiting, being zero when X T is limiting and finite when R T or _ w is limiting (Figure 3). It is therefore not obvious whether these sensing systems still obey the optimal resource allocation principle as observed for systems sensing static concentrations (Govern and Ten Wolde, 2014a).
However, Equation 8 shows that when for a given integration time t r , R T t r =t c ¼ X T ¼ b _ wt r , the bounds on the sensing precision as set by, respectively, the number of receptors R T , the number of readout molecules X T , and the power _ w are equal. Each of these resources is then equally limiting sensing and no resource is in excess. We thus recover the optimal resource allocation principle: Irrespective of whether the concentration fluctuates in time, the number of independent concentration measurements at the receptor level is R T t r =t c , which in an optimally designed system also equals the number of readout molecules X T and the energy b _ wt r that are both necessary and sufficient to store these measurements reliably.
The design principle X T » b _ wt r (Equation 12) predicts that there exists a driving force D opt that optimizes the trade-off between the number of samples and their accuracy. Noting that b _ wt r ¼ b _ nDt r ¼ bqf ð1 À f ÞX T D reveals that the principle X T » b _ wt r (Equation 12) specifies D for the optimal system in which f ! 1=2 and D 1 ¼ D 2 ¼ D=2 via the equation qðD opt Þ ¼ 4k B T=D opt , where qðDÞ is defined in Equation 7. A numerical inspection shows that to a good approximation the solution of this equation is precisely given by the crossover from the quasi-equilibrium regime to the irreversible one: D opt » 4k B T. This can be understood by noting that in the quasi-equilibrium regime X T can, for a given power and time constraint, be reduced by increasing D (Equation 11) without compromising the sensing precision (Equation 8 with h ¼ _ wt r ); in this regime, increasing D increases the reliability of each sample, and a smaller number of more reliable samples precisely compensates for a larger number of less reliable ones. Yet, when D becomes larger than 4k B T, the system enters the irreversible regime. Here, X T corresponding to a given _ w and t r constraint still decreases with D (Equation 10), but the sensing error now increases (Equation 8 with h ¼ _ wt r =ðD=4Þ) because each sample has become (essentially) perfect in this regime -hence, the samples' accuracy cannot (sufficiently) increase further to compensate for the reduction in the sampling rate _ n~X T =t r . Equation 12 holds for any integration time t r , yet it does not specify t r . The cell membrane is highly crowded, and many systems employ time integration (Berg and Purcell, 1977;Bialek and Setayeshgar, 2005;Govern and Ten Wolde, 2014a). This suggests that these systems employ time integration and accept the signal distortion that comes with it simply because there is not enough space on the membrane to increase R T . Our theory then allows us to predict the optimal integration time t r opt based on the premise that R T is limiting. As Equation 8 reveals, in this limit t r opt does not only depend on R T but also on t c , t L , and s L =L : t opt r ¼ t opt r ðR T ; t r ; t L ; s L =LÞ. The optimal design of the system is then given by Equation 12 but with t r given by t r opt ¼ t r opt ðR T ; t c ; t L ; s L =LÞ: This design principle maximizes for a given number of receptors R T the sensing precision and minimizes the number of readout molecules X T and power _ w needed to reach that precision.

Comparison with experiment
To test our theory, we turn to the chemotaxis system of E. coli. This system contains a receptor that forms a complex with the kinase CheA. This complex, which is coarse-grained into R (Govern and Ten Wolde, 2014a), can bind the ligand L and activate the intracellular messenger protein CheY (x) by phosphorylating it. Deactivation of CheY is catalyzed by CheZ, the effect of which is coarsegrained into the deactivation rate. This push-pull network allows E. coli to measure the current concentration, and the relaxation time of this network sets the integration time for the receptor (Sartori and Tu, 2011). The system also exhibits adaptation on longer timescales due to receptor methylation and demethylation. The push-pull network and the adaptation system together allow the cell to measure concentration gradients via a temporal derivative, taking the difference between the current concentration and the past concentration as set by the adaptation time (Segall et al., 1986). A lower bound for the error in the estimate of this difference is given by the error in the estimate of the current concentration, the central quantity of our theory. Here, we ask how accurately E. coli can estimate the latter and whether the sensing precision is sufficient to determine whether during a run the concentration has changed. Our theory predicts that if the number of receptors is limiting then the optimal integration time t r opt ðR T ; t c ; t L ; s L =LÞ is given by minimizing Equation 8 with h ¼ R T t r =t c . The number of receptor-CheA complexes depends on the growth rate and varies between R T » 10 3 and R T » 10 4 (Li and Hazelbauer, 2004). The receptor correlation time for the binding of aspartate to the Tar receptor can be estimated from the measured dissociation constant (Vaknin and Berg, 2007) and the association rate (Danielson et al., 1994), t c » 10ms (Govern and Ten Wolde, 2014a). The timescale t L of the input fluctuations is set by the typical run time, which is on the order of a few seconds, t L » 1s (Berg and Brown, 1972;Taute et al., 2015).
This leaves one parameter to be determined, ðs L =LÞ 2 . This is set by the spatial ligand-concentration profile and the typical length of a run. We have a good estimate of the latter. In shallow gradients, it is on the order of l » 50m (Berg and Brown, 1972;Taute et al., 2015;Jiang et al., 2010;Flores et al., 2012); specifically, Figure 4 of Taute et al., 2015 shows that the typical run times are 1-2 s while the typical run speeds are 20 À 60ms À1 , yielding a run length on the order of indeed 50 mm. We do not know the spatial concentration profiles that E. coli has experienced during its evolution. We can however get a sense of the scale by considering an exponential ligand-concentration gradient. For a profile LðxÞ ¼ L 0 e x=x0 with length scale x 0 , the relative change in the signal over the length of a run is s L =L ' ðdL=dxÞl=L ¼ l=x 0 . We consider the range s L =L » l=x 0 <1, where s L =L<0:1 corresponds to shallow gradients with x 0 > 500m in which cells move with a constant drift velocity (Shimizu et al., 2010;Flores et al., 2012). Figure 4a shows that as the gradient becomes steeper and s L =L » l=x 0 increases the optimal integration time t r opt decreases. This can be understood by noting that the relative importance of the dynamical error compared to the sampling error scales with s L =L À Á 2 (Equation 6). Shallow ingredients thus allow for a larger integration time while steep gradients necessitate a shorter one. Experiments indicate that the relaxation rate of CheY is t r À1 » 2s À1 for the attractant response and » 20s À1 for the repellent response (Sourjik and Berg, 2002), such that the integration time t r » 50 À 500ms (Sourjik and Berg, 2002;Govern and Ten Wolde, 2014a). Figure 4a shows that this integration time is optimal for detecting shallow gradients. Our theory thus predicts that the E. coli chemotaxis system has been optimized for sensing shallow gradients.
To navigate, the cells must be able to resolve the signal change over a run. During a run of duration t L , the system performs t L =t r independent concentration measurements. The effective error for these measurements is the instantaneous sensing error ðdLÞ 2 divided by the number of independent measurements t L =t r : ðdLÞ 2 =ðt L =t rÞ. Hence, the SNR for these concentration measurements is SNR t L ðs L =dLÞ 2 t L =t r .   8 with h ¼ R T t r =t c , as a function of the relative strength of the input noise, s L =L, for two different copy numbers R T of the receptor-CheA complexes; for an exponential gradient with length scale x 0 , the relative noise strength s L =L ' l=x 0 , where l » 50m is the run length of E. coli. It is seen that t r opt increases as s L =L decreases because the relative importance of the sampling error compared to the dynamical error increases. The figure also shows that t r opt decreases as R T is increased because that allows for more instantaneous measurements (see also Figure 3). The red bar indicates the range of the estimated integration time of E. coli, 50ms<t r <500ms, based on its attractant and repellent response, respectively (Sourjik and Berg, 2002), divided by the input timescale t L » 1s based on its typical run time of about a second (Berg and Brown, 1972;Taute et al., 2015). The panel indicates that E. coli has been optimized to detect shallow concentration gradients. (b) The signal-to-noise ratio SNR t L ¼ ðs L =dLÞ 2 t L =t r , with ðs L =dLÞ 2 ¼ SNR given by Equation 6, as a function of s L =L ' l=x 0 . To be able to detect the gradient, the SNR t L must exceed unity. The panel shows that the shallowest gradient that E. coli can detect (marked with dashed red line) has, for R T ¼ 10 4 , a length scale of x 0 » 25000m (corresponding to s L =L » 2 Â 10 À3 ), which is consistent with experiments based on ramp responses (Shimizu et al., 2010). Other parameter: receptor-ligand-binding correlation time t c ¼ 10ms (Vaknin and Berg, 2007;Danielson et al., 1994). Figure 4b shows that our theory predicts that when R T ¼ 10 3 , the shallowest gradient that cells can resolve, defined by SNR t L ¼ 1, is l=x 0 » s L =L » 1 Â 10 À2 , corresponding to x 0 » 7500m, while when R T ¼ 10 4 , l=x 0 » 2 Â 10 À3 and x 0 » 25000m. The shallowest gradient is thus on the order of x 0 » 10 4 m. Shimizu et al., 2010 show that E. coli cells are indeed able to sense such very shallow gradients: Figure 2A of Shimizu et al., 2010 shows that E. coli cells can detect exponential up ramps with rate r ¼ 0:001=s; using r ¼ v r =x 0 , where v r » 10m=s is the run speed (Jiang et al., 2010), this corresponds to x 0 » 10 4 m. Importantly, the predictions of our theory (Figure 4) concern the shallowest gradient that the system with the optimal integration time can resolve. These observations indicate that the optimal integration time is not only sufficient to make navigation in these very shallow gradients possible but also necessary. Figure 4 also shows that t r opt decreases as the number of receptor-CheA complex, R T , increases because the latter allows for more instantaneous measurements, reducing the need for time integration ( Figure 3c). Interestingly, the data of Li and Hazelbauer, 2004 shows that the copy numbers of the chemotaxis proteins vary with the growth rate. Clearly, it would be of interest to directly measure the response time in different strains under different growth conditions.

Discussion
Here, we have integrated ideas from Tostevin and ten Wolde, 2010; Hilfinger and Paulsson, 2011;and Bowsher et al., 2013 on information transmission via time-varying signals with the sampling framework of Govern and Ten Wolde, 2014a to develop a unified theory of cellular sensing. The theory is founded on the concept of the dynamic input-output relation p t r ðLÞ. It allows us to develop the idea that the cell employs the readout system to estimate the average receptor occupancy p t r over the past integration time t r and then exploits the mapping p t r ðLÞ to estimate the current ligand concentration L from p t r . The theory reveals that the error in the estimate of L depends on how accurately the cell samples the receptor state to estimate p t r , and on how much p t r , which is determined by the concentration in the past t r , reflects the current ligand concentration. These two distinct sources of error give rise to the sampling error and dynamical error in Equation 6, respectively.
While the system contains no less than 11 parameters, Equation 6 provides an intuitive expression for the sensing error in terms of collective variables that have a clear interpretation. The dynamical error depends only on the timescales in the problem, most notably t r =t L . The sampling error depends on how accurately the readout system estimates p t r , which is determined by the number of receptor samples, their independence, and their accuracy; yet it also depends on t r =t L via the dynamic gain, which determines how the error in the estimate of p t r propagates to that of L. The trade-off between the sampling error and dynamical error yields an optimal integration time.
Our study reveals that the optimal integration time t r opt depends in a non-trivial manner on the design of the system. When the number of readout molecules X T is smaller than the number of receptors R T , time integration is not possible and the optimal system is an instantaneous responder with t r opt » 0. When the power _ w~X T =t r , rather than X T , is limiting, t r opt is determined by the trade-off between the sampling error and dynamical error. In both scenarios, however, one resource, X T or _ w, is limiting the sensing precision. In an optimally designed system, all resources are equally limiting so that no resource is wasted. This yields the resource allocation principle (Equation 12), first identified in Govern and Ten Wolde, 2014a, for sensing static concentrations. The reason it can be generalized to time-varying signals is that the principle concerns the optimal design of the readout system for estimating the receptor occupancy over a given integration time t r , which holds for any type of input: the number of independent concentration measurements at the receptor level is R T t r =t c , irrespective of how the input varies, and in an optimally designed system this also equals the number of readout molecules X T and energy b _ wt r to store these measurements reliably. We thus expect that the design principle also holds for systems that sense signals that vary more strongly in time (Mora and Nemenman, 2019).
While the allocation principle Equation 12 holds for any t r , it does not specify the optimal integration time t r opt . However, our theory predicts that if the number of receptors R T is limiting, then there exists a t r opt that maximizes the sensing precision for that R T (Equation 8 with h ¼ R T t r =t c ). Via the allocation principle Equation 13, R T and t r opt then together determine the minimal number of readout molecules X T and power _ w to reach that precision. The resource allocation principle, together with the optimal integration time, thus completely specifies the optimal design of the sensing system.
Applying our theory to the E. coli chemotaxis system shows that this system not only obeys the resource allocation principle (Govern and Ten Wolde, 2014a) but also that the predicted optimal integration time to measure shallow gradients is in agreement with that measured experimentally (Figure 4a). This is remarkable because there is not a single fit parameter in our theory. Moreover, Figure 4b shows that the optimal integration time is not only sufficient to enable the sensing of these shallow gradients but also necessary. This is interesting because the sensing precision could also be increased by increasing the number of receptors, readout molecules, and energy devoted to sensing -but this would be costly. Our results thus demonstrate not only that the chemotaxis system obeys the design principles as revealed by our theory but also that there is a strong selection pressure to design sensing systems optimally, that is, to maximize the sensing precision given the resource constraints.
Our theory is based on a Gaussian model and describes the optimal sensing system that minimizes the mean square error in the estimate of the ligand concentration (see Equation 1). The latter is precisely the performance criterion of Wiener-Kolmogorov (Extrapolation, 1950;Kolmogorov, 1992) and Kalman, 1960 filtering theory, which, moreover, become exact for systems that obey Gaussian statistics. In fact, since our system (including the input signal) is stationary, they predict the same optimal filter, which is an exponential filter for signals that are memoryless. The signals studied here belong to this class, and the push-pull network forms an exponential filter (Hinczewski and Thirumalai, 2014;Becker et al., 2015). This underscores the idea that our theory gives a complete description, in terms of all the required resources, for the optimal design of cellular sensing systems that need to estimate this type of signals. Furthermore, because our model is Gaussian, the goal of minimizing the mean-square error in the estimate of the input signal is equivalent to maximizing the mutual information between the input (the ligand concentration) and the output (the readout x Ã ) (Becker et al., 2015).
In recent years, filtering theories and information theory have been applied increasingly to neuronal and cellular systems (Laughlin, 1981;Brenner et al., 2000;Fairhall et al., 2001;Andrews et al., 2006;Ziv et al., 2007;Nemenman et al., 2008;Cheong et al., 2011;Nemenman, 2012;Hinczewski and Thirumalai, 2014;Becker et al., 2015;Husain et al., 2019;Tkacik et al., 2008;Tkacˇik and Walczak, 2011;Dubuis et al., 2013;Monti and Wolde, 2016;Monti et al., 2018a). A key concept in these theories is that optimal sensing systems match the response to the statistics of the input. When the noise is weak, maximizing the entropy of the output distribution becomes paramount, which entails matching the shape of the input-output relation to the shape of the input distribution to generate a flat output distribution (Laughlin, 1981;Tkacik et al., 2008;Monti et al., 2018a). Yet, when the noise is large, the optimal response is also shaped by the requirement to tame the propagation of noise in the input signal (Andrews et al., 2006;Hinczewski and Thirumalai, 2014;Becker et al., 2015;Monti et al., 2018a;Monti et al., 2018b;Mora and Nemenman, 2019) or to lift the signal above the intrinsic noise in the response system (Tostevin and ten Wolde, 2010;Bowsher et al., 2013). In Appendix 3, we show that estimating the concentration from p t r is equivalent to that via readout x Ã . This makes it possible to connect our sampling framework, which is based on p t r ðLÞ, to filtering and information theory, which are based on x Ã ðLÞ. In particular, we show in this appendix how the optimal integration and dynamic gain can be understood from these ideas on matching the response to the input. We also briefly discuss in Appendix 3 the concepts from information theory that are beyond the scope of the Gaussian model considered here.
Yet, our discrete sampling framework gives a detailed description of how the optimal design of sensing systems depends on the statistics of the input signal in terms of all the required cellular resources: protein copies, time, and energy. In an optimal system, each receptor is sampled once every receptor-ligand correlation time t c , D » t c , and the number of samples per receptor is t r opt =D » t r opt =t c . The optimal integration time t r opt for a given R T is determined by the trade-off between the age of the samples and the number required for averaging the receptor state. When the input varies more rapidly, the samples need to be refreshed more regularly: to keep the dynamical error and the dynamic gain constant, t r opt must decrease linearly with t L (see Equation 6). Yet, only decreasing t r opt would inevitably increase the sampling error s 2;samp pt r in estimating the receptor occupancy because the sampling interval D~R T t r opt =X opt T would become smaller than t c , creating redundant samples. To keep the sensing precision constant, the number of receptors R T needs to be raised with t L À1 , such that the sampling interval D~R T t r opt =X opt T remains of order t c and the decrease in the number of samples per receptor, t r opt =t c , is precisely compensated for by the increase in R T . The total number of independent concentration measurements, R T t r opt =t c , and hence the number of readout molecules X opt T to store these, does indeed not change. In contrast, the required power b _ w opt » R T =t c rises (Equation 12): each receptor molecule is sampled each t c at D opt » 4k B T, and the increase in R T raises the sampling rate _ n ¼ _ w opt =D opt~X opt T =t r opt . Our theory thus predicts that when the input varies more rapidly the number of receptors and the power must rise to maintain a required sensing precision, while the number of readout molecules does not.
The fitness benefit of a sensing system does not only depend on the sensing precision but also on the energetic cost of maintaining and running the system. In principle, the cell can reduce the sensing error arbitrarily by increasing R T and decreasing t r . Our resource allocation principle (Equation 12) shows that then not only the number of readout molecules needs to be raised but also the power. Clearly, improving the sensing precision comes at a cost: more copies of the components of the sensing system need to be synthesized every cell cycle, and more energy is needed to run the system. Our theory (i.e., Equation 6) makes it possible to derive the Pareto front that quantifies the trade-off between the maximal sensing precision and the cost of making the sensing system (see Figure 5). Importantly, the design of the optimal system at the Pareto front obeys, to a good approximation, our resource allocation principle (Equation 12). This is because this principle specifies the optimal ratios of R T , X T , _ w, and t r given the input statistics, and these ratios are fairly  Figure 5. The benefit of a sensing system depends on the sensing precision it can achieve and the cost of making it. The Pareto front characterizes the trade-off between the maximal sensing precision, quantified by the maximal mutual information I max ðx Ã ; LÞ, and the cost of making the sensing system, C ¼ R T þ c X X T , where c X is the relative cost of making a readout versus a receptor protein, here taken to be c X ¼ 1. System designs below the Pareto front are suboptimal and can be improved by reducing the cost, that is, the number of proteins, and / or increasing the sensing precision. The optimal systems at the Pareto front obey, to a good approximation, the allocation principle Equation 12. The Pareto front, formed by the maximal value I max ðx Ã ; LÞ of Iðx Ã ; LÞ ¼ 1=2 lnð1 þ SNRÞ as a function of C, is obtained by minimizing Equation 6 over p; t r ; R T ; X T subject to the constraint C ¼ R T þ X T ; the quality parameter is q opt » 0:76 corresponding to D opt » 4k B T; t c =t L ¼ 10 À2 ; s L =L T ¼ 10 À2 .
insensitive to the costs of the respective resources: resources that are in excess cannot improve sensing and are thus wasted, no matter how cheap they are. It probably explains why our theory, without any fit parameters, not only predicts the integration time that allows E. coli to sense shallow gradients ( Figure 4) but also the number of receptor and readout molecules (Govern and Ten Wolde, 2014a).
In our study, we have limited ourselves to a canonical push-pull motif. Yet, the work of Govern and Ten Wolde, 2014a indicates that our results hold more generally, pertaining also to systems that employ cooperativity, negative or positive feedback, or multiple layers, as the MAPK cascade. While multiple layers and feedback change the response time, they do not make time integration more efficient in terms of readout molecules or energy (Govern and Ten Wolde, 2014a). And provided it does not increase the input correlation time (Skoge et al., 2011;Ten Wolde et al., 2016), cooperative ligand binding can reduce the sensing error per sample, but the resource requirements in terms of readout molecules and energy per sample do not change (Govern and Ten Wolde, 2014a). In all these systems, time integration requires that the history of the receptor is stored, which demands protein copies and energy.
Lastly, in this article we have studied the resource requirements for estimating the current concentration via the mechanism of time integration. However, to understand how E. coli navigates in a concentration gradient, we do not only have to understand how the system filters the high-frequency ligand-binding noise via time averaging but also how on longer timescales the system adapts to changes in the ligand concentration (Sartori and Tu, 2011). This adaptation system also exhibits a trade-off between accuracy, speed, and power (Lan et al., 2012;Sartori and Tu, 2015). Intriguingly, simulations indicate that the combination of sensing and adaptation allows E. coli not only to accurately estimate the current concentration but also the future ligand concentration (Becker et al., 2015). It will be interesting to see whether an optimal resource allocation principle can be formulated for systems that need to predict future ligand concentrations.

Materials and methods
Methods are described in Appendices 1-3. Appendix 1 derives the central result of our article (Equation 6). Appendix 2 derives the fundamental resources and the corresponding sensing limits (Equations 8 and 9). Appendix 3 describes how the optimal gain and integration time can be understood using ideas from filtering and information theory.
where n ¼ pð1 À pÞ=ðL T t c Þ and hdLðt 0 Þi dLðtÞ is the average ligand concentration at time t 0 , given that the ligand concentration at time t is dLðtÞ. The latter is given by Bowsher et al., 2013 hdLðt 0 Þi dLðtÞ ¼ dLðtÞe ÀjtÀt 0 j=t L : Combining Equations 17-19 yields the following expression for the average change in the average receptor occupancy p t r , given that the ligand at time t is dLðtÞ: g L!pt r dLðtÞ: Hence, the dynamic gain isg The dynamic gain is the slope of the dynamic input-output relation p t r ðLÞ (see Figure 2a). It yields the average change in the receptor occupancy p t r over the past integration time t r when the change in the ligand concentration at time t is dLðtÞ. It depends on all the timescales in the problem and only reduces to the static gain g L!p ¼ pð1 À pÞ=L when the integration time t r and the receptor correlation time t c are both much shorter than the ligand correlation time t L . The dynamic gain determines how much an error in the estimate of p t r propagates to the estimate of LðtÞ.

Error in receptor occupancy
We can derive the variance in the estimate of the receptor occupancy over the past integration time t r , s 2 pt r , directly from Equation 14 for the system in the irreversible limit (Malaguti and Ten Wolde, 2019). While this derivation is illuminating, it is also lengthy. For the fully reversible system studied here, we follow a simpler route. Since the average number of samples N over the integration time t r is constant, it follows from Equation 14 that where s 2 x Ã jL is the variance in the number of phosphorylated readout molecules, conditioned on the signal at time t being LðtÞ ¼ L. The conditional variance (Tostevin and ten Wolde, 2010) is the full variance s 2 x Ã of x Ã minus the varianceg 2 L!x Ã s 2 L that is due to the signal variations, given by the dynamic gaing 2 L!x Ã from L to x Ã times the signal variance s 2 L . The full variance of the readout s 2 x Ã in Equation 25 can be obtained from the linear-noise approximation (Gardiner, 2009), see Malaguti and Ten Wolde, 2019: In this expression, ¼ t c À1 ¼ k 1 L þ k 2 is the inverse of the receptor correlation time t c ; p ¼ RL=R T ¼ k 1 L=ðk 2 þ k 1 LÞ ¼ k 1 Lt c is the probability that a receptor is bound to ligand; ¼ R T k 1 ð1 À pÞ ¼ pð1 À pÞR T =L; 0 ¼ t À1 r ¼ ðk f þ k Àf ÞpR T þ k r þ k Àr is the inverse of the integration time t r ; f ¼ x Ã =x T ¼ ðk f pR T þ k Àr Þt r is the fraction of phosphorylated readout; and 0 ¼ k f X T ð1 À f Þ À k Àf X T f ¼ _ n=ðpR T Þ is the total flux _ n around the cycle of readout activation and deactivation divided by the total number pR T of ligand-bound receptors: it is the rate at which each receptor is sampled, be it ligand bound or not. For what follows below, we note that the quality parameter q ¼ ðe D1 À 1Þðe D2 À 1Þ=ðe D À 1Þ ¼ 0 pR T t r =ðf ð1 À f ÞX T Þ ¼ _ nt r =ðf ð1 À f ÞX T Þ. To get s 2 pt r from Equations 24 and 25, we need not only s 2 x (Equation 26) but also the average number of samples N and the dynamic gaing 2 L!x Ã . The average number of samples taken during the integration time t r is N ¼ _ nt r =p ¼ f ð1 À f ÞX T q=p ¼ 0 R T = 0 , and the effective number of reliable samples is N eff ¼ qN. Since p t r ðLÞ ¼ Ehx Ã i L =N, where Ehx Ã i L is the average number of active readout molecules for a given input LðtÞ ¼ L and N is a constant independent of L, it follows that g L!x Ã ¼g L!pt r N ¼g L!pt r R T 0 0 ; withg L!pt r the dynamic gain from L to p t r , given by Equation 22. Equation 27 can be verified via another route that does not rely on the sampling framework because we also know thatg L!x Ã ¼ s 2 L;x Ã =s 2 L (Tostevin and ten Wolde, 2010), where the co-variance s 2 L;x Ã can be obtained from the linear-noise approximation (Malaguti and Ten Wolde, 2019;Gardiner, 2009). Combining Equations 24-27 yields This can be rewritten using the expression for the fraction of independent samples, which, assuming that t r ) t c , is f I ¼ 1=ð1 þ 2t c =DÞ, with D ¼ 2t r R T =N eff the effective spacing between the samples (Govern and Ten Wolde, 2014a): Here, s 2; samp pt r is the sampling error in the estimate of p t r (Malaguti and Ten Wolde, 2019); it is a statistical error, which arises from the finite cellular resources to sample the state of the receptor, protein copies, time, and energy (see Figure 2b). The other contribution, s 2; dyn pt r , is the dynamical error in the estimate of p t r (Malaguti and Ten Wolde, 2019); it is a systematic error that arises from the input dynamics and only depends on the average receptor occupancy and the timescales of the input, receptor, and readout (see Figure 2c); it neither depends on the number of protein copies nor on the energy necessary to sample the receptor.

Final result: SNR
Combining Equations 29 and 22 with Equation 3 yields the principal result of our work (Equation 6) of the main text. estimating the ligand concentration from x Ã is no different from inferring it from the average receptor occupancyp t r ¼ x Ã =N. To make the connection with information and filtering theory, we note that in our Gaussian model the conditional distribution of dx Ã given dL is given by Tostevin and ten Wolde, 2010 whereg L!x Ã dL ¼ hdxi L is the average value of dx Ã given that dLðtÞ ¼ dL, and s 2 x Ã jL is the variance of this distribution (see also Equation 25).
The relative error, the inverse of the SNR (see Equation 2), is As mentioned in the main text, the SNR also yields the mutual information Iðx Ã ; LÞ ¼ 1=2 lnð1 þ SNRÞ between the input L and output x Ã (Tostevin and ten Wolde, 2010).
The notion of an optimal integration time or optimal dynamic gain is well known from filtering and information theory (Andrews et al., 2006;Hinczewski and Thirumalai, 2014;Becker et al., 2015;Monti et al., 2018a;Monti et al., 2018b;Mora and Nemenman, 2019). To elucidate the optimal gain and integration time in our system, we combine the above equation with Equations 25 and 26 to write the relative error as where g RL!x Ã ¼ 0 = 0 is the static gain from RL to x Ã . Written in this form, the trade-offs in maximizing the mutual information Iðx Ã ; LÞ (and minimizing the relative error in estimating the concentration) become apparent: increasing the dynamic gaing L!x Ã by decreasing the integration time t r raises the slope of the input-output relation x Ã ðLÞ, which helps to lift the transmitted signal above the intrinsic binomial switching noise of the readout, f ð1 À f ÞX T . Also, the dynamical error is minimized by minimizing t r and maximizingg L!x Ã . Yet, for the second term, which describes how noise in the input signal arising from receptor switching, pð1 À pÞR T , is propagated to the output x Ã , there exists an optimal integration time that minimizes this term: while decreasing t r increases the dynamic gain, which helps to raise the signal above the noise, it also impedes time averaging of this switching noise, described by the factor 1=ð1 þ t r =t c Þ.