A biological circuit to anticipate trend

Abstract Organisms gain by anticipating future changes in the environment. Those environmental changes often follow stochastic trends. The steeper the slope of the trend, the more likely the trend’s momentum carries the future trend in the same direction. This article presents a simple biological circuit that measures the momentum, providing a prediction about future trend. The circuit calculates the momentum by the difference between a short-term and a long-term exponential moving average. The time lengths of the two moving averages can be adjusted by changing the decay rates of state variables. Different time lengths for those averages trade off between errors caused by noise and errors caused by lags in predicting a change in the direction of the trend. Prior studies have emphasized circuits that make similar calculations about trends. However, those prior studies embedded their analyses in the details of particular applications, obscuring the simple generality and wide applicability of the approach. The model here contributes to the topic by clarifying the great simplicity and generality of anticipation for stochastic trends. This article also notes that, in financial analysis, the difference between moving averages is widely used to predict future trends in asset prices. The financial measure is called the moving average convergence–divergence indicator. Connecting the biological problem to financial analysis opens the way for future studies in biology to exploit the variety of highly developed trend models in finance.


Introduction
Predicting future environmental change provides many benefits.A microbe gains by anticipating the availability of sugars.A plant gains by forecasting the flow of nutrients.Plasticity benefits from a head start on altering physiology or form.Competitive players profit by preparing for the next step in a contest [1][2][3][4][5][6][7][8][9][10] .
Organisms often anticipate regular patterns of change, such as circadian rhythms or seasonal cycles.However, many regularities arise as stochastic trends.To take advantage of such trends, a biological circuit must measure past directionality and use that measurement to predict the direction of future change.
In the literature, studies of E. coli chemotaxis develop the most compelling models for the anticipation of trend [11][12][13] .Cells measure changes in chemical concentrations to predict whether future changes will be * Department of Ecology and Evolutionary Biology, University of California, Irvine, CA 92697-2525, USA web: https://stevefrank.orgincreasing or decreasing.Tjalma et al.'s 14 excellent recent article synthesizes past literature and develops new models.
This article introduces a simple model for anticipating trend.Roughly speaking, the model estimates the momentum of the current trend by the difference between a shorter-term moving average and a longerterm moving average.That estimate of momentum predicts the future direction of change because the future trend often continues in the direction of the current momentum.
Most existing models, such as those for E. coli chemotaxis, also base predictions on estimates of current or past trend.However, those previous models typically add specific aspects of a particular application or additional complexities, such as noise filtering.Those additions are interesting but also obscure the simplicity and generality of the underlying way in which estimates of momentum anticipate future trend.
The model here strips nonessential features to emphasize the fundamental structure of anticipation for simple stochastic trends.That abstraction provides the basis for future applications across a broader range of biological problems.
Empirically, the model predicts the primary mechanism that organisms use to anticipate environmental trends and the pattern of anticipatory response to environmental changes.Theoretically, the model provides the foundation for developing further predictions about tradeoffs between rapid adjustment of anticipated environmental changes and the susceptibility to perturbation of the circuit that predicts trends 14 .
The model's simplicity also reveals a close connection to the moving average convergence-divergence (MACD) indicator, the most widely used measure of momentum and trend to analyze asset prices in financial time series [15][16][17] .That connection between biological models and financial analysis encourages application of the highly developed models of information and anticipation in finance to biological problems.

The challenge
Let   be a randomly varying input signal.We wish to predict the direction of change at a future time,  + 1, relative to the current time, , which means predicting the sign of Δ  =   +1 −   .If  changes in a purely random way, as a random walk with no directionality, then expected prediction success above 1/2 is not possible.For prediction to be possible, we must assume some pattern to the fluctuations in   .
An exponential moving average of purely random inputs is perhaps the most generic type of trend.Start with a random walk, û , sampled at discrete times,  = 0, 1, . . . .Then replace each value at time  by its exponential moving average,   = (1 − ) û +   −1 .The value of 0 ≤  ≤ 1 sets the memory scale, with larger values averaging over longer time periods.Here, we linearly interpolate between the discretely sampled points to obtain values of   continuously with time.
The future change in   is positive when Because û is a random walk, its change is equally likely to be positive or negative.Thus, the best prediction for the sign of Δ  is the sign of Δ  −1 .In other words, the most recently observed direction of change provides the best prediction for the next direction of change.
Roughly speaking, we may think of the currently observed change, Δ  −1 , as the trend momentum.
Positive momentum means that the trend is likely to continue up.Negative momentum means that the trend is likely to continue down.The greater the momentum, the more likely the trend will continue in the same direction.For example, the larger Δ  −1 , the more negative the underlying random walk change, Δû  , must be to reverse the trend.Increasingly extreme moves in the underlying random walk are increasingly uncommon.
Thus, an ideal internal model uses the currently observed trend direction to predict the next direction of change.And it uses the trend momentum to estimate the confidence in the directional prediction.

Exponential moving average
I claimed that an exponential moving average provides a common type of trend.I made that claim because any process that balances a fluctuating input against a steady decay describes an exponential moving average.For example, the differential equation  =  −  determines a level of  that balances production or input, , against steady decay at rate .With  0 = 0, the value of  at time  is which is proportional to the continuous time exponential moving average of  at that time.The process in eqn 1 is a discrete time version of the balance between input and decay.

The circuit
To predict the trend direction, the following circuit calculates the difference between two moving aver-ages, each average taken over a different time scale Overdots denote derivatives with respect to time, , and , ,  are functions of time.For constant input, , the molecular of abundances of  and  have the same equilibrium values, /.As the input, , changes,  changes more slowly than  when  < 1.Thus,  −  tends to be positive when  is increasing and negative when  is decreasing.The values of  and  are approximately proportional to shorter and longer exponential moving averages of the input, .

An example
We can optimize the parameters relative to a particular goal.Figure 1 shows an example of an optimized circuit that predicts the future direction of change in   .Define maximum potential accuracy as the frequency at which the prior sign of change in   predicts the next sign of change, a continuation of trend.
In Fig. 1, the maximum potential accuracy is 0.8.Stochasticity in the input sequence means that sometimes the sign of the prior difference does not match the direction of the next difference.For this example, the optimized circuit accuracy is close the maximum potential accuracy, with a median deviation from the maximum of 0.001.
Figure 1b shows the classic MACD pattern for trend prediction from financial analysis.The slower signal in gold, which is the variable , lags the faster signal in blue, which is the variable, .A predicted trend reversal arises when the fast blue signal crosses the slow gold signal, that is, when the sign of  −  changes.Figure 1c  Typically, a change in momentum (panel c) precedes a change in trend (panel b), as happens around time point 104.The reason a slowing of momentum typically precedes a change in trend can be seen in eqn 1, which shows how changes in the direction of an exponentially smoothed input are often dominated by the momentum term.However, when the trend changes abruptly, momentum does not precede trend, as happends around time point 92.

Accuracy versus robustness
High accuracy requires that the  −  predictor in Fig. 1c switches sign immediately when the input turns down.The input appears as the red line in Fig. 1a.To achieve high accuracy in forecasting a change in trend direction, in Fig. 1b, the slower moving average, , in gold, must remain close to the faster moving average, , in blue.
The small difference between the moving averages,  and , means that false signals can arise from small perturbations.For example, at time point 102 in Fig. 1b, the moving averages touch, predicting an imminent reversal that does not subsequently occur.In addition, noise in the state variables  and  can trigger false signals.
Figure 2 shows the circuit optimized for wider differences between the fast and slow moving averages,  and .In panel b, The wider differences provide a stronger signal during a trend but lag in giving a signal when the trend does change direction.This system gives fewer false signals and is robust to small perturbations.However, because it lags when the trend does change, it has a lower accuracy when using the sign of the current difference,  −, to predict the direction of change in the input in the next time period.The median deviation from the maximum accuracy is 0.12, compared with a deviation of 0.001 in the circuit illustrated in Fig. 1.

Conclusion
Prior models analyzed how biochemical circuits predict future environmental changes 4,[11][12][13][14]19 . Thoe models use recent differences in input to predict future changes because that is the essential nature of the problem.
Although the prior models described biological circuits that predict environmental changes, none of those prior analyses presented a circuit and an explanation as simple as those given here.In essence, the difference between a shorter, more immediate moving average, , and a longer, slower moving average, , provides the basis to forecast trends.
In the technical analysis of financial prices, the MACD indicator for moving average convergencedivergence is calculated as the difference between longer and shorter moving averages.Organisms may use a similar calculation to anticipate environmental trends.

Markets
traces a function of the  −  difference.A convergence between the trends in panel b and c predicts a continuation of the current trend.A divergence between the trends in the two panels foreshadows a potential upcoming change in direction for the trend.For example, starting at time point 98, the  −  difference begins to shrink, causing an upturn in the trend in panel c.That uptrend signals a slowing of the downward momentum.At first the actual trend in panel b continues downward.Thus, the trends in the two panels are diverging.Then, at time point 104, the actual trend in b turns up, a convergence with the trend in c, signaling the potential start of an upswing, which in fact does occur.

Figure 1 :
Figure 1: Prediction for the direction of change in a sequence of observations.Dynamics given by eqn 2. In this example, the parameters , ,  were optimized for accuracy of prediction, yielding 0.1663, 0.08314, 0.2782, respectively.The plots show a subset of time points to magnify patterns and make them easier to see.(a) The faster of the two moving averages, , in blue, tracks the input sequence,   , in red.(b) The fast and slow moving averages,  and , in blue and gold, respectively.(c) The difference between the moving averages, plotted as 1000[ ( −) − 0.5], in which  () =   /(1 +  )is the sigmoid function.The sign predicts the direction of change in the next time step.The magnitude reflects the momentum, a measure of the relative confidence in the prediction for the future direction of change.To calculate the input sequence in eqn 1, the random walk follows a Wiener process with mean 0 and standard deviation 0.2, and the exponential moving average memory parameter is  = 0.2.For each realized sequence of the random walk, the values are normalized to [0.25, 0.75] by affine transformation, yielding û.The timescale and abundances in the plots have arbitrary units.The freely available computer code describes the scaling of time, the parameters, the optimization, and the production of graphics 18 .