Dynamical systems (Strogatz, 2018) describe the evolution of phenomena occurring in nature, in which a differential equation, dy/dt = f θ (y, t), models the dynamics of a d-dimensional state y ∈ R d . Here f θ is a non-linear operator parameterized by parameters θ. Learning dynamical systems is to search a good model for a dynamical system in the hypothesis space guided by some criterion for performance. In this work, we study the forecasting problem of predicting an sequence of future states (y k , ..., y k+q−1 ) given an sequence of historic states (y 0 , ..., y k−1 ).
A plethora of work has been devoted to learning dynamical systems. When f θ is known, physics-based methods based on numerical integration are commonly used for parameter estimation (Houska et al., 2012) . Raissi and Karniadakis (2018) ; Al-Aradi et al. (2018) ; Sirignano and Spiliopoulos (2018) propose to directly solve y by approximating f with neural networks that take the coordinates and time as input. When f θ is unknown and the data is abundant, data-driven methods are preferred. For example, deep learning (DL), especially deep sequence models (Benidis et al., 2020; Sezer et al., 2019; Flunkert et al., 2017; Rangapuram et al., 2018) have demonstrated success in time series forecasting. In addition, Wang et al. (2020b) ; Ayed et al. (2019b) ; Wang et al. (2020c) ; Chen et al. (2018) have developed hybrid DL models based on differential equations for spatiotemporal dynamics forecasting.
Our study was initially motivated by the need to forecast COVID-19 dynamics. Since the actual dynamics of COVID-19 is unknown, we perform a comprehensive benchmark study of various methods to forecast the cumulative number of confirmed, removed and death cases. 1 To our surprise, we found that physics-based models significantly outperform deep learning methods for COVID-19 forecasting. We adopt automatic differentiation for parameter estimation. Specifically, we use numerical integration to generate state estimate and minimize the difference between estimate and the ground truth with automatic differentiation (Baydin et al., 2017; Paszke et al., 2017) . This leads to a novel hybrid method for COVID-19 forecasting, AutoODE-COVID, which obtains a 57.4% reduction in mean absolute errors for 7-days ahead prediction.
To understand the inferior performance of DL in forecasting COVID-19 dynamics, we experiment with several other dynamical systems: Sine, SEIR, Lotka-Volterra and FitzHugh-Nagumo. We observe that DL models cannot cope with two distribution shift scenarios that may naturally occur in dynamical system learning: non-stationary dynamics and dynamics with different parameters. Our findings highlight the unique challenge of using DL models for learning dynamical systems and call for more robust methods that can generalize well for the forecasting task. To summarize, our contributions are the following:
1. We study the learning of dynamical systems for forecasting, even with unobserved variables. We perform a benchmark study of both physics-based and data-driven models for predicting the COVID-19 dynamics among the cumulative confirmed, removed and death cases. 2. We propose a hybrid model, AutoODE-COVID, with a novel compartmental model and automatic differentiation for forecasting COVID-19. Our method obtains a 57.4% reduction in mean absolute errors for 7-days ahead prediction compared with the best DL competitor. 3. We provide empirical evidence to explain the inferior performance of DL by learning Lotka-Volterra, FitzHugh-Nagumo and SEIR dynamics. We found that widely-used DL models fail to learn the correct dynamics when there is distribution shift either in the data space or the parameters of the dynamical system.
Learning Dynamical System The seminal work by Steven L. Brunton (2015) proposed to solve ODEs by creating a dictionary of possible terms and applying sparse regression to select appropriate terms. But it assumes that the chosen library is sufficient. Physics-informed deep learning directly solves differential equations with neural nets given space x and time t as input (Raissi and Karniadakis, 2018; Al-Aradi et al., 2018; Sirignano and Spiliopoulos, 2018 Deep Sequence Models Since accurate numerical computation requires lots of manual engineering and theoretical properties may have not been well understood, deep sequence models have been widely used for learning dynamical systems. Sequence to sequence models and the Transformer, have an encoder-decoder structure that can directly map input sequences to output sequences with different lengths (Vaswani et al., 2017; Wu et al., 2020; Li et al., 2020; Rangapuram et al., 2018; Flunkert et al., 2017) . Fully connected neural networks can also be used autoregressively to produce multiple time-step forecasts (Benidis et al., 2020; Lim and Zohren, 2020) . Neural ODE (Chen et al., 2018) is based on the assumption that the data is governed by an ODE system and able to generate continuous predictions. When the data is spatially correlated, deep graph models, such as graph convolution networks and graph attention networks (Velickovic et al., 2017) , have also been used.
Epidemic Forecasting Compartmental models are commonly used for modeling epidemics. proposes a time-dependent SIR model that uses ridge regression to predict the transmission and recovery rates over time. A potential limitation with this method is that it does not consider the incubation period and unreported cases. Pei and Shaman (2020) modified the compartments in the SEIR model into the subpopulation commuting among different places, and estimated the model parameters using iterated filtering methods. Wang et al. (2020a) proposes a populationlevel survival-convolution method to model the number of infectious people as a convolution of newly infected cases and the proportion of individuals remaining infectious over time. Zou et al. (2020) proposes the SuEIR model that incorporates the unreported cases, and the effect of the exposed group on susceptibles. Davis et al. (2020) shows the importance of simultaneously modeling the transmission rate among the fifty U.S. states since transmission between states is significant.
Denote y ∈ R d as observed variables and u ∈ R p as the unobserved variables, we aim to learn a dynamical system given as
(3.1)
In practice, we have observations (y 0 , y 1 , ..., y k−1 ) as inputs. The task of learning dynamical systems is to learn f θ and g θ , and produce accurate forecasts (y k , ..., y k+q−1 ), where q is called the forecasting horizon.
For data-driven models, we assume both f and g are unknown. We are given training and test samples either as sliced sub-sequences from a long sequence (same parameters, different initial conditions) or independent samples from the system (different parameters, same initial conditions).
In particular, let p S be the training data distribution and p T be the test data distribution. DL seeks a hypothesis h ∈ H : R d×k → R d×q that maps a sequence of past values to future values:
where (i) denotes individual sample, k is the input length and q is the output length. Following the standard statistical learning setting, a deep sequence model minimizes the training
is a loss function. For example, for square loss, we have
The test error is given as
The goal is to achieve small test error L 1 (h) and small |L 1 (h) − L 1 (h)| indicates good generalization ability.
A fundamental difficulty of forecasting in dynamical system is the distributional shift that naturally occur in learning dynamical systems (Kouw and Loog, 2018; Amodei et al., 2019) . In forecasting, the data in the future p T often lie outside the training domain p S , and requires methods to extrapolate to the unseen domain. This is in contrast to classical machine learning theory, where generalization refers to model adapting to unseen data drawn from the same distribution (Hastie et al., 2009; Poggio et al., 2012) .
Physics-based modeling assumes we already have an appropriate system of ODEs to describe the underlying dynamics. We know the function f and g, but not the parameters. We can use automatic differentiation to estimate the unknown parameters θ and the initial values u 0 . We coin this procedure as AutoODE. Similar approaches have been used in other papers (Rackauckas et al., 2020; Zou et al., 2020) but have not been well formalized. The main procedure is described in the algorithm 1. In the meanwhile, we need to ensure u and y have enough correlation that AutoODE can correctly learn all the parameters based on the observable y only. If u and y are not correlated or loosely correlated, we may be not able to estimate u solely based on the observations of y.
Algorithm 1: AutoODE 0: Initialize the unknown parameters θ, u 0 in Eqn. 3.1 randomly. 1: Discretize Eqn. 3.1 and apply 4-th order Runge Kutta (RK4) Method. 2: Generate estimation for y: (ŷ 0 , ...,ŷ k ) 3: Minimize the forecasting loss with the Adam optimizer,
. 4: After convergence, use estimatedθ,û 0 and 4-th order Runge Kutta Method to generate final prediction, (y k , ..., y t+q−1 ).
NeuralODE (Chen et al., 2018) uses the adjoint method to differentiate through the numerical solver. Adjoint methods are more efficient in higher dimensional neural network models which require complex numerical integration. In our case, since we are dealing with low dimension ordinary differential equations and the RK4 is sufficient to generate accurate predictions. We can directly implement the RK4 in Pytorch and make it fully differentiable.
We benchmark different methods for predicting the COVID-19 dynamics among the cumulative confirmed, removed and death cases. We instantiate a special instance of AutoODE, with a novel SuEIR compartmental model, called AutoODE-COVID.
We present the AutoODE-COVID model given in Eqn. (4.1) and details are listed as below. We estimate the unknown parameters β i , σ i , µ i , and γ i , which correspond to the transmission, incubation, discovery, and recovery rates, respectively. We also need to estimate unknown variables, the cumulative numbers of susceptibles (S), exposed (E) and unreported (U ) cases, and predict the cumulative numbers of infected (I), removed (R) and death (D) cases. The total population
Low Rank Approximation to the Sparse Transmission Matrix A ij We introduce a sparse transmission matrix A to model the transmission rate among the 50 U.S. states. A is the element-wise product of the U.S. states adjacency matrix M and the transmission matrix C, that is, A = C M ∈ R 50×50 . M is a sparse 1-0 matrix that indicates whether two states are adjacent to each other. C learns the transmission rates among the all 50 states from the data. A = C M means that we omit the transmission between the states that are not adjacent to each other. We make C sparse with M as C contains too many parameters and we want to avoid overfitting. To further reduce the number of parameters and improve the computational efficiency to O(kn), we use a low rank approximation to generate the correlation matrix C = B T D, where B, D ∈ R k×n for k << n.
Piece-wise Linear Transmission Rate β i (t) Most compartmental models assume the transmission rate β i is constant. For COVID-19, the transmission rate of COVID-19 changes over time due to government regulations, such as school closures and social distancing. Even though we focus on short-term forecasting (7 days ahead), it is possible that the transmission rate may change during the training period. Instead of a constant approximation to β i , we use a piece-wise linear function over time β i (t), and set the breakpoints, slopes and biases as trainable parameters.
Death Rate Modeling: r i (t) The relationship between the numbers of accumulated removed and death cases can be close to linear, exponential or concave in different states. We assume the death rate r i (t) as a linear combination of a i t + b i to cover both the convex and concave functions, where a i and b i are set as learnable parameters. Weighted Loss Function We set the unknown parameters in Eqn. (4.1) as trainable, and apply AutoODE to minimize the following weighted loss function:
with weights α 1 , α 2 and loss function l(·, ·) which we will specify in the following section. We utilize these weights to balance the loss of the three states due to scaling differences, and also reweigh the loss at different time steps. We give larger weights to more recent data points by setting w(t) = √ t. The constants, α 1 , α 2 and k are tuned on the validation set.
We use the COVID-19 data from Apr 14 to Sept 12 provided by Johns Hopkins University (Dong et al., 2020) . It contains the cumulative numbers of infected (I), recovered (R) and death (D) cases. We investigate six DL models on forecasting COVID-19 trajectories: sequence to sequence with LSTMs (Seq2Seq), Transformer, autoregressive fully connected neural nets (FC), NeuralODE, graph convolution networks (GCN) and graph attention networks (GAN). We standardize I, R and D time series of each state individually to avoid one set of features dominating another. We use sliding windows to generate samples of sequences before the target week and split them into training and validation sets. We perform exhaustive search to tune the hyperparameters on the validation set.
We also compare SuEIR (Zou et al., 2020) and AutoODE-COVID. We rescale the trajectories of the number of cumulative cases of each state by the population of that state. We use the quantile regression loss (Wen et al., 2018) for all models. All the DL models are trained to predict the number of daily new cases instead of the number of cumulative cases because we want to detread the time series, and put the training and test samples in the same approximate range. All experiments were conducted on Amazon Sagemaker (Liberty et al., 2020) . Table 1 shows the 7-day ahead forecasting mean absolute errors of three features I, R and D for the weeks of July 13, Aug 23 and Sept 6. We can see that AutoODE-COVID overall performs better than SuEIR and all the DL models. FC and Seq2Seq have better prediction accuracy of death counts but all DL models have much bigger errors on the prediction of week July 13. Figure 1 visualizes the 7-day ahead COVID-19 predictions of I, R and D in Massachusetts by AutoODE-COVID and the best performing DL model, FC. The prediction by AutoODE-COVID is closer to the target and has smaller confidence intervals. This demonstrates the effectiveness of our hybrid model, as well as the benefits of our novel compartmental model design.
We explore the potential reasons behind inadequate performance of DL models on COVID-19 forecasting by studying their generalization ability. We experimentally explore the two cases, distribution shift in the data where the observations range changes; and parameter domains where the parameter range of the system in training and test differs.
Apart from COVID-19 trajectories, we also investigate the following three non-linear dynamics.
Lotka-Volterra (LV) system (Ahmad, 1993) of Eqn.(5.1) describes the dynamics of biological systems in which predators and preys interact, where d denotes the number of species interacting and p i denotes the population size of species i at time t. The unknown parameters r i ≥ 0, k i ≥ 0 and A ij denote the intrinsic growth rate of species i, the carrying capacity of species i when the other species are absent, and the interspecies competition between two different species, respectively.
FitzHugh-Nagumo (FHN) FitzHugh (1961) and, independently, Nagumo et al. (1962) derived the Eqn.(5.2) to qualitatively describe the behaviour of spike potentials in the giant axon of squid neurons. The system describes the reciprocal dependencies of the voltage x across an axon membrane and a recovery variable y summarizing outward currents. The unknown parameters a, b, and c are dimensionless and positive, and c determines how fast y changes relative to x.
SEIR system of Eqn.(5.3) models the spread of infectious diseases (HE, 1992) . It has four compartments: Susceptible (S) denotes those who potentially have the disease, Exposed (E) models the incubation period, Infected (I) denotes the infectious who currently have the disease, and Removed/Recovered (R) denotes those who have recovered from the disease or have died. The total population N is assumed to be constant and the sum of these four states. The unknown parameters β, σ and γ denote the transmission, incubation, and recovery rates, respectively.
We define p S and p T as the training and the test data distributions. And the θ S and θ T denote parameter distributions of training and test sets, where the parameter here refers to the coefficients and the initial values of dynamical systems. A distribution is a function that map a sample space to the interval [0,1] if it a continuous distribution, or a subset of that interval if it is a discrete distribution. The domain of a distribution p, i.e. Dom(p), refers to the set of values (sample space) for which that distribution is defined. We define two types of interpolation and extrapolation tasks. Regarding the data domain, we define a task as an interpolation task when the data domain of the test data is a subset of the domain of the training data, i.e., Dom(p T ) ⊆ Dom(p S ), and then extrapolation occurs Dom(p T ) ⊆ Dom(p S ). Regarding the parameter domain, an interpolation task indicates that Dom(θ T ) ⊆ Dom(θ S ), and an extrapolation task indicates that Dom(θ T ) ⊆ Dom(θ S ).
Through a simple experiment on learning the Sine curves, we show deep sequence models have poor generalization on extrapolation tasks regarding the data domain, i.e. Dom(p T ) ⊆ Dom(p S ). Specifically, we generate 2k Sine samples of length 60 with different frequencies and phases, and randomly split them into training, validation and interpolation-test sets. The extrapolation-test set is the interpolation-test set shifted up by 1. We investigate four models, including Seq2Seq (sequence to sequence with LSTMs), Transformer, FC (autoregressive fully connected neural nets) and NeuralODE. All models are trained to make 30 steps ahead prediction given the previous 30 steps. Table 2 shows that all models have substantially larger errors on the extrapolation test set. Figure  2 shows Seq2Seq predictions on an interpolation (left) and an extrapolation (right) test samples. We can see that Seq2Seq makes accurate predictions on the interpolation-test sample, while it fails to generalize when the same samples are shifted up only by 1.
Even when Dom(p T ) ⊆ Dom(p S ), deep sequence models can still fail to learn the correct dynamics if there is a distributional shift in the parameter domain, i.e., Dom(θ T ) ⊆ Dom(θ S ). For each of the three dynamics in section 5.1, we generate 6k synthetic time series samples with different system parameters and initial values. The training/validation/interpolation-test sets for each dataset have the same range of system parameters while the extrapolation-test set contains samples from a different range. Table 3 shows the parameter distribution of test sets. For each dynamics, we perform two experiments to evaluate the models' extrapolation generalization ability on initial values and system parameters. All samples are normalized so that Dom(p T ) = Dom(p S ).
Interpolation Extrapolation Interpolation Extrapolation The initial values and system parameters ranges of interpolation and extrapolation test sets. Table 4 shows the prediction RMSEs of the models on initial values and system parameter interpolation and extrapolation test sets. We observe that the models' prediction errors on extrapolation test sets are much larger than the error on interpolation test sets. Figures 3-4 show that Seq2Seq and FC fail to make accurate prediction when tested outside of the parameter distribution even though they make accurate predictions for parameter interpolation test samples.
Our AutoODE always obtains the lowest errors as it would be not affected by the range of parameters or the initial values. However, it is a local method and we need to train one model for each sample. In contrast, DL models can only mimic the behaviors of SEIR, LV and FHN dynamics rather than understanding the underlying mechanisms.
We are still at the early or middle stage of the COVID-19 epidemic. The recovery rate γ may increase as we gain more treatment experience. If the situation is not getting better, the government regulation would become stricter, leading to smaller contact rate β. Thus, there is a great chance that new test samples are outside of the parameter domain of training data. In that case, the DL models would not make accurate prediction for COVID-19.
We study the problem of forecasting non-linear dynamical systems and propose a hybrid method AutoODE-COVID for forecasting COVID-19 dynamics. From a benchmark study of DL and physics-based models, we find that FC and Seq2Seq have better prediction accuracy on the number of deaths, while the DL methods generally much worse than the physics-based models on the number of infected and removed cases. This is mainly due to the distribution shift in the COVID-19 dynamics. On several other non-linear dynamical systems, we experimentally show that four DL models fail to generalize under shifted distributions in both the data and the parameter domains. Even though these models are powerful enough to memorize the training data, and perform well on the interpolation tasks. Our study provides important insights on learning real world dynamical systems: to achieve accurate forecasts with DL, we need to ensure that both the data and dynamical system parameters in the training set are sufficient enough to cover the domains of the test set. Future works include incorporating compartmental models into deep learning models and derive theoretical generalization bounds of dynamics forecasting for deep learning models.