Time-universal data compression and prediction
Abstract
Suppose there is a large file which should be transmitted (or stored) and there are several (say, ) admissible data-compressors. It seems natural to try all the compressors and then choose the best, i.e. the one that gives the shortest compressed file. Then transfer (or store) the index number of the best compressor (it requires bits) and the compressed file. The only problem is the time, which essentially increases due to the need to compress the file times (in order to find the best compressor). We propose a method that encodes the file with the optimal compressor, but uses a relatively small additional time: the ratio of this extra time and the total time of calculation can be limited by an arbitrary positive constant.
Generally speaking, in many situations it may be necessary find the best data compressor out of a given set, which is often done by comparing them empirically. One of the goals of this work is to turn such a selection process into a part of the data compression method, automating and optimizing it.
A similar result is obtained for the related problem of time-series forecasting.
I Introduction and preliminaries
I-A General description of the problems and results
Nowadays there are many efficient lossless data-compressors (or archivers) which are widely used in information technologies. These compressors are based on different ideas and approaches, among which we note the PPM universal code [1] (which is used along with the arithmetic code [2]), the Lempel-Ziv (LZ) compression methods [3], the Burrows-Wheeler transform [4] (which is used along with the book-stack (or MTF) code [5, 6, 7]) and the class of grammar-based codes [8, 9]. All these codes are universal. This means that, asymptotically, the length of the compressed file goes to the smallest possible value (i.e. the Shannon entropy per letter), if the compressed sequence is generated by a stationary source.
Currently, several dozens of archivers are known, each of which has certain merits and it is impossible to single out one of the best or even remove the worst ones. The main part of them are universal codes (as far as a computer program can meet asymptotic properties). Thus, the one faces the problem of choosing the best method to compress a given file.
Suppose someone wants to compress a certain file in order to store it (or transfer it). It seems natural to use for compression the best compressor: the one which gives the shortest compressed file. In such a case one can try to compress the file in turn by all the compressors and then store the name of the best compressor (as a prefix) and the file, compressed by the best method. An obvious drawback of this approach is the need to spend a lot of time in order to first compress the file by all the compressors.
In this paper we show that there exists a method that encodes the file with the optimal compressor, but uses a relatively small additional time. Very briefly, the main idea of the suggested approach is as follows: in order to find the best, try all the archivers, but, when doing it, use for compression only a small part of the file. Then apply the best archiver for the compression of the whole file. It turns out, that under certain conditions on the source of the files, the total time can be made as close to the minimal as required. Thus, we call such methods ”time-universal”. This scheme can be extended to the problem of time-series forecasting, which is considered in a framework of the Laplace approach (This approach is shortly described in Appendix 2.)
In this paper we suggest time-universal methods for data compression and forecasting. To the best of our knowledge, the suggested approach to prediction and compression is new, but close ideas have been considered in algorithmic information theory and artificial intelligence, where they were developed for solving other problems [10, 11].
I-B The over-fitting problem
If someone wants to find the best method of prediction or data compression, she/he should take into account the so-called over-fitting problem. The over-fitting problem is the phenomenon in which the accuracy of the model on unseen data is poor whereas the training accuracy is nearly perfect.
In our case, there is a set of either data compressors or predictors . Besides, there is a sequence , and one should choose a good method from the set of predictors (or data compressors) based on investigating of a short initial part In the case of data compression, it is natural to choose such a method , for which is minimal. In the case of forecasting, it is natural to choose such a predictor for which the probability is maximal (the maximum likelihood principle.)
In this situation the problem of over-fitting is as follows: if is a relatively short sequence and the set of methods is large or even infinite, it is possible that a performance of the chosen method on is good, but on the whole sequence it is bad. The over-fitting problem for prediction is similar: the error of the chosen predictor on unseen data is large whereas the training error is nearly zero.
We consider a solution to this problem based on the approach developed in the theory of universal coding [12, 13], but note that a similar solution can be obtained in the framework of MDL (minimal description length) method suggested by J. Rissanen [14, 15] and developed in numerous papers [16, 17, 18]. For this we need such a probability distribution on the set for which all . For example, the following:
| (1) |
(Clearly, this is a probability distribution, because .) The described approach to problem of over-fitting is to find a data-compressor for which is minimal: . Note that, if the set of data-compressors is finite, it is possible to use an uniform distribution , . It is worth noting that there is a natural interpretation of the considered solution. The value can be considered as a codeword length, where the first part encodes the number , whereas the second part encodes by the data compressor .
In the case of prediction the solution of the over-fitting problem is similar: find a predictor for which is maximal.
II Description of problems and the main notations
In this section we first consider the following problem: There is a set of data compressors and let be a sequence of letters from a finite alphabet whose initial part should be compressed by some . Let, as before, be the time spent on encoding one letter by the data compressor and suppose that all are upper-bounded by a certain constant , i.e. (Note, that can be unknown beforehand, but should be known.)
The goal is to find a good data compressor from in order to compress in such a way that the total time spent for all calculations and compressions does not exceed , where is the minimum time that must be reserved for compression and is an additional time that can be used to find the good compressor (among ). In order to accurately describe the problem, we suppose also that there is a probability distribution such that all . The goal is to fined such that the value
is close to minimal. (Here the first part is used for encoding number .) The decoder first finds and then using the decoder corresponding .
Definition 1
We call any method that encodes a sequence , , , by the binary word of the length for some , a time-adaptive code and denote it by . The output of is the following word:
| (2) |
where is -bit word that encodes , whereas the time of encoding is not grater than .
If for a time-adaptive code the following equation is valid
this code is called time-universal.
The definition for the forecast is as follows: Let there be a set of predictors . By definition, the goal of the time-adaptive predictor is to spend the extra time in order to find such that the value
is close to maximal. By definition, the output of the time-adaptive predictor is the following set of forecasts (conditional probabilities):
for a certain . It will be convenient to define
| (3) |
If for a predictor the following equation is valid
and, for any , time of calculation is not grater than this predictor is called time-universal.
Comment 1. Here and below we did not take into account the time required for the calculation of and some other auxiliary calculations. If in a certain situation this time is not negligible, it is possible to reduce in advance by the required value.
III Finite number of data-compressors or predictors
Suppose that there is a file and data compressors , . Let, as before, be the time spent on encoding one letter by the data compressor ,
| (4) |
and let
| (5) |
The goal is to find the data compressor , , that compresses the file in the best way in time . Seemingly, the simplest method is as follows:
Step 1 Calculate .
Step 2 Compress the file by and find the length of compressed file , then , likewise, find , , etc.
Step 3 Calculate
Step 4 Compress the whole file by and compose the codeword , where is -bit word with the presentation of .
The decoding is obvious. Denote this method by .
Comment 2. We considered the case of data compression. It is possible to apply the described method for time-universal prediction. In this case one should calculate instead of and the third step should be changed as follows:
Calculate
The asymptotic properties of the method are as follows:
Claim 1. Let there be an infinite sequence and data compressors such that there exist the following limits
| (6) |
for all . Then, for any
i.e. is time-universal.
Next we describe a more general method, for which Claim 1 is a special case.
IV General method
Generally speaking, it is possible to offer many reasonable strategies for finding the optimal data compressor (or predictor) for a given time. For the finite set of data-compressors such a strategy can be as follows: try all the compressors on a (very) short sequence and choose a few of the best ones. Then try those chosen data-compressors on a larger sequence , , and choose the best which will be used for compression of the whole sequence . Another reasonable strategy can be based on maximization of the probability to determine the optimal data compressor as a function of the extra time and other parameters.
So, we can see that there are a lot of reasonable strategies and each of them has a lot of parameters. That is why, it could be useful to use multidimensional optimization methods, such as machine learning, so-called deep learning, etc. Since this is the first paper devoted to time-adaptive and time-universal data compression and prediction, we consider only some general conditions needed for time-universality.
For a time-adaptive data-compressor and we define for any
Theorem 1
If the following properties are valid:
i) for all
| (7) |
ii) for any the method uses such a compressor for which, for any and
| (8) |
iii) the limits exist for all .
Then is time universal, i.e., in a case of data compression,
| (9) |
A proof is given in Appendix 1, but here we note that Claim 1 is a particular case of this theorem.
Comment 3. If the sequence is generated by a stationary source and all are universal codes, the property iii) is valid with probability 1 (See, for example, [19]). Hence, this theorem (and the claim 1) are valid for this case.
In general, the property iii) shows that the sequence under consideration has some stability. In turn, it gives a possibility to estimate characteristics of the whole sequence based on its initial part.
V The time-universal code for stationary ergodic sources
In this subsection we describe a time-universal code (and the corresponding predictor) for stationary sources. It is based on optimal universal codes for Markov chains, developed by Krichevsky [20, 21] and the twice-universal code [12]. Denote by , the set of Markov chains with memory (connectivity) , and let be the set of Bernoulli sources. For stationary ergodic and an integer we denote by the -order entropy (per letter) and let be the limit entropy; see for definitions [19].
Krichevsky [20, 21] described the codes which are asymptotically optimal for , correspondingly. If the sequence , , is generated by a source , the following inequalities are valid almost surely (a.s.):
| (10) |
where grows. (Here is a constant.) The length of a codeword of the twice-universal code is defined as the following ”mixture”:
| (11) |
(It is well-known in Information Theory [19] that there exists a code with such codeword lengths, because .) This code is called twice-universal because for any , , and the equality (10) is valid (with different ). Besides, for any stationary ergodic source a.s.
| (12) |
Let us estimate the time of calculations necessary when using . First, note that it suffices to sum a finite number of terms in (11), because all the terms are equal for . On the other hand, the number of different terms grows, where and, hence, the encoder should calculate for growing number ’s. It is known [12] that the time spent for encoding one letter is close for different codes . Hence, the time spent for encoding one letter by the code grows to infinity, when grows. The described below time-universal code has the same asymptotic performance, but the time spent for encoding one letter is a constant.
In order to describe the time-universal code we give some definitions. Let, as before, be an upper-bound of the time spent for encoding one letter by any , be the generated word,
| (13) |
Denote by the following method:
Step 1 Calculate and
Step 2 Find such a that
Step 3 Calculate the codeword and output
where is the -bit codeword of .
The decoding is obvious.
Theorem 2
Let be a sequence generated by a stationary source and the code be applied. Then this code is time-universal, i.e. a.s.
| (14) |
In the case of prediction
A proof is given in Appendix 1.
VI Conclusion
Here we note some possible generalisations. We consider mainly the case of off-line prediction and data compression, where the whole sequence can be investigated in order to find a suitable data-compressor or predictor. There are situations where the forecast should be made step-by-step, i.e. should be predicted based on , should be predicted based on and so on. The suggested approach and methods can be naturally extended to this case, too, if we take into account the possibility to store results of calculations done on previous steps.
Another generalization is connected with the need to know in advance the speed of computing the forecast (or data compression). In such a case the goal of time-universal method can be the same: it should limit the time of calculation by , where is (unknown beforehand) the time of the optimal method (from a given set). In such a case the speeds can be evaluated during the calculation.
VII Appendix 1
Proof of Theorem 1. Define , and let
| (15) |
Let be any positive number. Having taken into account that the set is finite, from these definitions we can see that there exists such that
| (16) |
Taking into account the property i), we can see that there exists such a number for which is defined for all and , and denote . Take any and suppose that a data-compressor was chosen, when was applied to . Hence, from the property ii) we can see that there exists , such that
| (17) |
From (15) we obtain the following two inequalities
Having taken into account (17) we can see from the two latest inequalities that and, hence, . Taking into account, that, by definition (15), , we obtain
| (18) |
Since , we can see from (16) that
Taking into account that we obtain from (18) that
and, hence,
It is true for any , hence, . The theorem is proven.
Proof of Theorem 2. It is known in Information Theory [19] that for any and (by definition) . Let and be such an integer that . From (V) we can see that there exists such that if . Taking into account (10) and (V), we can see that there exists for which a.s. if . From the description of (the step 3) we can see that there exists such for which a.s.
if . By definition,
Having taken into account that is an arbitrary number and two latest inequalities as well as the fact that a.s. , we obtain (14). The theorem is proven.
VIII Appendix 2: The Laplace approach to prediction
Let there be a source with unknown statistics which generates sequences of letters from some finite alphabet . Let the source generate a message , , and the following letter needs to be predicted. This problem can be traced back to Laplace who considered the problem of estimation of the probability that the sun will rise tomorrow, given that it has risen every day since Creation [22]. In our notation the alphabet contains two letters, (“the sun rises”) and (“the sun does not rise” ); is the number of days since Creation,
Laplace suggested the following predictor:
| (19) |
where denotes the count of letter occurring in the word For example, if , then the Laplace prediction is as follows: In other words, and are estimations of the unknown probabilities and (In what follows we will use the shorter notation: and We can see that Laplace considered prediction as a set of estimations of unknown (conditional) probabilities, because they contain all information about the future behaviour of any stochastic process. In general, we call as a predictor any conditional probabilities defined for all integers , , .
Acknowledgment
This work was supported by Russian Foundation for Basic Research (grant 15-07-01851).
References
- [1] J. Cleary and I. Witten, “Data compression using adaptive coding and partial string matching,” IEEE transactions on Communications, vol. 32, no. 4, pp. 396–402, 1984.
- [2] J. Rissanen and G. G. Langdon, “Arithmetic coding,” IBM Journal of research and development, vol. 23, no. 2, pp. 149–162, 1979.
- [3] J. Ziv and A. Lempel, “A universal algorithm for sequential data compression,” IEEE Transactions on information theory, vol. 23, no. 3, pp. 337–343, 1977.
- [4] M. Burrows and D. J. Wheeler, “A block-sorting lossless data compression algorithm,” 1994.
- [5] B. Y. Ryabko, “Data compression by means of a “book stack”,” Problemy Peredachi Informatsii, vol. 16, no. 4, pp. 16–21, 1980.
- [6] J. Bentley, D. Sleator, R. Tarjan, and V. Wei, “ A locally adaptive data compression scheme,” Communications of the ACM, vol. 29, no. 4, pp. 320–330, 1986.
- [7] B. Ryabko, N. R. Horspool, G. V. Cormack, S. Sekar, and S. B. Ahuja, “Technical correspondence,” Communications of the ACM, vol. 30, no. 9, pp. 792–797, 1987.
- [8] J. C. Kieffer and E.-H. Yang, “Grammar-based codes: a new class of universal lossless source codes,” IEEE Transactions on Information Theory, vol. 46, no. 3, pp. 737–754, 2000.
- [9] E.-H. Yang and J. C. Kieffer, “Efficient universal lossless data compression algorithms based on a greedy sequential grammar transform. i. without context models,” IEEE Transactions on Information Theory, vol. 46, no. 3, pp. 755–777, 2000.
- [10] M. Li and P. Vitanyi, An Introduction to Kolmogorov Complexity and Its Applications, 3rd edition. New York: Springer, 2008.
- [11] M. Hutter, Universal Artificial Intelligence: Sequential Decisions based on Algorithmic Probability. Berlin: Springer, 2005.
- [12] B. Ryabko, “Twice-universal coding,” Problems of Information Transmission, vol. 3, pp. 173–177, 1984.
- [13] ——, “Prediction of random sequences and universal coding,” Problems of Information Transmission, vol. 24, pp. 87–96, 1988.
- [14] J. J. Rissanen, “Modeling by shortest data description.” Automatica, vol. 14, pp. 465–471, 1978.
- [15] ——, Stochastic Complexity in Statistical Inquiry. World Scientific Publ. Co., 1989.
- [16] A. Barron, J. Rissanen, and B. Yu, “The mdl principle in modeling and coding’, special issue of ieee trans,” Information Theory to commemorate, vol. 50, pp. 2743–2760, 1998.
- [17] P. Grünwald, The Minimum Description Length Principle. The MIT Press, Cambridge, 2007.
- [18] P. Kontkanen, P. Myllymäki, T. Silander, H. Tirri, and P. Grünwald, “On predictive distributions and bayesian networks,” Statistics and Computing, vol. 10, no. 1, pp. 39–54, 2000.
- [19] T. M. Cover and J. A. Thomas, Elements of information theory. New York, NY, USA: Wiley-Interscience, 2006.
- [20] R. Krichevsky, “A relation between the plausibility of information about a source and encoding redundancy,” Problems Inform. Transmission, vol. 4, no. 3, pp. 48–57, 1968.
- [21] ——, Universal Compression and Retrival. Kluwer Academic Publishers, 1993.
- [22] W. Feller and P. M. Morse, “An introduction to probability theory and its applications,” Physics Today, vol. 11, p. 32, 1958.
- [23] B. Ryabko,“Compression-based methods for nonparametric prediction and estimation of some characteristics of time series,” IEEE Transactions on Information Theory, vol. 55, pp. 4309–4315, 2009.