An $n$-code is a mapping $c_n$ from the set $A^n$ of sequences of length $n$ drawn from a finite set $A$ into the set of finite length binary sequences $B^\ast$. A decoder with distortion $D$ is a map from $B^\ast$ back into $A^n$ that sends $c_n(a^n_1)$ into a sequence that agrees with $a^n_1$ in all but at most $Dn$ places. We describe a sequence of codes and associated decoders of distortion $D$ such that, for almost every sequence from an ergodic process, the number of bits per $A$-symbol converges almost surely to $R(D)$, the optimal compression attainable for the process. The codes are universal in that the statistics of the process need not be known in advance. Expected value results of this type were first obtained by Davisson and, independently, Fittinghof; almost sure results for the invertible case $(D = 0)$ are implicitly contained in the Ziv-Lempel algorithm. Our results also apply, virtually without change in proof, to random fields.
"Universal Almost Sure Data Compression." Ann. Probab. 18 (2) 441 - 452, April, 1990. https://doi.org/10.1214/aop/1176990840