{'fraction_non_alphanumeric': 0.034544069088138174, 'fraction_numerical': 0.008382016764033528, 'mean_word_length': 4.540103189493434, 'pattern_counts': {'":': 0, '<': 0, '<?xml version=': 0, '>': 2, 'https://': 0, '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}}
A correspondence between temporal correlations in time series, inverse problems, and the Spherical Model

In this paper we employ methods from Statistical Mechanics to model temporal correlations in time series. We put forward a methodology based on the Maximum Entropy principle to generate ensembles of time series constrained to preserve part of the temporal structure of an empirical time series of interest. We show that a constraint on the lag one autocorrelation can be fully handled analytically, and corresponds to the well known Spherical Model of a ferromagnet. We then extend such a model to include constraints on more complex temporal correlations by means of perturbation theory, showing that this leads to substantial improvements in capturing the lag one autocorrelation in the variance. We showcase our approach on synthetic data, and illustrate how it can be used to formulate expectations on the future values of a data generating process.

In this paper we employ methods from Statistical Mechanics to model temporal correlations in time series. We put forward a methodology based on the Maximum Entropy principle to generate ensembles of time series constrained to preserve part of the temporal structure of an empirical time series of interest. We show that a constraint on the lag one autocorrelation can be fully handled analytically, and corresponds to the well known Spherical Model of a ferromagnet. We then extend such a model to include constraints on more complex temporal correlations by means of perturbation theory, showing that this leads to substantial improvements in capturing the lag one autocorrelation in the variance. We showcase our approach on synthetic data, and illustrate how it can be used to formulate expectations on the future values of a data generating process.
Arguably, one of the main driving forces of such an interest is Statistical Mechanics, which provides a unified and coherent framework based on first principles to model large interacting systems even outside the realm of Physics. In particular -as originally suggested by Jaynes [21,22] -the Maximum Entropy principle has been used as a flexible tool to build unbiased statistical models in a vast range of different disciplines [23][24][25].
However, in most of such applications, the Maximum Entropy principle is used in the opposite way with respect to its classical use in Statistical Mechanics, where the goal is usually to compute observable macroscopic quantities (such as correlations in an Ising model) from the unobservable microscopic laws ruling the interactions between the components of a system [26]. The opposite problem is that of inferring the parameters of an interacting system (e.g., the coupling constants and fields in an Ising model) from snapshots of its microscopic configurations. This is referred to as the "inverse problem". In Physics, it has received considerable attention especially when applied to fully connected Ising models [26,27]. Outside Physics, instead, it has provided a theoretical basis for some of the aforementioned interdisciplinary applications, due to the increased accessibility of the "microscopic configurations" of many non-physical systems (e.g., financial markets, social networks, neuron firing patterns, etc.) thanks to Big Data.
Jaynes proposed an alternative principle when dealing with models of time-evolving systems, typically non stationary or out of equilibrium ones. Known as the Maximum Caliber principle [28], its goal is to determine an unbiased distribution over all possibles paths of a system by maximising the system's path entropy while preserving some desired constraints on its trajectories. Researchers have used the Maximum Caliber principle in a wide rage of different applications [29,30], the majority of which have been devoted to determining the transition rates of Markov models [31,32] for systems evolving in continuous time between a fixed set of states.
In the case of systems evolving in discrete time, the Maximum Caliber principle can be shown to coincide with the Maximum Entropy principle by mapping time as the spatial dimension of a lattice whose sites are occupied by events [33,34]. In practice, this mapping effectively corresponds to time series, as even most systems evolving in continuous time are sampled at discrete times.
In Ref. [34], we have shown how the Maximum Caliber / Entropy formulation can be used to generate ensembles of multivariate time series in discrete time constrained to preserve -on average -some empirically observed distributional properties of a multivariate system (such as, e.g., higher order moments and seasonalities). One of the main challenges of the multivariate case presented in [34] is that of explicitly accounting for correlations, which can only be captured indirectly via other constraints.
In the present work, we partially overcome such limitations by tackling the problem of explicitly accounting for temporal correlations in the case of univariate systems. Modeling the temporal correlations of statistical systems is a notoriously challenging task. The most frequently used tools are autoregressive models belonging to the ARCH-GARCH family [35,36], or stochastic processes such as the Ornstein-Uhlenbeck model [37]. These models -and those inspired by them -have enjoyed great success in a variety of applications where modeling time correlations can be crucial, such as, e.g., in Economics or Finance [38,39]. Here, instead, we adopt a data-driven perspective -grounded in the Maximum Entropy principle -in order to capture the time correlations of a system without the need to explicitly model its time evolution.
First, we will briefly introduce the general methodology in its full mathematical form (Section II). Then, we will apply it to generate ensembles of time series designed to preserve on average correlations between first moments as measured in an empirical time series of interest. In order to do so, we will leverage the Spherical Model [40,41], and we will show that it naturally corresponds to autoregressive processes [35] (Section III). After that, we will proceed to account for higher order temporal correlations. We will do so by solving a more complex model by expanding on the Spherical Model by means of perturbation theory (Section IV). In the former case, the analytical knowledge of the Spherical Model's partition function makes the calibration of the proposed approach extremely simple, whereas in the latter case we will show how the Plefka expansion [42] -a technique commonly used for the inverse Ising problem -can be applied to find an approximate solution.

II. MAXIMUM ENTROPY FRAMEWORK FOR TIME SERIES DATA
Let X be the set of all real-valued time series of length T , and let X ∈ X be an empirical time series of interest, i.e., x t stores the time t value sampled from a variable under consideration. The goal of the methodology is to define an ensemble able to preserve -as ensemble averages -L empirical measurements on X. In other words, we want to find a probability density function P (X) over X , such that the expectation values O (X) = X∈X O (X)P (X) of a set of observables ( = 1, . . . , L) coincide with their values measured in the given time series O = O (X). In these terms, the problem is ill-defined, as P (X) may be defined in an arbitrary number of ways. However, if we require P (X) to also maximise the entropy S(X) = X∈X −P (X) log (X), computing P (X) becomes a constrained maximization problem which can be uniquely solved by choosing: where H(X) = β O (X) is the Hamiltonian of the ensemble, β ( = 1, . . . , L) are Lagrange multipliers introduced to enforce the constraints, and Z = X e −H(X) is the partition function of the ensemble, which verifies O (X) = −∂ log Z/∂β , ∀ . The existence and uniqueness of the Lagrange multipliers can be proved, and it can also be shown that they are equivalent to those that maximize the likelihood of drawing the time series X from the ensemble [43].
The problem of determining P (X) has therefore been solved. However, explicitly computing the Lagrange multipliers β that maximise the likelihood of drawing the data from the ensemble without an analytical form for Z can only be achieved by means of Boltzmann learning gradient-descent algorithms [26]. These ultimately require an exhaustive phase space exploration through sequential Monte Carlo simulations, which quickly becomes computationally unfeasible for T 1. Therefore, finding a closed form solution (even an approximate one) for Z is the cardinal problem to be solved in order to fully define a working methodology.
As a dummy example to illustrate how a specific ensemble can be computed, let us consider an empirical time series X t of length T and let us choose as constraints its sample mean m = T t=1 x t and mean square value V = T t=1 x 2 t . In order to compute the partition function Z, let us denote as x t the t-th element in X, and let us place each of such elements on a one dimensional lattice of length T . The constraints on the mean and mean square value lead to the following Hamiltonian: After having specified the constraints, what is left to do is to evaluate the partition function. In order to do that, we need to properly define the sum over the phase space X appearing in the definition of Z: Once the partition function is known, the Lagrange multipliers λ 1 and λ 2 can be found by solving the following system of coupled equations: which leads to the following probability density function for the ensemble: which is the factorized probability density function of T independent Gaussian random variables with mean m and variance (V − m) 2 .

III. THE FIRST HAMILTONIAN
We shall now apply the framework introduced in the previous section to a more complex set of constraints, namely the sample mean (m), mean square value (V ) and temporal correlation at lag one After placing the data points on a temporal lattice, the specified set of constraints leads to the following Hamiltonian: where we are assuming spherical boundary conditions (1) is that of the Spherical Model [40], a well-known model in Statistical Mechanics.
Having specified the Hamiltonian, the task now becomes finding the partition function Z, which reads: where we have introduced the following vector notation: Using the fact that A is a special case of a real symmetric circulant matrix (whose spectral properties are generally known [44]), one can show that its eigenvalues are Λ t = λ 2 +λ 3 cos 2π T (t − 1) (t = 1, . . . , T ). These can be used to highlight -in the limit T 1 -the explicit dependency of Z from the Lagrange multipliers. Expanding each term appearing in Eq. (2), we have: where we have used the fact that e = (1, . . . , 1) is the eigenvector of A (and therefore of A −1 ) associated to Λ 1 . Plugging the above expressions into Eq. (2), we obtain the ensemble's partition function, which reads: From Eq. (4) we can derive the system of equations for the Lagrange multipliers: .
The above equations can be easily solved analytically. Their expressions are not particularly instructive, so we omit them for easiness of exposition. Once the system in Eq. (5) has been solved the ensemble is fully defined, and instances can be drawn from it with standard Monte Carlo methods [45]. Figure 1 showcases an application of the ensemble aimed at reconstructing a known data generating process. Black lines correspond to data generated synthetically from an autoregressive model defined as follows: is a random number drawn at time t from a uniform distribution in the interval [a, b]. The solid black line corresponds to the final 30 points of an initial time series of length T = 180, which we use to compute the Lagrange multipliers appearing in Eq. (4) for the first time. The black dashed line corresponds to the continuation of such time series beyond time T , which we use both to update the Lagrange multipliers in "real time", and to test the agreement between the scenarios generated by the ensemble with respect to new data points. The blue solid line and shaded region correspond to "out of sample" next-step expectations for times t > T (i.e., obtained by recomputing the ensemble's Lagrange multipliers for all times t ≥ T + 1), denoting, respectively, the average value and 99% confidence interval computed from the ensemble via Monte Carlo simulations. The purple solid line and shaded region instead capture the "true" next-step evolution of the system. They correspond, respectively, to the mean and 99% confidence interval computed over a sample of 10 6 trajectories of the aforementioned autoregressive model generated as one-step increments starting -at all times -from the values represented by the dashed black line. As it can be seen from a qualitative inspection of the Figure, the ensemble reproduces rather faithfully the average time evolution of the underlying data generating process. There are, however, some visible deviations between the two confidence intervals shown in the Figure. These are due to the fact that the data generating process has non trivial time correlations in its higher order moments, which are not captured by the ensemble. These will be captured by the model introduced in the next Section, where we will also perform a more rigorous statistical assessment of the model's ability to reconstruct a data generating process.

IV. A MORE COMPLEX HAMILTONIAN
We now proceed to investigate a more complex ensemble encoding additional constraints. We consider the following Hamiltonian: ). Such constraints -coupled with the ones mentioned previously -effectively amount to constraining, respectively, the ensemble average on the kurtosis and on the variance autocorrelation at lag one.
Similarly to Eq. (2), the partition function resulting from Eq. (6) reads Integrals similar to the one above appear in λφ 4 lattice field theories, and are known for not being solvable ana-lytically. However, such calculations are commonly tackled by using resummation techniques or perturbation theory [46]. Following this line of research, we will make use of the Plefka expansion -a perturbation method widely used in the inverse Ising problem -in order to find approximate estimates of the true Lagrange multipliers.
In standard perturbation theory, the true Hamiltonian H of a system is written as a sum of an unperturbed part H 0 and a perturbation H p , i.e., H = H 0 + H p . Using this notation, the partition function of the system becomes: where Z 0 is the partition function of the unperturbed system (Z 0 = X e −H0 ), and · · · 0 is the average over the ensemble defined by Z 0 . Equation (8) is exact. However, in order to make it usable in practise, one needs to truncate the power series expansion (which becomes a power series expansion in the Lagrange multipliers appearing in the definition of H p ) to a certain order k. Of course, if one is lucky enough to find a recursion for H k p 0 and to sum the resulting series, one can in principle compute the true partition function Z.
The Plefka expansion follows a very similar procedure to the one just described. It starts from the Hamiltonian of the system written as H = H 0 + λH p , where λ is a constant that serves to distinguish different perturbation orders which will be ultimately set to one. Instead of expanding the partition function Z, the Plefka expansion considers the free energy of the system: where F 0 is the free energy of the unperturbed ensemble and F p = − log Z Z0 . We can now expand F p as a power series in λ: where we used the fact that if λ = 0 then F = F 0 . Substituting into e −Fp = Z/Z 0 , we obtain: Comparing Eq. (11) with the direct power series expansion Z/Z 0 = k (−λ) k H k p 0 /k!, we obtain an explicit expression for every term of the expansion in Eq. (10): As it can seen from Eq. (12), the expansion of the free energy F is effectively an expansion around the cumulants of the unperturbed ensemble. A similar idea was developed (8 years earlier than Plefka) by Bogolyubov et al. [47] for the ferromagnetic Ising model. Let us now perform a second order Plefka expansion in the case of the Hamiltonian in Eq. (6). We will consider the Spherical Model (4) as the unperturbed ensemble Z 0 , with the perturbation given by As a result, the second order approximated free energy reads (13) We now proceed to evaluate the expectation values in Eq. (13) around the ensemble defined by Eq. (4). In order to do that, we need to apply Isserlis' Theorem [48], a result which is also largely employed in quantum field theory under the name of Wick's Theorem [49].
For easiness of exposition, let us redefine some quanti-ties appearing in Eq (5) as follows: where s 0 = s tt and s 1 = s t,t+1 , ∀t.
We can now proceed to calculate the expectation values appearing in Eq. (13). These read where f and g are polynomial functions of their variables and are specified in the Appendix. As one can see from Eqs. (13) and (15), the second order approximation contains the covariances of the unperturbed Hamiltonian at all possible ranges, i.e., not just at lag one. As a result, we need to find an explicit form for s tt in order to move forward. Following the steps that lead to the solution of the Gaussian integral in Eq. (2), we have: ) is the t-th element of the k-th eigenvector of the matrix A in Eq. (2), and y k = t V tk x t . The above expression can be then rewritten as where R = t − t is the distance between the two lattice sites being considered. We can now approximate the above expression for T 1 as follows: where I n (x) is the modified Bessel function of the first kind, and sign (x) = x |x| is the sign function. Let us briefly comment on the approximation made in the third step of the above expression (i.e., for λ 2 −|λ 3 | 1). As it can be seen from the expressions for s 0 and s 1 in Eq. (14), such approximation corresponds to a regime of strong time correlations up to lag one. The approximation effectively becomes useful only to compute time correlations at lag two or higher, i.e., to compute s tt for t > t+1, given that those at lower lags are known exactly. Therefore, λ 2 − |λ 3 | ≈ 1 corresponds to a regime of low time correlations even at lags zero and one. This, in turn, ensures that time correlations at higher lags will be low enough to make the error due to the above approximation negligible.
We can now plug the above result into Eq. (13) via Eq. (15) in order to compute the approximate form of the free energy deriving from the partition function in Eq. (7). After having computed such approximate form for F , we can calculate the Lagrange multipliers as usual, i.e., by solving the system of equations O (X) = ∂F/∂β , ∀ . Alternatively, one could truncate Eq. (11) to the second order of the couplings λ 3 and λ 4 , find an approximate form Z p of Z and then maximize the approximate likelihood e −H(X) /Z p .
In Figure 2 we showcase the ability of the ensemble introduced in this Section to match the imposed constraints with respect to its unperturbed counterpart. We do so using two autoregressive models with markedly distinct correlation features. The first model (Y t+1 = ξ , panels (a-c)) is designed to produce time series that -on average -have non-zero correlations only between second or higher order moments. This represents an "adversarial" example, in the sense that the only correlations present in the process cannot be captured by the unperturbed model of Eq. (4). This would suggest the need to use a "stronger" perturbation than the second order one in order to substantially improve the model's ability to capture the correlations of the process. However, panels (b) and (c) show that even stopping the perturbation expansion at the second order gives a sizeable improvement. The second model  I: Accuracy of one lag ahead predictions of the mean and 10% and 90% quantiles of the three data generating processes used so far. These are denoted respectively as M1 (Yt+1 = ξ ). The means and quantiles are denoted as x and q. H1 and H2 denote, respectively, predictions obtained by means of the unperturbed ensemble of Eq. (4) and the full ensemble of Eq. (7).
, panels (d-f)) is instead designed to produce time series with time correlations between first moments as well. This represents a scenario where the unperturbed model captures by design correlations between first moments, which translates into a partial ability to capture higher order correlations. These are then fully captured by the full model (see panels (e) and (f)).
In order to quantitatively assess the improvement of the proposed perturbative solution with respect to the unperturbed ensemble, we report the results from a few simple prediction exercises in Table I. Namely, we seek to predict the mean and the 10% and 90% quantiles of the data generating process one lag ahead. We compare such quantities against those computed from both the unperturbed and full ensemble, and we quantify the agreement with two widely adopted metrics of accuracy, namely the root mean square error (RMSE) and the R 2 . As it can be seen, in all cases switching from the unperturbed ensemble to the one in Eq. (7) systematically provides a measurable improvement, regardless of the specific model considered. Notably, the biggest relative improvement occurs for the model that we identified as an "adversarial" example. This is because, as mentioned above, in that case the unperturbed model cannot capture by design the relevant time correlations in the data generating process.

V. CONCLUSIONS
In this paper we have shown how we can apply tools from classical Statistical Mechanics to time series analysis by simply mapping the time dimension of a timeevolving system onto the spatial dimension of a lattice. This allows to design ensembles that preserve -on average -some desired constraints on the temporal structure of the data under consideration by imposing constraints on such a lattice. . In panels (c) and (f) horizontal dashed lines denote the 95% confidence level interval for the autocorrelation of white noise.
In particular, we have shown how a constraint on the lag one autocorrelation corresponds to a well known ensemble in Statistical Mechanics, namely the Spherical Model of a (anti/)ferromagnet. Moreover, we have shown how the Spherical Model can be used as a basis to handle higher order temporal correlations by using a perturbation theory approach. We have also shown how the inferred Lagrange multipliers of the ensembles can be updated in "real time" as new data from the system of interest are collected, which in turn allows to obtain information about the possible evolution of the underlying data generating process.
The results in this paper can be used as a basis to push the intuition presented here much further. First of all, the framework presented here, coupled with tools commonly used to tackle inverse Ising problems such as Pseudo-Likelihood methods, can be adapted in order to handle multiple time series and their correlations. Moreover, the accuracy of the single time series case presented here can be improved by considering higher perturbation orders or by considering different Hamiltonians. In particular, it would be interesting to extend the approach proposed here to Hamiltonians whose Lagrange multipliers are drawn from parametric distributions (similarly to couplings in spin-glass systems), which would provide an alternative -and possibly even more flexible -method to fit ensembles to some desired constraints. We hope to see some of these topics pursued in the near future.