{'fraction_non_alphanumeric': 0.03977621367984118, 'fraction_numerical': 0.011117126872405703, 'mean_word_length': 4.491774033696729, 'pattern_counts': {'":': 0, '<': 2, '<?xml version=': 0, '>': 2, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
RECOWNs: Probabilistic Circuits for Trustworthy Time Series Forecasting

Time series forecasting is a relevant task that is performed in several real-world scenarios such as product sales analysis and prediction of energy demand. Given their accuracy performance, currently, Recurrent Neural Networks (RNNs) are the models of choice for this task. Despite their success in time series forecasting, less attention has been paid to make the RNNs trustworthy. For example, RNNs can not naturally provide an uncertainty measure to their predictions. This could be extremely useful in practice in several cases e.g. to detect when a prediction might be completely wrong due to an unusual pattern in the time series. Whittle Sum-Product Networks (WSPNs), prominent deep tractable probabilistic circuits (PCs) for time series, can assist an RNN with providing meaningful probabilities as uncertainty measure. With this aim, we propose RECOWN, a novel architecture that employs RNNs and a discriminant variant of WSPNs called Conditional WSPNs (CWSPNs). We also formulate a Log-Likelihood Ratio Score as better estimation of uncertainty that is tailored to time series and Whittle likelihoods. In our experiments, we show that RECOWNs are accurate and trustworthy time series predictors, able to"know when they do not know".


INTRODUCTION
Time series forecasting is the task to predict the future course (Y ) of a time series given its past X, also known as context. Currently, Recurrent Neural Networks [Rumelhart et al., 1985] are models of choice when it comes to time series forecasting. Recent advancements in RNNs research fostered their adoption in practice surpassing established models, e.g. ARIMA (Autoregressive Integrated Moving Av- Figure 1: Overview of the RECOWN architecture. The context X is transformed using STFT with a window size of T w , a) determining the weights of the CWSPN via the Neural Network (NN) and b) serving as input to the (complex)-Gated Recurrent Units (GRU) [Chung et al., 2014] of the RNN, resulting in the prediction of the Fourier coefficients D 2 , D 3 . Those are then provided to the CWSPN, which computes the conditional Whittle log-likelihood (D 2 , D 3 |D 0 , D 1 ) (see Section 2.3). erage) [Siami-Namini et al., 2018], in several scenarios [Fei and Yeung, 2015, Li et al., 2019, Li and Cao, 2018. However, in complex real-world applications, time series are highly subject to several influence factors which are often hard to capture. For example, in the case of grocery demand, the demand for ice cream or BBQ-related products is expected to be higher as long as the weather is warmer than usual. Furthermore, exceptional events like a pandemic can significantly influence demands as well. In such cases, the prediction of a model will likely be less accurate compared to usual circumstances. To properly detect such cases, a mea- RECOWNs are trustworthy models that can provide predictions with an uncertainty measure estimated by the Log-Likelihood Ratio Score (LLRS, in green, see Section 3.3). This can be provided at any time point of the prediction. Here, the model has been trained to perform short-range "standard" forecast. Obviously, the model is less accurate on longer-range predictions. For those, RECOWNs correctly indicate their confidence with a meaningful increase of uncertainty (LLRS) over time. This makes the model trustworthy and can support users in decision-making processes.
sure of uncertainty about the prediction is valuable [Guo et al., 2017, Laptev et al., 2017, Gal and Ghahramani, 2016. It would make the predictions trustworthy and it would better support the users in decision-making processes. A relevant approach to achieve this is provided by Gaussian Processes (GPs) [Rasmussen and Williams, 2006]. However, GPs are comparably computationally expensive and therefore not suited for large datasets [Seeger, 2004]. Several methods have been proposed to scale GPs on large datasets, e.g. by modeling the mixture of subspaces using GP experts with Sum-Product Networks (SPNs) [Trapp et al., 2020, Bruinsma et al., 2020, Yu et al., 2021b. Anyhow, for time series forecasting, RNN architectures [Alpay et al., 2016, Wolter et al., 2020, Koutnik et al., 2014 have shown to be superior in terms of prediction accuracy. Rasul et al. [2021] already examined this direction, by employing autoregressive denoising diffusion models in the time domain to equip RNN-predictions with a measure of uncertainty on the level of time steps. Still, they do not provide an uncertainty measure on the level of sequences, which enables users to quickly detect potentially problematic forecasts. Furthermore, modeling in the spectral domain is beneficial for prediction performance [Wolter et al., 2020].
Therefore, we introduce REcurrent COnditional Whittle Networks (RECOWNs), a deep architecture that makes use of Short Time Fourier Transform (STFT) and integrates a Spectral RNN [Wolter et al., 2020] together with a conditional variant of a Whittle SPN [Yu et al., 2021a] (CWSPN) i.e. a discriminative probabilistic circuit tailored for time series. The overall architecture is depicted in Figure 1. In this way, RECOWN can keep the good forecasting performance of RNNs while, thanks to the CWSPN, providing meaningful probabilities as a measure of uncertainty of the predictions. A showcase of its potential can be found in Figure 2, showing how the CWSPN correctly predicts when the forecast of the Spectral RNN increasingly diverges from the ground truth. RECOWNs can be trained end-to-end by gradient descent and have modular nature, in fact, one can employ any differentiable density estimator instead of a CWSPN. However, in our experiments, CWSPNs resulted in the best choice compared to another state-of-the-art density estimator, MAF [Papamakarios et al., 2017], especially when the model capacity is reduced. Furthermore, CWSPNs are also more flexible given that they can answer to a wider range of exact probabilistic queries in a tractable way.
ries in the spectral domain, but employ a different kind of Fourier Transform -the STFT -to account for changes in the frequency domain as the signal changes over time.
While Yu et al. [2021a] focus on modeling the joint distribution of the multivariate time series, in this work we shift our focus on predictions, providing them with probabilities as a useful measure of uncertainty. As successfully done in Yu et al. [2021a] and other previous methods [Tank et al., 2015], modeling time series in the spectral domain enables us to make use of the Whittle Approximation Assumption [Whittle, 1953] which facilitates the modeling of Fourier coefficients of a time series. Additionally, since RECOWNs model the time series in the spectral domain, we propose Log-Likelihood Ratio Score (LLRS) which enables us to compute the confidence intervals of the predictions back in the time domain. Experiments show that, compared to state-of-the-art models, RECOWNs are more accurate and trustworthy. Our contributions are the following: • We introduce RECOWN, the first deep tractable model for time series forecasting that is accurate and that provides an uncertainty measure for its predictions on sequence level as well as in the time domain, making them more trustworthy.
• We introduce a data sample weighting strategy based on the Mean Squared Error.
• We formulate the (Whittle) Log-Likelihood Ratio Score, tailored to better estimate the uncertainty of time series predictions based on the Whittle likelihood.
The paper is structured as follows: We start by introducing STFT, CWSPNs as well as Spectral RNNs, i.e. the main components of RECOWNs in Section 2. Then, in Section 3, we describe the experimental setting and analyze the results, showing that RECOWNs are accurate as well as trustworthy and that the LLRS is a valid tool to assess the uncertainty and the quality of the predictions. We conclude in Section 4 where we also point out future directions.

SHORT TIME FOURIER TRANSFORM
With Discrete Fourier Transformation (DFT), a time series can be mapped from the time to the spectral domain with a decomposition into linear combinations of sinus functions. For a multivariate time series X = x 1 , ..., x T with x t ∈ R p and length T , we can define the discrete Fourier coefficients d k ∈ C p at frequency λ k = 2πk T , k = 0, · · · , T − 1, using the Fourier transformation F as follows [Tank et al., 2015]: Moreover, given Fourier coefficients D = (d 0 , ..., d T −1 ), we can apply the inverse DFT to project the frequencies back to the time domain: However, to account for potential changes in the frequency domain as the signal changes over time, we apply STFT. The input is divided into overlapping segments and each segment is then approximated separately. STFT is introduced by Griffin and Lim [1984] by considering segments of length T w , extracted every S time steps: with w being a window function, m denoting the corresponding shift and the remaining defined analogously to Equation 1. This results in n s = T −Tw S + 3 windows in total when applying a padding of size S at the start and end of sequences. As with the regular Fourier transform, STFT can also be inverted: .
(4) Due to Hermitian symmetry, for real-valued time series, the negative Fourier coefficients are redundant. Therefore, we only need to model T = Tw 2 + 1 Fourier coefficients for a window size of T w . Furthermore, we apply a low-pass filter to filter out noise, which further reduces the number of parameters in the model. Details on the extent of filtering are described in Section 3.
The window function can be determined either by hand or learned by an optimizer [Wolter et al., 2020]. We apply a truncated Gaussian window at position n: The standard deviation σ is learned by the optimizer. By increasing σ, the window approaches a more rectangular shape, while it gets narrower when decreasing σ.

WHITTLE LIKELIHOOD
The Whittle likelihood models multivariate time series in the spectral domain. Given X , x t and T as defined in Section 2.1, x t is Gaussian stationary for t ∈ Z, if: Figure 3: Depiction of the optimization process for RECOWN in co-ordinate descent fashion. First, SRNN weights are optimized (Left), then CWSPN weights are optimized using the MSE together with the CWLL, which is derived from the SRNN predictions (Right). These steps are iterated until convergence.
Given X 1:N = {X 1 , . . . , X N } being N independent realizations of X and d n,k ∈ C p represent the discrete Fourier coefficient of the n-th sequence at frequency λ k : Based on the Whittle approximation assumption [Whittle, 1953], the Fourier coefficients are independent complex normal RVs with mean zero: with S k ∈ C p×p being the spectral density matrix. For a stationary time series, it is defined as: where the infinite sum may be approximated. Finally, the Whittle likelihood of the X 1:N is given by: The Whittle approximation holds asymptotically with large T and has been used also in Bayesian context [Tank et al., 2015]. We will make use of it and place a Complex Conditional SPN over the frequencies, resulting in CWSPNs, modeling the conditional Whittle Log-Likelihood (CWLL).

COMPLEX CONDITIONAL SPN
Sum-Product Networks [Poon and Domingos, 2011] are deep probabilistic circuits with tractable and exact inference. Among several applications, they have been successfully employed also for univariate time series modeling [Melibari et al., 2016]. Recent tensor-based SPN implementations such as RAT-SPNs [Peharz et al., 2020b] build upon randomly generated structures based on the notion of region graphs [Dennis and Ventura, 2012]. They are more scalable and enable training in an end-to-end fashion which allows them to be optimized jointly with NNs.
To provide a measure of how good a prediction (Y ) is with respect to a context (X), we aim for modeling the conditional likelihood P (Y |X). Although any SPN modeling the joint distribution could be employed for this task (since the conditional can be derived from the joint using P (Y |X) = P (X,Y ) P (X) ), the Conditional SPN (CSPN) [Shao et al., 2020] is a more natural choice. CSPN parameters are not learned directly, instead, a separate general function approximator g -in our case a neural network -is employed to provide parameters θ to the SPN based on the input x, i.e. g(x) = θ, while only y is provided as input to the SPN on the leaf layer. Analogously to Shao et al. [2020], we structure g as two separate, fully-connected networks g L and g S with ReLU activations, learning the leaf and sum node parameters θ = (θ L , θ S ) respectively, i.e. g(x) = (g L (x), g S (x)). Training this architecture -using gradient descent -results in modeling P (Y = y|X = x) := P (Y = y; θ). The structure of CSPN is generated at random, based on RAT-SPNs [Peharz et al., 2020b]. In this way, we can take advantage of the benefits provided by a tensorized SPN implementation.
We alter this approach to account for the complex values of the Fourier coefficients similarly to the Complex-Valued SPNs (CoSPNs) [Yu et al., 2021a], resulting in Complex Conditional SPNs (CoCSPNs). The input for the leaves of the CoCSPN are the Fourier coefficients of Y at frequency k and shift m, i.e. d m k = ST F T (Y ) m k . Based on the Whittle assumption, we know that the Fourier coefficients d m k are normal distributed. Therefore, also their real and imaginary parts are jointly normal distributed. To account for the correlations between the two parts, they are jointly mod- Context is not shown for clarity. We can observe much bigger variance between time steps for Retail data. This makes the prediction task for the SRNN harder.
eled by a single pairwise Gaussian leaf node, parameterized by a vector of means µ d m k ∈ R 2 and a covariance matrix Σ d m k ∈ R 2×2 . Thus, CoCSPN encodes the conditional where Based on this and Equation 11, we define the CWLL as: which models the probability of the predicted STFTwindows given the STFT-windows of the context, i.e. the Fourier coefficients of ST F T (X) are provided to the neural network g. The structural constraints of completeness and decomposability for SPNs still hold, as in [Yu et al., 2021a].

SPECTRAL RNN
We employ Spectral RNN [Wolter et al., 2020], designed for univariate time series forecasting, to provide predictions in RECOWN. Compared to a standard RNN, the recurrent steps are performed over the windows retrieved from STFT. Therefore, for a window with width T w and a step size S, it only has to perform n s instead of T time steps for an input of length T . The SRNN is defined as follows: with τ = [0, n s ] enumerating the total number of segments n s . Since X τ ∈ C T × 1 is a complex signal, the RNN cell either needs to operate in the complex space or needs to provide projections I : C T → R ni , O : R no → C T for n i -dimensional in-and n o -dimensional outputs respectively. Since complex units have not shown superior in preliminary experiments (similar to [Wolter et al., 2020]), we employ standard Gated Recurrent Units (GRU) [Chung et al., 2014]. As projections, we employ concatenation and splitting respectively, i.e. I(X τ ) = (Re(X τ ), Im(X τ )), and W pc ∈ R n h ×2T , where n h is the size of the hidden state and T the reduced amount of frequencies in the STFT. Additional details on SRNN are in [Wolter et al., 2020].

TRAINING RECOWNS
The architecture of RECOWN is shown in Figure 1. SRNN and CWSPN can be trained end-to-end in a co-ordinate descent fashion, as shown in Figure 3, resulting in RE-COWN. In each optimization step, the weights of the SRNN are updated first by minimizing the Mean Squared Error (MSE-loss), i.e. M SE(Y GT , Y P red ). Afterwards, the SRNN weights are fixed and the CWSPN is to be optimized w.r.t. minimizing an MSE-weighted negative Log-Likelihood (LL) loss on M samples of data: where SE denotes the Squared Error. Therefore, the CWSPN learns a skewed conditional distribution of predictions given the context: Predictions of the SRNN are directly passed to the SPN-part of CWSPN, while the Fourier coefficients of the context are passed to the NN g of CWSPN. By using the inverse weighting with the SE, we assume that less accurate predictions (high SE) occur less frequently in the distribution, while better predictions (low SE) are assumed to appear more often in the distribution. We opt for the square of the scaling factor to account for the exponentiallyshaped curve of the MSE as it can be seen in Figure 1. This helps the CWSPN to learn a more meaningful likelihood, as we will show in Section 3. One can employ any gradientdescent-based density estimator in RECOWN. However, as shown in the next Section, CWSPNs turned to be more suitable for RECOWN. Figure 5: RECOWNs can correctly separate between bad and good predictions. This is captured by the correlation of CWLL and MSE on Power (left) and Retail dataset (right). On the x-axis is denoted the enumeration of all test sequences (both context and prediction) in ascending order by MSE. It can be observed a clear (negative) correlation between a decreasing CWLL and an increasing MSE. The CWLL is smoothed by a moving average of 12 for clarity. Figure 6: RECOWNs CWLL can be employed successfully to sort sequences w.r.t. their expected error when the ground truth is not available. This represents a real use case, where possibly "bad" forecasts need to be detected.. For clarity, the MSE is smoothed by a moving average of 12.

EXPERIMENTAL EVALUATION
To show the benefits of using RECOWNs, we investigate the following research questions: (Q1) Quality of Predictions Can RECOWNs distinguish between "bad" and "good" predictions on a sequence level?
(Q2) Uncertainty of Predictions Using the Log-Likelihood Ratio Score (proposed in Section 3.3), can RECOWNs estimate the uncertainty of predictions in the time domain?

DATASETS
For our experiments 1 we evaluate the performance on two different z-score normalized datasets.
The first dataset is Power consumption, which uses the 15 minute-frequency data from the European Network of Trans-1 Code at: https://github.com/ml-research/ wtf-nets mission System Operators for Electricity 2 . Given 14 days of context, the network has to predict the power load from noon to midnight of the following day (i.e. 1.5 days). As window size, we choose 96, which corresponds to a full day given the 15-minute sampling rate.
The second dataset regards the task of forecasting the Retail demand, using data from a retail location of a big German retailer 3 , spanning over 2 years and including roughly 4k different products with a daily sampling rate. Here, the task is to predict three weeks of demand given half a year of context. Since no sales data of Sundays is present, we filter them out, making a window size of 12 a reasonable choice, i.e. spanning 2 weeks. We deliberately use a smaller window size here compared to the Power dataset in order to verify that the approach works also with different window sizes. Regarding the low-pass filter of STFT, we apply it with a factor of 4 to the Power and with a factor of 2 to the Retail data. Examples of sequences of both datasets can be found in Figure 4, together with the predictions of the SRNN.

CLASSIFICATION ACCURACY
Since the target of our approach is to use the likelihood of the CWSPN as an indicator for the quality of predictions, we will focus our evaluation on whether this correlation is true for a significant part of our test sequences or not. To do so, we first inspect the correlation visually through plots and revise it more formally later by using a correlation error.

Correlation Plots
To visually inspect the quality of the CWLL as an indicator for the prediction quality, we first calculate the CWLL and MSE for all test sequences of each dataset and plot those in ascending order by MSE. As shown in Figure 5, a clear  correlation between CWLL and MSE exists: The higher the MSE, the lower the CWLL. The same happens for the magnitude, i.e. the exponentially-shaped curve of the MSE is reflected in the CWLL. Based on these observations, we can assume that the CWLL is a good indicator for the prediction quality, and it fulfills (Q1). We show this assumption holds more formally in Section 3.2.2.
As in real-world scenarios, where usually the ground truth is not (yet) known and the MSE is therefore missing, one could use the CWLL to sort sequences from potential high MSE (low CWLL) to probably low MSE (high CWLL) and analyze further those potential high MSE frequencies. Such a use case is depicted in Figure 6. It shows once again a strong correlation between an increasing CWLL with a lower MSE of predictions. To have a quantitative perspective, we provide the following example of a potential use-case: Selecting the 5% sequences with the lowest CWLL from CWSPN on Power, we find that 75% of all sequences with the worst 5% of MSEs are included. Looking at the 10% sequences with the lowest CWLL, we find 98.5% of all sequences with the worst 5% of MSEs. This highlights how RECOWNs are able to distinguish between good and bad predictions.

Correlation Error (CE)
In order to provide a correlation error for each test sequence n, we calculate a relative prediction error S n P red = and a likelihood score (S n ) respectively: The square root is taken to take into account the exponential shape of the conditional CWLL, as can be seen in Figure 5.
Given that the MSE reflects the gold standard on where a sequence should be placed on the range from "bad" to "good", we define the Correlation Error (CE) for the CWLL as the quadratic distance of the scores: Since S n P red , S n ∈ [0, 1] by definition, we have CE n ∈ [0, 1]. In order to better assess this novel score, we provide a random baseline, which draws likelihood scores randomly from a uniform distribution, i.e. S n random ∼ U(0, 1). To evaluate the correlation error, we compare CWSPN with Masked Autoregressive Flow (MAF) [Papamakarios et al., 2017], a state-of-the-art neural density estimator. MAF is integrated into the joint RECOWN architecture like CWSPN, therefore, it follows the same training objective as given in Equation 18. We refer to this architecture as RECOWN-MAF. For each model, we report scores from the spectral domain as well as on the original time series (for CWSPN, modeling the time series in the time domain results in a CSPN). Furthermore, we evaluate three different model sizes, Small, Medium, and Large. The results and the number of trainable parameters are given in Table 1.
In general, modeling in the spectral domain (by using STFT) is more beneficial than operating in the time domain, while improving also parameter efficiency. This is more prominent for MAF. Furthermore, MAF achieves the best scores on bigger models, in comparison, CWSPN is particularly good with reduced model capacity. Overall, the correlation error obtained with the different architectures is relatively low, also on Retail which is a more difficult dataset. Moreover, it is much better than the random baseline. This allows us to answer (Q1) affirmatively. -RECOWN can distinguish between "bad" from "good" predictions on a sequence level. However, it is important to remark that SPN archi-tectures can naturally answer a wider range of queries than MAF. Additionally, during our experiments, we observed that CWSPN is also less sensitive to hyperparameter tuning.

PROVIDING UNCERTAINTY TO PREDICTIONS
The conditional Whittle Likelihood can also be used to estimate the uncertainty for a prediction in the time domain. This allows to take insights on how it changes over time.
With this aim, we use the notion of likelihood ratios, leveraging the window function w, to project the likelihood to the time domain at time step n: (22) Here, (Y pred (n)|X) denotes the conditional likelihood of prediction window n given the context. Every other window in the prediction is marginalized. Note that the calculation of λ LR has high similarities to the likelihood-score S n introduced in Section 3.2.2. Furthermore, we define the maximum likelihood ratio occurring in the training data: (23) Using λ LRmax as normalization for λ LR , we can estimate the uncertainty of the prediction via the Log-Likelihood Ratio Score (LLRS): As with the correlation error, we take the square root to account for the exponential shape of the CWLL (see e.g. Figure 5). In this way, a likelihood equally worse as the worst training sample likelihood (i.e. (Y pred |X) = min Y,X∈DTrain (Y |X)) results in LLRS = 1. Larger likelihoods (i.e. (Y pred |X) > min Y,X∈DTrain (Y |X)) result in scores LLRS < 1, smaller likelihoods (i.e. (Y pred |X) < min Y,X∈DTrain (Y |X)) in LLRS > 1. Thanks to z-score normalization, LLRS can be applied without concerns about the magnitude of the original data.
To evaluate LLRS potential, we run long-time range forecasting on both datasets. For the Power dataset, we predict 40 days as long-range prediction, performed by RECOWN trained only for 5 days prediction ("standard prediction"). For the Retail dataset, we predict 16 weeks, performed by RECOWN trained only for 8 weeks prediction. Our assumption is that the predictions made by the SRNN are less accurate over time and our aim is to make sure that this undesirable behaviour is captured by the uncertainty estimated with LLRS. As it can be seen in Figure 2, the more the prediction diverges from the ground truth over time, the more the uncertainty grows. This shows that the uncertainty estimated by LLRS can be a good indicator for users to detect such cases, even when the ground truth might be not available. Therefore, (Q2) can be answered positively: RE-COWNs can estimate the uncertainty of predictions in the time domain and this can support users in decision-making.

CONCLUSION
In this paper, we proposed RECOWNs, a novel architecture that jointly trains an SRNN and a probabilistic circuit in order to provide the SRNN with a measure of uncertainty of its predictions, on sequence level as well as in the time domain. This yields a trustworthy model for time series forecasting being able to inform the users when it is not confident of its predictions. We leveraged the conditional likelihood of context and predictions together with the Whittle approximation to introduce CWSPNs, which can provide a likelihood of the prediction given the context in the spectral domain. Furthermore, we introduced LLRS, an effective score to evaluate the uncertainty for any time point of a prediction. Our experiments on real-world datasets show that RECOWNs are both accurate and trustworthy. In this context, a probabilistic circuit tailored for time series based on the Whittle approximation showed to be superior to MAF, a state-of-the-art density estimator. We hope our results will inspire further research on trustworthy models for time series forecasting.
Future work may extend our contributions in several ways. Since RECOWN can be trained in an end-to-end fashion, we envision more sophisticated strategies for joint training. For example, gradients from the CWSPN could be used to improve the predictions of an SRNN. Moreover, it could be explored whether RECOWNs are robust against adversarial attacks. Besides, tractable general inference of CWSPNs could be exploited to gain knowledge about factors of influence for the prediction. In the same direction, modeling the joint distribution of the coefficients instead of the conditional, thus, being able to compute any marginal, could open new opportunities. For this scope, employing Einsum Networks [Peharz et al., 2020a], fast and scalable probabilistic circuits, could be an effective solution.