scieee AI-readable full text Open interactive document viewer

An improved estimator of Shannon entropy with applications to systems with memory

Gregorio, Juan de,Sánchez, David,Toral, Raúl

Abstract

Partial financial support has been received from MCIN/AEI/10.13039/501100011033 and the Fondo Europeo de Desarrollo Regional (FEDER, UE) through projects PACSS (RTI2018-093732-B-C21), APASOS (PID2021-122256NB-C21) and the María de Maeztu Program for units of Excellence in R&D , grant MDM-2017-0711.

Full text

An improved estimator of Shannon entropy with applications to systems with memory Juan De Gregorio,1David S´anchez,1and Ra´ul Toral1 1Institute for Cross-Disciplinary Physics and Complex Systems IFISC (UIB-CSIC), Campus Universitat de les Illes Balears, E-07122 Palma de Mallorca, Spain (Dated: November 21, 2022) We investigate the memory properties of discrete sequences built upon a finite number of states. We find that the block entropy can reliably determine the memory for systems modeled as Markov chains of arbitrary finite order. Further, we provide an entropy estimator that remarkably gives accurate results when correlations are present. To illustrate our findings, we calculate the memory of daily precipitation series at different locations. Our results are in agreement with existing methods being at the same time valid in the undersampled regime and independent of model selection. I. INTRODUCTION Stochastic modeling lies at the heart of many modern studies of complex systems. In this approach, the detailed dynamics is replaced by a set of transition probabilities that connect the states of the system at two different times. Quite often, the resulting stochastic processes can be modeled with the aid of discrete Markov chains [1], where the transition probabilities to a future state depend only on the present state and not on past states [2]. The broad applicability of this Markovian dynamics runs across disciplines: fluctuation theory in statistical physics [3], DNA sequence analysis in molecular biology [4], weather forecast in meteorology simulations [5], or web searches in information retrieval [6], just to mention a few. However, this memoryless approximation is insufficient if one deals with strongly correlated systems [7,8], whose next state depends not only on the present one but also on a longer history of past states. Higher-order Markov chains [9], which include a finite number mof past states to determine the transition probability to the next one, are thus needed for an accurate characterization of systems with memory. Recent examples of systems modeled with higher-order Markovian discrete chains include Parkinsonian tremor time series [10], linguistically detected emotional events [11], genomic polymorphisms for cancer research [12], human navigation on the web [13] and autochemotactic searchers [14]. It is therefore of utmost importance to have reliable methods that faithfully determine the order or memory mfor a given sequence of data [15]. This goal can be achieved in several ways. For the purpose of this paper, we focus on information-theoretical methods. The widely used Akaike information criterion (AIC) [16] is based on a loss function constructed from the Kullback-Leibler relative entropy. The loss function is then minimized to find a good estimate of m[17]. Since this approach views the transition probabilities from a frequentist perspective, the Bayesian information criterion (BIC) uses instead Bayes factors to further constrain the loss function [18]. While the AIC criterion is shown to overestimate m, the BIC is biased towards overly simple models [19]. To overcome these difficulties we propose in this paper a new method to determine the order of a Markov chain that best represents a given series of data. Advantages of the proposed method include that it is independent on model selection and sufficiently precise even in the undersampled regime. Central to our proposal is the block Shannon entropy [20]. Data are grouped in blocks of a given size nfrom which the entropy is extracted using the probability of each block. When the total sequence length is much larger than the number of possible blocks, such that all blocks appear with sufficient statistical relevance, the maximum likelihood estimator for the entropy works well. Nevertheless, sequences extracted from real data can be short and the previous estimator is consequently negatively biased [21]. There have been several attempts to derive unbiased estimators for the entropy but, to the best of our knowledge, all these proposals rely on the sequence being composed by independent random states. What is needed is a faithful estimator being able to deal with correlated systems, as inferred in this work. Therefore, our contribution is twofold. First, we suggest a novel method that determines the memory of a generic discrete sequence when the series is described by a Markov chain of arbitrary order. Second, we introduce an estimator suitable for the expected value of any observable (like the entropy) that provides information of a correlated system. We emphasize that both findings are independent and constitute, by their own, interesting advances that do not rely on each other. The calculation technique for the order of Markov chains would still hold if another block entropy estimator is used in any of the multiple contexts where these processes are relevant [22]. Additionally, our improved estimator can be applied to any model of correlations (not necessarily a Markov chain) and is thus of interest in situations where entropy is fundamental to understand the system’s properties [23]. The paper is organized as follows. In Section II we develop the main relation between the block entropy and the order of a Markov chain. We then explain the method to extract the order from the entropy estimator, based on a linear relation between the block entropy and the order, whose proof is left for the Appendix. In Section III we develop the algorithm to estimate the block entropy from arXiv:2205.11931v2 [cond-mat.stat-mech] 18 Nov 2022 2 FIG. 1. Sketch for the transition probabilities of two sequences with memory a) m= 1 and b) m= 2. a series of correlated data. In Section IV A we present a case study where we determine the memory of a series constructed numerically, while in Section IV B we apply the method to determine the order of daily precipitation series, comparing with the results found within the BIC approach. Finally, Section Vcontains our conclusions. II. RELATION BETWEEN BLOCK ENTROPY AND MEMORY Consider a discrete random variable Xwith Lpossible outcomes, {zi}, i ∈ {1, . . . , L}. Let S= (X1, . . . , XN) be a sequence of time-ordered observations, where Nis the sequence size. Then, Shas memory m≥1 if the transition probabilities satisfy P(Xs=zj|Xs−1=zl, . . . , X1=zk) = P(Xs=zj|Xs−1=zl, . . . , Xs−m=zr),(1) with sthe time or position in the series. For the case m= 0 the probabilities P(Xs=zj) are independent for all s. The sequence is termed Markovian if m= 1 in Eq. (1). Values m > 1 correspond to higher-order Markov systems, which are the focus of this work. In Fig. 1(a) we illustrate the transition probabilities for a generic sequence with m= 1: the outcome probability at time sdepends only on the previous state at time s−1 (red arrow). Figure 1(b) is a graphical representation for the case m= 2, where now the probability to observe the system in a given state at time sdepends on states at both previous times s−1 and s−2 (red arrows). In what follows, we consider homogeneous Markov chains for which the Lm+1 transition probabilities of Eq. (1) are independent of time index sand the conditional probabilities are then uniquely determined by the states {zi}. Furthermore, we will only consider the stationary case and therefore neglect transient effects. Given a long sequence Sit is not an easy task to determine the order mby a direct application of Eq. (1) since one should check a growing number of relations as mis increased. However, a much more efficient procedure stems from an analysis of the block Shannon entropy [24,25]. Let us form overlapping blocks in Sof size n≥1. The j-th block is then B(n) j= (Xj, . . . , Xj+n−1) with 1 ≤j≤N−n+1 ≡Nn. There exist Lndistinct possible blocks of size n, which we denote as {b(n) i}1≤i≤Ln. All observed blocks {B(n) j}j=1,...,Nnin the series Sbelong to the set {b(n) i}1≤i≤Ln. The block Shannon entropy is defined by Hn=− Ln X i=1 p(b(n) i) log(p(b(n) i)), n ≥1,(2) where p(b(n) i) is the probability of appearance of the block sequence b(n) i. We use the convention that H0≡0. The key point of the proposed method to determine the order of a stochastic process is to realize that Hnis a linear function of nfor n≥mif and only if the sequence has memory m(see Afor a proof). Therefore, we can write Hn= (Hm+1 −Hm)(n−m) + Hmn≥m≥0,(3) which, for the independent case (m= 0), reduces to the known expression for the entropy rate per symbol [26] Hn=nH1n≥1.(4) For the general case m > 0 the following procedure yields an accurate assessment of m. Given a trial memory µ= 0,1,2, . . . we define the trial entropies Hµ(n) by the relation: Hµ(n)=(Hµ+1 −Hµ)(n−µ) + Hµn≥µ. (5) Now, according to Eq. (3), Hµ(n) would be equal to Hn for n≥µif the series Scould be represented by a Markov chain of order µ. Therefore, if we consider the mean squared error ∆µ=1 nmax −µ+ 1 nmax X n=µ (Hµ(n)−Hn)2,(6) we find that ∆µvanishes for µ≥m, independently of the value of the cutoff nmax. Hence, the criterion to find the order mof the sequence Sis m= min({µ: ∆µ= 0}).(7) In contrast to the BIC and AIC methods, where the loss function depends on the model selected, Eq. (7) is independent of any selection procedure. For memory determination, both AIC and BIC methods are generally used along with a comparison among possible models suitable for a given sequence, whereas our proposed method provides an exact result for discrete random variables. If the system is naturally described with a continuous random variable, we first need to discretize this variable and the results obtained with Eq. (7) will depend on the binsize used for the discretization. 3 1 2 3 4 5 6 n 1 2 3 4 5 6 H n  0  1  2  3  4 01234 μ 0.0 0.5 1.0 Δ μ FIG. 2. Block entropies Hn(dots) and Hµ(n) (µ= 0,...,4 with different colors) versus block size nfor a binary sequence, L= 2, with memory m= 3 and transition probabilities chosen randomly from the interval (0,1). Inset: Mean squared error ∆µas a function of the trial memory µ. The proposed method determines the true memory from the condition min({µ: ∆µ= 0}), which is satisfied at µ= 3. As an example of an explicit calculation of m, in Fig. 2 we show results for a binary system (L= 2) and memory m= 3. The 23+1 = 16 transition probabilities are chosen randomly from a uniform distribution in the interval (0,1) (and multiplied by a common factor in order to fulfill the necessary normalization conditions). We plot in the main panel with color lines the trial entropy Hµ(n) given by Eq. (5) for different values of µ. For comparison, the exact block entropies Hn, computed from the transition probabilities, are also shown with black dots. Clearly, the trial entropies Hµ(n) coincide for µ≥3 with the exact block entropy Hnin agreement with the memory of the process. Alternatively, the inset of Fig. 2shows that the mean squared error ∆µvanishes for µ≥3. Therefore, Eq. (7) is met and the memory is m= 3, as expected. This particular example is based on a particular set of transition probabilities drawn from a uniform distribution. We stress that for a different set of transition probabilities the curves in Fig. 2would change quantitatively but the condition ∆µ= 0 for µ≥3 will always hold for a system with memory m= 3. As a consequence, the method is robust against strong variations of the transitions between states. It should be clear that in this example the determination of the memory mhas been very efficient because we had access to the true block entropies Hn, determined from the knowledge of the Lm+1 transition probabilities. In a case where this is not possible, for example, if we are given a numerical sequence Sof finite length N, we would need to replace the exact block entropies Hnin Eqs. (5) and (6) with appropriate estimators ˆ Hn. As a consequence, a good performance of our method requires a reliable estimator of the block entropies. Unfortunately, this is not an easy issue since all the entropy estimators reported in the literature have systematic biases that degrade the performance of the method. In the next section, we will propose a new entropy estimator that turns out to be particularly suitable for our purposes of determining the memory of a higher-order Markov process. III. ENTROPY ESTIMATOR Block probabilities and, hence, the Shannon block entropy, could also be obtained with a sufficient precision if we had access to an unlimited amount of data. However, data records are necessarily finite and we must resort to other less accurate estimates of the entropy that take into account this finite amount of data. Hereafter, we will use the notation ˆato denote a numerical estimator for an arbitrary random variable a. We recall that an unbiased estimator is one for which hˆai=a, while for biased estimators the difference hˆai − agenerally decreases with the sample size N. A first attempt to estimate the entropy of a general sequence Sis to employ the maximum likelihood estimator (MLE), ˆ HMLE n=− Ln X i=1 ˆpMLE(b(n) i) log ˆpMLE(b(n) i),(8) where ˆpMLE(b(n) i) = ˆn(n) i/Nnis the relative frequency given by the observed number of occurrences ˆn(n) ifor the block b(n) iwith respect to the total number Nn= N−n+ 1 of overlapping blocks of size npresent in S. Despite the fact that ˆpMLE is unbiased, ˆ HMLE nturns out to be biased [27] and this can lead to an extreme underestimation of Hn, especially in the undersampled regime Nn< Lnwhere hˆ HMLE ni< Hn. The estimation provided by this method can be considered reliable up to nmax ∼log(N)/log(L). There is not known unbiased estimator for the entropy [28] but there is a large number of estimators that manage to improve the results obtained with the MLE [29], allowing one to increase their range of validity as given by nmax. In particular, the coverage adjusted estimator proposed by Chao and Shen [21] provides good results for sequences of independent events. Here, we will present an estimator that generally improves the coverage adjusted estimator for systems with memory, using a combination of the Horvitz-Thompson adjustment [30] to account for missing elements in the sequence and a correction to the probabilities that takes into account correlations. A. Horvitz-Thompson correction Consider a variable A(b(n) i) that depends on block b(n) i. We are interested in a numerical estimation of the sum of Afor all possible blocks, namely Yn=PLn i=1 A(b(n) i). In a finite series S, not all Lnpossible values of b(n) iwill necessarily appear. To account for the missing blocks in the 4 data, Horvitz and Thompson [30] proposed to estimate Ynby summing only the contributions of the blocks that do appear in Sand weighting each term by the probability that the element is included in S: ˆ YHT n=X b(n) i∈S A(b(n) i) P(b(n) i∈ S),(9) For a random sequence of length N, memory m= 0 (independent events) and block size n= 1, the probability of appearance for block b(1) ican be computed as P(b(1) i∈ S)=1−(1 −p(b(1) i))N.(10) In principle, Eq. (10) does not hold in the presence of correlations (m > 0). It does not hold either for m= 0 and n > 1 as the existing overlapping between consecutive blocks already induces correlations in the block series: e.g., in the case L= 2 and n= 3 with possible results zi= 0,1, the block (0,0,1) can only be followed by the blocks (0,1,0) and (0,1,1). Nevertheless, we have checked in all our numerical simulations that the corrections introduced by these effects are negligible in the limit Nn(see B). Using Eqs. (9) and (10) in Eq. (2), one arrives at the Horvitz-Thompson estimator for the block entropy ˆ HHT n=−X b(n) i∈S p(b(n) i) log(p(b(n) i)) 1−(1 −p(b(n) i))Nn .(11) B. Chao-Shen estimator In general, the exact probabilities p(b(n) i) that appear in Eq. (11) are not known. Thus, it is necessary to replace them by their estimators obtained from the sequence S. The most basic estimator is the maximumlikelihood-estimator ˆpMLE(b(n) i) defined above. However, since not all possible blocks are likely to appear in the finite sequence S, we note that Pb(n) i∈S p(b(n) i)≤1 but, by construction, Pb(n) i∈S ˆpMLE(b(n) i) = 1. Therefore, it is convenient to correct the estimated frequencies before substituting them into Eq. (11). Chao and Shen [21] proposed to use instead of ˆpMLE(b(n) i) a new estimator ˆp(b(n) i) obtained by multiplying ˆpMLE(b(n) i) by the sample coverage ˆ Cn, ˆp(b(n) i) = ˆ CnˆpMLE(b(n) i).(12) The new estimator is requested to satisfy the condition Pb(n) i∈S ˆp(b(n) i) = Pb(n) i∈S p(b(n) i). From Eq. (12) and using the normalization condition of the MLE estimator, one finds that ˆ Cn=X b(n) i∈S p(b(n) i) (13) represents the total probability for the occurrence of the blocks observed in S.Pb(n) i∈S p(b(n) i)<1 implies that there exist unseen blocks in the data and this is an error source for the estimation of Hn. Again, as the exact values of p(b(n) i) are not known, Eq. (13) can not be used to compute ˆ Cnfor a given sequence S. The Good-Turing estimator [31] can be used as an estimate for the sample coverage, ˆ CGT n= 1 −N(n) 1 Nn ,(14) where N(n) 1is the number of blocks of size nthat appear only once in the sequence S. Substituting Eq. (12) into Eq. (11) and using Eq. (14), one finds the Chao-Shen entropy estimator ˆ HCS n=−X b(n) i∈S ˆ CGT nˆpMLE(b(n) i) log( ˆ CGT nˆpMLE(b(n) i)) 1−(1 −ˆ CGT nˆpMLE(b(n) i))Nn , (15) which has proven to provide very good results for independent sequences. However, we show below that Eq. (15) does not work so well for correlated data as happens in systems with memory. This is our motivation to present an improved estimator that does take into account correlations. C. Correlation coverage estimator Our proposal follows Eq. (12) but ˆ Cnis now estimated using a sequential procedure to tackle possible correlations in the sequence. First, we consider the initial part of the sequence, namely S0= (X1, X2, . . . , XN1), with N1≡ n−1 + Nn/2, such that S0contains exactly Nn/2≡N0 n blocks of size n. We adopt the initial estimator ˆ C(0) n= 1. After observing all the blocks B(n) j=1,...,N0 nthat appear in S0, we take the next observation B(n) +1 (we adopt the simplifying notation B(n) +k≡B(n) N0 n+k, 1 ≤k≤N0 n), and modify the sample coverage according to ˆ C(1) n=   ˆ C(0) nif B(n) +1 ∈ S0, ˆ C(0) n−1 N0 n+ 1 if B(n) +1 6∈ S0,(16) here the factor 1/(N0 n+ 1) accounts for the probability that the observed block B(n) +1 appears for the first time. We repeat the process with the next observation B(n) +2 to modify the estimator ˆ C(2) n=   ˆ C(1) nif B(n) +2 ∈ S+1, ˆ C(1) n−1 N0 n+ 2 if B(n) +2 6∈ S+1,(17) where S+i=S0∪(XN1+1, . . . , XN1+i). At variance with the coverage given by Eq. (14), which is obtained 5 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 n 0 5 10 15 20 H H MLE H CS H CC FIG. 3. Exact Shannon entropy per block of size n(dotted line) for a particular case of a Markovian binary system with fixed transition probabilities p(0|0) = 0.7 and p(1|1) = 0.6. A sequence of N= 104realizations is numerically generated from which we calculate three different entropy estimators discussed in the main text. The best performance is shown for the estimator that takes into account correlations (red dots). from a single observation from the whole series, this procedure has the advantage of iteratively updating ˆ C(k) n, k= 0,1,2, . . . , N0 nbased on the previously observed data. We continue with this procedure until we arrive at the final value of the correlation coverage (CC) estimator ˆ CCC n≡ˆ C(N0 n) n= 1 − N0 n X j=1 1 N0 n+jIB(n) +j6∈ S+(j−1), (18) where the indicator function I(Z) yields 1 if the event Z is true and 0 otherwise. Finally, we substitute the corrected probabilities into Eq. (11) to obtain the correlation coverage-adjusted entropy estimator ˆ HCC n=−X b(n) i∈S ˆ CCC nˆpMLE(b(n) i) log( ˆ CCC nˆpMLE(b(n) i)) 1−(1 −ˆ CCC nˆpMLE(b(n) i))Nn . (19) As an example, in Fig. 3we show the exact entropy Hn(dashed black line and dots) as a function of the block size for a Markovian (m= 1) binary process that takes the values z= 0,1, with transition probabilities P0≡p(0|0) = P(Xs= 0|Xs−1= 0) = 0.7 and P1≡p(1|1) = P(Xs= 1|Xs−1= 1) = 0.6. Note that, as expected, Hnis linear from n≥1. To compare with, we also depict the results obtained with the maximum-likelihood estimators given by Eq. (8) (green line and dots), the Chao-Shen estimator of Eq. (15) (blue line and dots) and our coverage-adjusted estimator proposed in Eq. (19) (red line and dots), all calculated from a sequence of N= 104elements generated numerically. Notably, the proposed estimator performs better than both the MLE and Chao-Shen entropies and perfectly agrees with the exact result for a wide range of block sizes up to n.17 while the MLE and the Chao-Shen estimators deviate earlier from the exact Hn. In fact, the MLE estimator provides a good approximation up to a value of n.12 which is close to the expected limit n∼log(N)/log(L)∼13, while the validity of the Chao- Shen estimator extends up to n.13 and our estimator even further. In Cwe present a similar comparison for sequences with memory 2 and 3. Departures from the exact value will show up only in the extremely undersampled regime (NnLn). In this case, every observation will constitute a different element. As a consequence, the sum in Eq. (19) will include all blocks in the second part and ˆ CCC n= 1 −PN0 n j=1 1 N0 n+j≃ 1−ln(2) ≃0.307, for large N. The proximity of the computed estimator to this limiting value indicates a largely undersampled sequence and determines the validity of the estimators to the coverage Cn. For a more detailed comparison, we show in panel (a) of Fig. 4the performance of the Chao-Shen estimator given by Eq. (15), and in panel (b) that of the our correlation estimator from Eq. (19), both calculated for a process with m= 1 and L= 2. We show the results as a function of all possible combinations of transition probabilities P0and P1, the remaining probabilities being derived from the normalization conditions p(1|0) = 1 −P0 and p(0|1) = 1−P1. We measure the goodness of each estimator for particular values of P0and P1with the mean squared error (P0, P1)≡1 nmax Pnmax n=1 (Hn−ˆ Hn)2. To improve the statistics of the error, for each set of transition probabilities (P0, P1) we generate M= 20 series, each with N= 104elements, and average the mean squared error over the Mvalues. We use in all cases nmax = 17 and plot the resulting values in a color code. As shown in the figure, quite generally, Eq. (19) performs better than Eq. (15), with the possible exception of the cases near P0, P1≈1/2 (the independent case with equal outcome probability), in which the latter is slightly better. The overall performance is obtained by adding all values of (P0, P1) using a grid size ∆P= 0.1 in Fig. 4, resulting in an aggregated mean squared error five times larger for the Chao-Shen estimator as compared with the correlation coverage-adjusted estimator. IV. DETERMINATION OF THE MEMORY OF A SEQUENCE Having demonstrated the usefulness of the estimator given by Eq. (19) for Markovian systems, we now return to the method of Sec. II for the determination of the memory in discrete sequences. Suppose we are given a finite time series Sthat describes a phenomenon for which we would like to determine its memory m. As explained above, we will use the criterion given by Eq. (7) after computing ∆µfollow- 6 0.1 0.3 0.5 0.7 0.9 p (0|0) 0.0 0.2 0.4 0.6 0.8 1.0 p (1|1) 0.00 0.05 0.10 0.15 a) 0.1 0.3 0.5 0.7 0.9 p (0|0) 0.0 0.2 0.4 0.6 0.8 1.0 p (1|1) 0.00 0.05 0.10 0.15 b) FIG. 4. Comparison between the Chao-Shen entropy, panel (a), and our proposed estimator for correlated systems, panel (b). Calculations are done for a binary system with memory m= 1 and varying transition probabilities p(0|0) ≡P0 and p(1|1) ≡P1. Colors represent the departure of each estimator (computed from 104realizations) from the exact entropy, as measured by the mean squared error (P0, P1)≡ 1 nmax Pnmax n=1 (Hn−ˆ Hn)2with nmax = 17. Adding all values for (P0, P1) using the grid size ∆P= 0.1, we find that the overall error reaches a value of 4.65 in (a) but only of 0.90 in (b). ing Eqs. (5,6) and using a suitable estimator ˆ Hnfor the block entropy Hn. For a given entropy estimator with a known nmax and fixed Nand L, a meaningful linear fit for the calculation of ∆µas given by Eq. (6) requires that µ≤nmax −2 (at least three points are required for a meaningful fit to a straight line). Since the chosen entropy estimator works for block sizes up to nmax, our method can provide in principle an accurate result if the system under study has memory m≤nmax −2 but would fail otherwise. In Figs. 3and C1 we have shown evidence that nCC max > nMLE max. Hence, there exist three regimes for the estimation of the memory m: i) if m≤nMLE max −2, the fit to a straight line works with both MLE and CC entropy estimators; ii) if nMLE max −2< m ≤nCC max −2, the MLE estimator is insufficient; iii) if m>nCC max−2 the memory is exceedingly large and both estimators are inadequate. It is worth mentioning that, in general, the value of nmax for a certain estimator is not the same for every sequence since nmax may depend on the transition probabilities. To be conservative, in this section we use nCC max =nMLE max even though our estimator certainly provides good results for larger block sizes. Due to the limitations of all estimators we expect that ∆µis determined within an error that must be taken into account. To do so, we consider Mseries of data S(i), i = 1, . . . , M, all with the same length, obtained either by repeating the experiment Mtimes or by splitting the original series in Mdisconnected sequences. For each sequence we calculate the corresponding value of ∆(i) µ. Then, we calculate the mean ¯ ∆µand standard deviation σµfor the obtained values ∆(i) µ. The condition given by Eq. (7) is transformed into the criterion that the mean value ¯ ∆µis consistent with the value 0 within the standard deviation, m= min(µ:¯ ∆µ−σµ≤0).(20) A. Numerical simulation We first present results arising from controlled numerical simulations. We generate M= 20 series of length N= 1000 with memory m= 1 and possible values z= 0,1 (L= 2). We show only results corresponding to p(0|0) = 0.7 and p(1|1) = 0.6 but similar conclusions are obtained quite generally for different values of the transition probabilities. In Fig. 5we plot the values of ¯ ∆µobtained using the method explained above. In Fig. 5(a) we employ the MLE estimator for the block entropy, while Fig. 5(b) uses the correlation coverage-adjusted estimator. Remarkably, the MLE entropy is not able to yield any useful result, and it is thus not possible to determine the sequence memory since Eq. (20) is never satisfied. In stark contrast, the calculation of ¯ ∆µand σµusing the entropy estimator given by Eq. (19) clearly shows that the criterion Eq. (20) yields the correct result m= 1. In Fig. 6(a) and (b) we present results arising from similar numerical simulations as before but now generating sequences with memory m= 2 and m= 5, respectively (same values of M,Nand Las before) and transition probabilities chosen randomly from an uniform distribution in the interval (0,1). We plot the values of ¯ ∆µobtained using the correlation coverage-adjusted estimator for the entropy. Again, the usage of our proposed entropy estimator allows us to accurately determine the memory of the system. Similar conclusions are generally obtained for a different set of transition probabilities. These numerical experiments illustrate the importance of having a reliable entropy estimator to successfully apply the method of memory determination. 7 0123 μ 0.0 0.2 0.4  Δ μ aΔ 0123 μ 0.0 0.1 0.2  Δ μ bΔ FIG. 5. Mean squared error ¯ ∆µas a function of the trial entropy with nmax = 10 after averaging over M= 20 realizations of a Markov chain with N= 1000 data points, memory m= 1 and transition probabilities p(0|0) = 0.7 and p(1|1) = 0.6. In panel a) we use the MLE estimator while panel b) is generated with the correlation coverage-adjusted estimator. Error bars are given by the standard deviation. Importantly, our proposed estimator clearly yields the memory value m= 1 applying Eq. (20). B. Daily precipitations We have thus far tested our proposed method only with numerically generated sequences of known memories. We now test the method with real data. It has been widely accepted that the occurrence (or not) of precipitation can be modeled as a system of memory 1, but it is also well known that this assumption has several shortcomings [32]. There have been some attempts to improve this model by studying sequences of daily data worldwide. It has been found [33] that the model memory depends on the geographical location. Here, we select a few locations and compare the results with those obtained using the BIC method [34]. We collect data from the Global Historical Climatology Network Daily [35]. For each location, we record the available observation for daily precipitation, setting the threshold at 0.1 mm to specify if a day is rainy or not. This way we produce a time series with two states (L= 2) and length Ns.25000 (the exact value of Nsvaries for each location). Then, this series is divided in M= 5 sequences of equal lengths N=Ns/5 and for each of this sequence we estimate the block entropies ˆ HCC nfor n= 1,...,12, from which we obtain the mean values ¯ ∆µand their standard deviations σµ. It should be noted that the use of the correlation coverage estimator for the entropy 0123456 μ 0.00 0.25 0.50 0.75  Δ μ aΔ 0123456 μ 0.0 0.2 0.4  Δ μ bΔ FIG. 6. Mean squared error ¯ ∆µas a function of the trial entropy with nmax = 10 after averaging over M= 20 realizations of a Markov chain with N= 1000 data points, transition probabilities chosen randomly from an uniform distribution in the interval (0,1) and memory m= 2 panel a), and m= 5, panel b), using the method explained in the main text with correlation coverage-adjusted estimator. Error bars are given by the standard deviation. Importantly, in both cases, our proposed entropy estimator clearly yields the right memory value applying Eq. (20). allows us to obtain reliable results up to nmax = 12. If we had used the MLE estimator, this limit value would have been nmax ∼11. In Fig. 7we show the results obtained for four locations: Rome, Dallas, Bangkok and Than Lwin. For the first two locations, our method predicts m= 1 whereas for the second two places the procedure suggests that both series are better described with m= 2. These results are in excellent agreement with the BIC method (see Fig. 5 in Ref. [33]) and consequently validate our technique for the memory determination in real data sequences modeled with Markov chains of arbitrary order. V. CONCLUSIONS We have developed a novel method to determine the memory of a discrete sequence. Importantly, the method is valid for both Markovian and non-Markovian systems. Since the technique relies on the calculation of the Shannon entropy as a function of the block size, it is crucial to additionally propose an entropy estimator that gives good results for correlated systems. To this end, we have introduced a correction to the estimated probabilities to amend the source of error stemming from unseen ele- 8 0123 μ 0.0 0.2 0.4 0.6  Δ μ aΔ 0123 μ 0.00 0.05 0.10  Δ μ bΔ 0123 μ 0.0 0.5 1.0 1.5  Δ μ cΔ 0123 μ 0 1 2 3  Δ μ Δ) FIG. 7. Results of the method explained in Section II applied to sequences of data of daily precipitations for four locations: (a) Rome-Italy, (b) Dallas-USA, (c) Bangkok-Thailand and (d) Than Lwin-Myanmar. ments in small samples. Our estimator is shown to significantly increase the accuracy of the entropy for systems with memory. Both numerically generated sequences and real data series have been used as benchmarks. These successful results will certainly encourage further applications of the proposals discussed in this work. It is left as a future project to present a more detailed comparison of our entropy estimator with different estimators that have shown promising results for independent sequences [36–39]. ACKNOWLEDGEMENTS Partial financial support has been received from MCIN/AEI/10.13039/501100011033 and the Fondo Europeo de Desarrollo Regional (FEDER, UE) through project PACSS (RTI2018-093732-B-C21), APASOS (PID2021-122256NB-C21) and the Mar´ıa de Maeztu Program for units of Excellence in R&D, grant MDM-2017- 0711. [1] David Roxbee Cox and Hilton David Miller, The theory of stochastic processes (Routledge, 2017). [2] A. A. Markov, “An example of statistical investigation of the text Eugene Onegin concerning the connection of samples in chains,” Science in Context 19, 591–600 (2006). [3] C. W. Gardiner, Handbook of stochastic methods for Physics, Chemistry and the Natural Sciences (Springer, Berlin, 1965). [4] Gary A. Churchill, “Stochastic models for heterogeneous DNA sequences,” Bulletin of Mathematical Biology 51, 79–94 (1989). [5] D. S. Wilks and R. L. Wilby, “The weather generation game: a review of stochastic weather models,” Progress in Physical Geography: Earth and Environment 23, 329– 357 (1999). [6] Lawrence Page, Sergey Brin, Rajeev Motwami, and Terry Winograd, The PageRank citation ranking: Bringing order to the Web, Technical Report 1999-66 (Stanford InfoLab, 1999). [7] Peter H¨anggi and Harry Thomas, “Stochastic processes: Time evolution, symmetries and linear response,” Physics Reports 88, 207–319 (1982). [8] ZA Mayzelis, SS Apostolov, SS Melnyk, OV Usatenko, and VA Yampol’skii, “Additive N-step Markov chains as prototype model of symbolic stochastic dynamical systems with long-range correlations,” Chaos, Solitons & Fractals 34, 112–128 (2007). [9] Adrian E. Raftery, “A model for high-order Markov chains,” Journal of the Royal Statistical Society: Series B (Methodological) 47, 528–539 (1985). [10] Renat M Yulmetyev, Sergey A Demin, O Yu Panischev, Peter H¨anggi, Serge F Timashev, and Grigoriy V Vstovsky, “Regular and stochastic behavior of Parkinsonian pathological tremor signals,” Physica A: Statistical Mechanics and its Applications 369, 655–678 (2006). [11] Dung T Ho and Tru H Cao, “A high-order hidden Markov model for emotion detection from textual data,” in Pacific rim knowledge acquisition workshop (Springer, 2012) pp. 94–105. [12] Michael Seifert, Andr´e Gohr, Marc Strickert, and Ivo Grosse, “Parsimonious higher-order hidden Markov models for improved array-CGH analysis with applications to Arabidopsis Thaliana,” PLoS computational biology 8, e1002286 (2012). [13] Philipp Singer, Denis Helic, Behnam Taraghi, and Markus Strohmaier, “Detecting memory and structure in human navigation patterns using Markov chain models of varying order,” PloS one 9, e102070 (2014). [14] Hugues Meyer and Heiko Rieger, “Optimal non- Markovian search strategies with n-step memory,” Phys. Rev. Lett. 127, 070601 (2021). [15] Christopher C. Strelioff, James P. Crutchfield, and Alfred W. H¨ubler, “Inferring markov chains: Bayesian estimation, model comparison, entropy rate, and out-of-class modeling,” Phys. Rev. E 76, 011106 (2007). [16] Hirotogu Akaike, “Information theory and an extension of the maximum likelihood principle,” in Selected papers of hirotugu akaike (Springer, 1998) pp. 199–213. [17] Howell Tong, “Determination of the order of a Markov chain by Akaike’s information criterion,” Journal of applied probability 12, 488–497 (1975). [18] Richard W Katz, “On some criteria for estimating the order of a Markov chain,” Technometrics 23, 243–249 (1981). [19] David L Weakliem, “A critique of the Bayesian information criterion for model selection,” Sociological Methods & Research 27, 359–397 (1999). [20] Armin O Schmitt and Hanspeter Herzel, “Estimating the entropy of DNA sequences,” Journal of theoretical biology 188, 369–377 (1997). 9 [21] Anne Chao and Tsung-Jen Shen, “Nonparametric estimation of Shannon’s diversity index when there are unseen species in sample,” Environmental and Ecological Statistics 10, 429–443 (2003). [22] Olle H¨aggstr¨om et al.,Finite Markov chains and algorithmic applications, Vol. 52 (Cambridge University Press, 2002). [23] B Pompe, “On some entropy methods in data analysis,” Chaos, Solitons & Fractals 4, 83–96 (1994). [24] C. E. Shannon, “A mathematical theory of communication,” Bell System Technical Journal 27, 379–423 (1948). [25] Sanghyun Park and Vijay S Pande, “Validation of Markov state models using Shannon’s entropy,” The Journal of chemical physics 124, 054118 (2006). [26] T.M. Cover and J.A. Thomas, Elements of Information Theory (John Wiley and Sons, 2006). [27] Thomas Sch¨urmann, “Bias analysis in entropy estimation,” Journal of Physics A: Mathematical and General 37, L295–L301 (2004). [28] Liam Paninski, “Estimation of entropy and mutual information,” Neural Computation 15, 1191–1253 (2003). [29] Lianet Contreras Rodr´ıguez, Evaristo Jos´e Madarro- Cap´o, Carlos Miguel Leg´on-P´erez, Omar Rojas, and Guillermo Sosa-G´omez, “Selecting an effective entropy estimator for short sequences of bits and bytes with maximum entropy,” Entropy 23 (2021), 10.3390/e23050561. [30] D. G. Horvitz and D. J. Thompson, “A generalization of sampling without replacement from a finite universe,” Journal of the American Statistical Association 47, 663– 685 (1952). [31] I.J. Good, “The population frequencies of species and the estimation of population parameters,” Biometrika 40, 237–64 (1953). [32] Hui Wan, Xuebin Zhang, and Elaine M. Barrow, “Stochastic modelling of daily precipitation for Canada,” Atmosphere-Ocean 43, 23–32 (2005). [33] Sarah Wilson Kemsley, Timothy J. Osborn, Stephen R. Dorling, Craig Wallace, and Joanne Parker, “Selecting Markov chain orders for generating daily precipitation series across different K¨oppen climate regimes,” International Journal of Climatology 41, 6223–6237 (2021). [34] Gideon Schwarz, “Estimating the dimension of a model,” The Annals of Statistics 6, 461–464 (1978). [35] Matthew J Menne, Imke Durre, Russell S Vose, Byron E Gleason, and Tamara G Houston, “An overview of the global historical climatology network-daily database,” Journal of atmospheric and oceanic technology 29, 897– 910 (2012). [36] Ilya Nemenman, F. Shafee, and William Bialek, “Entropy and inference, revisited,” in Advances in Neural Information Processing Systems, Vol. 14, edited by T. Dietterich, S. Becker, and Z. Ghahramani (MIT Press, 2001). [37] Evan W Archer, Il Memming Park, and Jonathan W Pillow, “Bayesian entropy estimation for binary spike train data using parametric prior knowledge,” in Advances in Neural Information Processing Systems, Vol. 26, edited by C.J. Burges, L. Bottou, M. Welling, Z. Ghahramani, and K.Q. Weinberger (Curran Associates, Inc., 2013). [38] Jean Hausser and Korbinian Strimmer, “Entropy inference and the James-Stein estimator, with application to nonlinear gene association networks,” Journal of Machine Learning Research 10, 1469–1484 (2009). [39] Peter Grassberger, “On Generalized Sch¨urmann Entropy Estimators,” Entropy 24 (2022), 10.3390/e24050680. Appendix A 1. Proof that if a sequence has memory m, then Hnis a linear function for n≥m Since we consider only homogeneous sequences we will omit the time variable in this appendix. We will use the notation p(x1, . . . , xs)≡P(X1=x1, . . . , Xs=xs), with xi∈ {zj}1≤j≤L. Let us calculate the difference between the block entropies Hn+1 −Hn. Using p(x1, . . . , xn+1) = p(xn+1|x1, . . . , xn)p(x1, . . . , xn), we obtain Hn+1 −Hn=−X x1,...,xn+1 p(x1, . . . , xn+1) log(p(x1, . . . , xn+1)) + X x1,...,xn p(x1, . . . , xn) log(p(x1, . . . , xn)) =−X x1,...,xn+1 p(x1, . . . , xn+1) log(p(xn+1|x1, . . . , xn)) −X x1,...,xn+1 p(x1, . . . , xn+1) log(p(x1, . . . , xn))+ +X x1,...,xn p(x1, . . . , xn) log(p(x1, . . . , xn)). (A1) Because P xn+1 p(x1, . . . , xn+1) = p(x1, . . . , xn), the last two terms of the Eq. (A1) cancel out. Thus, Hn+1 −Hn=−X x1,...,xn+1 p(x1, . . . , xn+1) log(p(xn+1|x1, . . . , xn)).(A2) This is a general result, valid for any kind of sequence. Now, for a sequence of memory mand for n≥m, one has