format: text

text:
# Source Coding, Large Deviations, and Approximate Pattern Matching

## 1 Introduction

### 1.1 Lossless Data Compression

It is probably only a slight exaggeration to say that the central piece of mathematics in the proof of almost any lossless coding theorem is provided by the Asymptotic Equipartition Property, or AEP. Suppose we want to (losslessly) compress a message $`X_1^n=(X_1,X_2,\mathrm{},X_n)`$ generated by a stationary memoryless source $`𝑿=\{X_n;n1\}`$ where each $`X_i`$ takes values in the finite alphabet $`A`$ (much more general situations will be considered later). For this source, the AEP states that as $`n\mathrm{}`$

$`{\displaystyle \frac{1}{n}}\mathrm{log}_2P^n(X_1^n)H\text{in probability}`$ (1)
where $`P`$ is the common distribution of the independent and identically distributed (i.i.d.) random variables $`X_i`$, $`P^n`$ denotes the (product) joint distribution of $`X_1^n`$, and $`H=E[\mathrm{log}_2P(X_1)]`$ is the entropy rate of the source – see Shannon’s original paper \[68, Theorem 3\] or Cover and Thomas’ text \[20, Chapter 4\]. \[Here and throughout the paper, $`\mathrm{log}_2`$ denotes the logarithm taken to base 2, and $`\mathrm{log}`$ denotes the natural logarithm.\] From (1) we can immediately extract some useful information: It implies that when $`n`$ is large the message $`X_1^n`$ will most likely have probability at least as high as $`2^{n(H+ϵ)}`$:

$`P^n(X_1^n)2^{n(H+ϵ)}\text{with high probability.}`$ (2)
But there cannot be many high-probability messages. In fact, there can be at most $`2^{n(H+ϵ)}`$ messages with $`P^n(X_1^n)2^{n(H+ϵ)}`$, so we need approximately $`2^{nH}`$ representative messages from the source $`𝑿`$ in order to cover our bets (with high probability). If we let $`𝒯_n`$ be the set of high-probability strings $`x_1^nA^n`$ having $`P^n(x_1^n)2^{n(H+ϵ)}`$, then with high probability we can correctly represent the source output $`X_1^n`$ by an element of $`𝒯_n`$. Since there are no more than $`2^{n(H+ϵ)}`$ of them, we need no more than $`nH`$ bits to correctly encode $`X_1^n`$.

##### Shannon’s Random Code.

Another way to extract information from (1) is as follows. The fact that for large $`n`$ we typically have $`P^n(X_1^n)2^{nH}`$ also means that if we independently generate another random string, say $`Y_1^n`$, from the same distribution as the source, the probability that $`X_1^n`$ is the same as $`Y_1^n`$ is about $`2^{nH}`$. Suppose that instead of using the strings in $`𝒯_n`$ above as our representatives for the source, we decided to independently generate a collection of random strings $`Y_1^n`$ from the distribution $`P^n`$; how many would we need? Given a source string $`X_1^n`$, the probability that any one of the $`Y_1^n`$ matches it is $`2^{nH}`$, so in order to have high probability of success in representing $`X_1^n`$ without error we should choose approximately $`2^{n(H+ϵ)}`$ random strings $`Y_1^n`$. Therefore, whether we choose the set of representatives systematically or randomly, we always need about $`2^{nH}`$ strings in order to be able to encode $`X_1^n`$ losslessly with high probability. Note that the randomly generated set $`𝒯_n`$ is nothing but Shannon’s random codebook  specialized to the case of lossless compression.

##### Idealized Lempel-Ziv Coding.

In 1989, in a very influential paper , Wyner and Ziv took the above argument several steps further. Aiming to “obtain insight into the workings of \[…\] the Lempel-Ziv data compression algorithm,” they considered the following coding scenario: Suppose that an encoder and a decoder both have available to them a long database, say an infinitely long string $`Y_1^{\mathrm{}}=(Y_1,Y_2,\mathrm{})`$ that is independently generated from the same distribution as the source. Given a source string $`X_1^n`$ to be transmitted, the encoder looks for the first appearance of $`X_1^n`$ in the database (assuming, for now, that it does appear somewhere). Let $`W`$ denote the position of this first appearance, that is, let $`W`$ be the smallest integer for which $`Y_W^{W+n1}=(Y_W,Y_{W+1},\mathrm{},Y_{W+n1})`$ is equal to $`X_1^n`$. Then all the encoder has to do is it to tell the decoder the value of $`W`$; the decoder can read off the string $`Y_W^{W+n1}`$ and recover $`X_1^n`$ perfectly. This description can be given using (cf. ) no more than

$`\mathrm{}(X_1^n)=\mathrm{log}_2W+O(\mathrm{log}_2\mathrm{log}_2W)\text{bits.}`$ (3)
How good is this scheme? First note that, for any given source string $`X_1^n`$, the random variable $`W`$ records the first “success” in a sequence of trials (“Is $`Y_1^n=X_1^n`$?,” “Is $`Y_2^{n+1}=X_1^n`$?,” and so on), each of which has probability of success $`p=P^n(X_1^n)`$. Although these trials are not independent, for large $`n`$ they are almost independent (in a sense that will be made precise below), so the distribution of $`W`$ is close to a geometric with parameter $`p=P^n(X_1^n)`$. For long strings $`X_1^n`$ (i.e., for large $`n`$) $`p`$ is small, and $`W`$ is typically close to its expected value, which is approximately equal to the mean of a geometric random variable with parameter $`p`$, namely $`1/p`$. But the AEP tells us that, when $`n`$ is large, $`p=P^n(X_1^n)2^{nH}`$, so we expect $`W`$ to be typically around $`2^{nH}`$. Hence, from (3) the description length $`\mathrm{}(X_1^n)`$ of $`X_1^n`$ will be, to first order,

$$\mathrm{}(X_1^n)\mathrm{log}_2P^n(X_1^n)nH\text{bits, with high probability.}$$

This shows that above scheme is asymptotically optimal, in that its limiting compression ratio is equal to the entropy.

##### Practical Lempel-Ziv Coding.

The Lempel-Ziv algorithm  and its many variants (see, e.g., \[4, Ch. 8\]) are some of the most successful data compression algorithms used in practice. Roughly speaking, the main idea behind these algorithms is to use the message’s own past as a database for future encoding. Instead of looking for the first match in an infinitely long database, in practice the encoder looks for the longest match in a database of fixed length. The analysis in  of the idealized scheme described above was the first step in providing a probabilistic justification for the optimality of the actual practical algorithms. Subsequently, in  and  Wyner and Ziv established the asymptotic optimality of the Sliding-Window (SWLZ) and the Fixed-Database (FDLZ) versions of the algorithm.

### 1.2 Lossy Data Compression

A similar development to the one outlined above can be given in the case of lossy data compression, this time centered around a lossy analog of the AEP . To motivate this discussion we look at Shannon’s original random coding proof of the (direct) lossy source coding theorem .

##### Shannon’s Random Code.

Suppose we want to describe the output $`X_1^n`$ of a memoryless source, with distortion $`D`$ or less with respect to a family of single-letter distortion measures $`\{\rho _n\}`$. Let $`Q_n^{}`$ be the optimum reproduction distribution on $`\widehat{A}^n`$, where $`\widehat{A}`$ is the reproduction alphabet. Shannon’s random coding argument says that we should construct a codebook $`𝒯_n`$ of $`2^{n(R(D)+ϵ)}`$ codewords $`Y_1^n`$ generated i.i.d. from $`Q_n^{}`$, where $`R(D)`$ is the rate-distortion function of the source (in bits). The proof that $`2^{n(R(D)+ϵ)}`$ codewords indeed suffice is based on the following result, Lemma 1 in .

Shannon’s “Lemma 1”: For $`x_1^nA^n`$ let $`B(x_1^n,D)`$ denote the distortion-ball of radius $`D`$ around $`x_1^n`$, i.e., the collection of all reproduction strings $`y_1^n\widehat{A}^n`$ with $`\rho _n(x_1^n,y_1^n)D`$. When $`n`$ is large:111The notation in Shannon’s statement is slightly different, and he considers the more general case of ergodic sources. For the sake of clarity we restrict attention here to the i.i.d. case.

$`Q_n^{}(B(X_1^n,D))2^{n(R(D)+ϵ)}\text{with high probability.}`$ (4)
In the proof of the coding theorem this lemma plays the same role that the AEP played in the lossless case; notice the similarity between (4) and its analog (2) in the lossless case.

Let’s fix a source string $`X_1^n`$ to be encoded. The probability that $`X_1^n`$ matches any one of the codewords $`Y_1^n`$ in $`𝒯_n`$ is

$$\mathrm{Pr}\{\rho _n(X_1^n,Y_1^n)D|X_1^n\}=\mathrm{Pr}\{Y_1^nB(X_1^n,D)|X_1^n\}=Q_n^{}(B(X_1^n,D))$$

and by the lemma this probability is at least $`2^{n(R(D)+ϵ)}`$. Therefore, with $`2^{n(R(D)+ϵ)}`$ independent codewords to choose from, we have a good chance for finding a match with distortion $`D`$ or less.

##### Generalized AEP and Applications.

A stronger and more general version of Lemma 1 will be our starting point in this paper. In the following section we will prove a generalized AEP: For any product measure $`Q^n`$ on $`\widehat{A}^n`$

$`{\displaystyle \frac{1}{n}}\mathrm{log}Q^n(B(X_1^n,D))R_1(P,Q,D)\text{w.p.1}`$ (5)
where $`R_1(P,Q,D)`$ is a (non-random) function of the distributions $`P`$ and $`Q`$ and of the distortion level $`D`$. \[We will later prove several variants of (5) under much weaker assumptions.\]

Like the AEP in the lossless case, the generalized AEP and its refinements find numerous applications in data compression, universal data compression, and in general pattern-matching questions. Many of these applications were inspired by the treatment in Wyner and Ziv’s 1989 paper . A (very incomplete) sample of subsequent work in the Wyner-Ziv spirit includes the papers  on lossy data compression, and  on pattern-matching.

Aaron Wyner himself remained active in this field for the following ten years, and his last paper , co-written with J. Ziv and A.J. Wyner, was a review paper on this subject. In the present paper we review the corresponding developments in the lossy case, and in the process we add new results (and some new proofs of recent results) in an attempt to present a more complete picture.

### 1.3 Central Themes, Paper Outline

In Section 2 we give an extensive discussion of the generalized AEP. By now there are numerous different proofs under different assumptions, and we offer a streamlined approach to the most general versions using techniques from large deviation theory (cf.  and Bucklew’s earlier work ). We also discuss the relationship of the generalized AEP with the classical extensions of the AEP (due to Barron  and Orey ) to processes with densities. We establish a formal connection between these two by looking at the limit of the distortion level $`D0`$.

In Section 3 we develop applications of the generalized AEP to a number of related problems. We show how the generalized AEP can be used to determine the asymptotic behavior of Shannon’s random coding scheme, and we discuss the role of mismatch in lossy data compression. We also determine the first order asymptotic behavior of waiting times and longest match-lengths between stationary processes. The main ideas used here are strong approximation  and duality . We present strengthened versions of Shannon’s direct lossy source coding theorem (and of a corresponding universal coding theorem), showing that almost all random codebooks achieve essentially the same compression performance. A lossy version of the Lempel-Ziv algorithm is recalled, which achieves optimal compression performance (asymptotically) as well as polynomial complexity at the encoder. We also discuss how the classical source coding problem can be generalized to a question about weighted sphere-covering. The answer to this question gives, as corollaries, Shannon’s coding theorems, Stein’s lemma in hypothesis testing, and some converse concentration inequalities.

Section 4 is devoted to second order refinements of the AEP and the generalized AEP. It is shown, for example, that under certain conditions $`\mathrm{log}P^n(X_1^n)`$ and $`\mathrm{log}Q^n(B(X_1^n,D))`$ are asymptotically Gaussian. These refinements are used in Section 5 to provide corresponding second order results (such as central limit theorems) for the applications considered in Section 3. We prove second order asymptotic results for waiting times and longest match-lengths. Precise redundancy rates are given for Shannon’s random code, and converse coding theorems show that the random code achieves the optimal pointwise redundancy, up to terms of order $`(\mathrm{log}n)`$. For i.i.d. sources the pointwise redundancy is typically of order $`\sigma \sqrt{n}`$, where $`\sigma `$ is the minimal coding variance of the source. When $`\sigma =0`$ these fluctuations disappear, and the best pointwise redundancy is of order $`(\mathrm{log}n)`$. The question of exactly when $`\sigma `$ can be equal to zero is briefly discussed.

Finally, Sections 6 and 7 contain generalizations of some of the above results to random fields. All the results stated there are new, although most of them are straightforward generalizations of corresponding one-dimensional results.

## 2 The Generalized AEP

### 2.1 Notation and Definitions

We begin by introducing some basic definitions and notation that will remain in effect for the rest of the paper. We will consider a stationary ergodic process $`𝑿=\{X_n;n\}`$ taking values in a general alphabet $`A`$.222To avoid uninteresting technicalities, we will assume throughout that $`A`$ is a complete, separable metric space, equipped with its associated Borel $`\sigma `$-field $`𝒜`$. Similarly we take $`(\widehat{A},\widehat{𝒜})`$ to be the Borel measurable space corresponding to a complete, separable metric space $`\widehat{A}`$. When talking about data compression, $`𝑿`$ will be our source and $`A`$ will be called the source alphabet. We write $`X_i^j`$ for the vector of random variables $`X_i^j=(X_i,X_{i+1},\mathrm{},X_j)`$, and similarly $`x_i^j=(x_i,x_{i+1},\mathrm{},x_j)A^{ji+1}`$ for a realization of these random variables, $`\mathrm{}ij\mathrm{}`$. We let $`P_n`$ denote the marginal distribution of $`X_1^n`$ on $`A^n`$ ($`n1`$), and write $``$ for the distribution of the whole process. Similarly, we take $`𝒀=\{Y_n;n\}`$ to be a stationary ergodic process taking values in the (possibly different) alphabet $`\widehat{A}`$.2 In the context of data compression, $`\widehat{A}`$ is the reproduction alphabet and $`𝒀`$ has the “codebook” distribution. We write $`Q_n`$ for the marginal distribution of $`Y_1^n`$ on $`\widehat{A}^n`$, $`n1`$, and $``$ for the distribution of the whole process $`𝒀`$. We will always assume that the process $`𝒀`$ is independent of $`𝑿`$.

Let $`\rho :A\times \widehat{A}[0,\mathrm{})`$ be an arbitrary nonnegative (measurable) function, and define a sequence of single-letter distortion measures $`\rho _n:A^n\times \widehat{A}^n[0,\mathrm{})`$ by

$`\rho _n(x_1^n,y_1^n)\stackrel{\mathrm{}}{=}{\displaystyle \frac{1}{n}}{\displaystyle \underset{i=1}{\overset{n}{}}}\rho (x_i,y_i)x_1^nA^n,y_1^n\widehat{A}^n.`$
Given $`D0`$ and $`x_1^nA^n`$, we write $`B(x_1^n,D)`$ for the distortion-ball of radius $`D`$ around $`x_1^n`$:

$$B(x_1^n,D)=\{y_1^n\widehat{A}^n:\rho _n(x_1^n,y_1^n)D\}.$$

Throughout the paper, $`\mathrm{log}`$ denotes the natural logarithm and $`\mathrm{log}_2`$ the logarithm to base 2. Unless otherwise mentioned, all familiar information-theoretic quantities (such as the entropy, mutual information, and so on) are assume to be defined in terms of natural logarithms (and are therefore given in nats).

### 2.2 Generalized AEP When $`𝒀`$ is I.I.D.

In the case when $`A`$ is finite, the classical AEP, also known as the Shannon-McMillan-Breiman theorem (see \[20, Chapter 15\] or the original papers ), states that as $`n\mathrm{}`$

$`{\displaystyle \frac{1}{n}}\mathrm{log}P_n(X_1^n)H()\text{w.p.1}`$ (6)
where

$$H()\stackrel{\mathrm{}}{=}\underset{n\mathrm{}}{lim}\frac{1}{n}H(X_1^n)$$

is the entropy rate of the process $`𝑿`$ (in nats, since we are taking logarithms to base $`e`$). As we saw in the Introduction, in lossy data compression the role of the AEP is taken up by the result of Shannon’s “Lemma 1” and, more generally, by statements of the form

$$\frac{1}{n}Q_n(B(X_1^n,D))R(,,D)\text{w.p.1}$$

for some non-random “rate-function” $`R(,,D)`$.

First we consider the simplest case where $`𝒀`$ is assumed to be an i.i.d. process. We write $`Q=Q_1`$ for its first order marginal, so that $`Q_n=Q^n`$, for $`n1.`$ Similarly we write $`P=P_1`$ for the first order marginal of $`𝑿`$. Let

$`D_{\mathrm{min}}`$ $`\stackrel{\mathrm{}}{=}`$ $`E_P[\underset{YQ}{\mathrm{ess}\mathrm{inf}}\rho (X,Y)]`$ (7)
$`D_{\mathrm{av}}`$ $`\stackrel{\mathrm{}}{=}`$ $`E_{P\times Q}[\rho (X,Y)].`$ (8)
\[Recall that the essential infimum of a function $`g(Y)`$ of the random variable $`Y`$ with distribution $`Q`$ is defined as $`\mathrm{ess}\mathrm{inf}_{YQ}g(Y)=sup\{t:Q\{g(Y)>t\}=1\}.`$\]

Clearly $`0D_{\mathrm{min}}D_{\mathrm{av}}`$. To avoid the trivial case when $`\rho (x,y)`$ is essentially constant for ($``$-almost) all $`xA`$, we assume that with positive $``$-probability $`\rho (x,y)`$ is not essentially constant in $`y`$, that is:

$`D_{\mathrm{min}}<D_{\mathrm{av}}.`$ (9)
Note also that for $`D`$ greater than $`D_{\mathrm{av}}`$, the probability $`Q^n(B(X_1^n,D))1`$ as $`n\mathrm{}`$ (this is easy to see by the ergodic theorem), so we restrict our attention to distortion levels $`D<D_{\mathrm{av}}`$.

Theorem 1. Generalized AEP when $`𝐘`$ is i.i.d.: Let $`𝑿`$ be a stationary ergodic process and $`𝒀`$ be i.i.d. with marginal distribution $`Q`$ on $`\widehat{A}`$. Assume that $`D_{\mathrm{av}}=E_{P\times Q}[\rho (X,Y)]`$ is finite. Then for any $`D(D_{\mathrm{min}},D_{\mathrm{av}})`$

$`{\displaystyle \frac{1}{n}}\mathrm{log}Q^n(B(X_1^n,D))R_1(P,Q,D)\text{w.p.1}.`$
The rate-function $`R_1(P,Q,D)`$ is defined as

$`R_1(P,Q,D)=\underset{W}{inf}H(WP\times Q)`$
where $`H(WV)`$ denotes the relative entropy between two distributions $`W`$ and $`V`$,

$$H(WV)\stackrel{\mathrm{}}{=}\{\begin{array}{cc}E_W[\mathrm{log}\frac{dW}{dV}]\hfill & \text{if the density }\frac{dW}{dV}\text{ exists},\hfill \\ \mathrm{}\hfill & \text{otherwise}\hfill \end{array}$$

and the infimum is taken over all joint distributions $`W`$ on $`A\times \widehat{A}`$ such that the first marginal of $`W`$ is $`P`$ and $`E_W[\rho (X,Y)]D.`$

Example 1: The rate-function $`R_1(P,Q,D)`$ when $`Q`$ is Gaussian: Although in general the rate-function $`R_1(P,Q,D)`$ cannot be evaluated explicitly, here we show that it is possible to obtain an exact expression for $`R_1(P,Q,D)`$ in the special case when $`\rho (x,y)=(xy)^2`$, $`𝑿`$ is a real-valued, process, and $`Q`$ is a Gaussian measure on $`.`$ Specifically, assume that $`𝑿`$ is a zero-mean, stationary ergodic process with finite variance $`\sigma ^2=\text{Var}(X_1)<\mathrm{}`$, and take $`Q`$ to be a zero-mean Gaussian measure with variance $`\tau ^2`$, i.e., $`QN(0,\tau ^2)`$. Under these assumptions, it is easy to see that $`D_{\mathrm{min}}=0`$ and $`D_{\mathrm{av}}=\sigma ^2+\tau ^2`$. Moreover, with the help of Proposition 2 below, $`R_1(P,Q,D)`$ can be explicitly evaluated as:

$$R_1(P,Q,D)=\{\begin{array}{cc}\mathrm{},\hfill & D=0\hfill \\ \frac{1}{2}\mathrm{log}\left(\frac{v}{D}\right)\frac{(vD)(v\sigma ^2)}{2v\tau ^2},\hfill & \mathrm{\hspace{0.33em}\hspace{0.33em}\hspace{0.33em}\hspace{0.33em}0}<D<\sigma ^2+\tau ^2\hfill \\ 0,\hfill & D\sigma ^2+\tau ^2\hfill \end{array}$$

where

$$v\stackrel{\mathrm{}}{=}\frac{1}{2}\left[\tau ^2+\sqrt{\tau ^4+4D\sigma ^2}\right].$$

We will come back to this example when considering mismatched rate-distortion codebooks in Section 3.2.

Remark 1: In more familiar information-theoretic terms, the rate-function $`R_1(P,Q,D)`$ can equivalently be defined as (cf. )

$`R_1(P,Q,D)=\underset{(X,Y)}{inf}[I(X;Y)+H(Q_YQ)]`$
where $`I(X;Y)`$ denotes the mutual information (in nats) between the random variables $`X`$ and $`Y`$, and the infimum is over all jointly distributed random variables $`(X,Y)`$ with values in $`A\times \widehat{A}`$ such that $`X`$ has distribution $`P`$, $`E[\rho (X,Y)]D`$, and $`Q_Y`$ denotes the distribution of $`Y`$.

Remark 2: The assumption that $`𝒀`$ is i.i.d. is clearly restrictive and it will be relaxed below. On the other hand the assumptions on the distortion measure $`\rho `$ seem to be minimal; we simply assume that $`\rho `$ has finite expectation (in the more general results below $`\rho `$ is assumed to be bounded). In this form, the result of Theorem 1 is new.

Discussion of Proof: Let’s fix a realization $`x_1^{\mathrm{}}`$ of $`𝑿`$. The probability $`Q^n(B(X_1^n,D))`$ can be written as

$$\text{Pr}\left\{Y_1^nB(X_1^n,D)\right|X_1^n=x_1^n\}=\text{Pr}\left\{\frac{1}{n}\underset{i=1}{\overset{n}{}}\rho (x_i,Y_i)D\right\}.$$

Since the distortion level $`D`$ is taken smaller than the average value $`D_{\mathrm{av}}`$, this is large deviations probability for the partial sums $`(1/n)_{i=1}^nZ_i`$ of the independent (but not identically distributed) random variables $`Z_i=\rho (x_i,Y_i)`$. The proof is essentially an application of the Gärtner-Ellis theorem of large deviations to the random variables $`\{Z_i\}`$.

Proof Outline: Choose and fix a realization $`x_1^{\mathrm{}}`$ of $`𝑿`$ and define the random variables $`Z_i=\rho (x_i,Y_i)`$. Let

$$S_n=\frac{1}{n}\underset{i=1}{\overset{n}{}}Z_i$$

and define the log-moment generating functions of the normalized partial sums $`S_n`$ by

$$\mathrm{\Lambda }_n(\lambda )\stackrel{\mathrm{}}{=}\mathrm{log}E_{Q^n}\left(e^{\lambda S_n}\right),\lambda 0.$$

Then for any $`\lambda 0`$, by the ergodic theorem we have that

$`{\displaystyle \frac{1}{n}}\mathrm{\Lambda }_n(n\lambda )={\displaystyle \frac{1}{n}}{\displaystyle \underset{i=1}{\overset{n}{}}}\mathrm{log}E_Q\left(e^{\lambda \rho (x_i,Y_i)}\right)\mathrm{\Lambda }(\lambda )\stackrel{\mathrm{}}{=}E_P\left[\mathrm{log}E_Q\left(e^{\lambda \rho (X,Y)}\right)\right]`$ (10)
for $``$-almost any realization $`x_1^{\mathrm{}}`$. Now we would like to apply the Gärtner-Ellis theorem, but first we need to check some simple properties of the function $`\mathrm{\Lambda }(\lambda )`$. Note that $`\mathrm{\Lambda }(\lambda )0`$ and also (by Jensen’s inequality) $`\mathrm{\Lambda }(\lambda )\lambda D_{\mathrm{av}}>\mathrm{}`$, for all $`\lambda 0`$. Moreover, $`\mathrm{\Lambda }(\lambda )`$ is twice differentiable in $`\lambda `$ with

$$\mathrm{\Lambda }^{}(\lambda )=E_{P\times Q}\left(\rho (X,Y)\frac{e^{\lambda \rho (X,Y)}}{E_Q[e^{\lambda \rho (X,Y^{})}]}\right)$$

and

$$\mathrm{\Lambda }^{\prime \prime }(\lambda )=E_P\left[E_Q\left\{\rho ^2(X,Y)\frac{e^{\lambda \rho (X,Y)}}{E_Q[e^{\lambda \rho (X,Y^{})}]}\right\}\left(E_Q\left\{\rho (X,Y)\frac{e^{\lambda \rho (X,Y)}}{E_Q[e^{\lambda \rho (X,Y^{})}]}\right\}\right)^2\right]$$

(this differentiability is easily verified by an application of the dominated convergence theorem). By the Cauchy-Schwarz inequality $`\mathrm{\Lambda }^{\prime \prime }(\lambda )0`$ for all $`\lambda <0`$, and in fact $`\mathrm{\Lambda }^{\prime \prime }(\lambda )`$ is strictly positive due to assumption (9). Also it is not hard to verify that

$$\underset{\lambda 0}{lim}\mathrm{\Lambda }^{}(\lambda )=D_{\mathrm{av}}$$

and

$`\underset{\lambda \mathrm{}}{lim}\mathrm{\Lambda }^{}(\lambda )=D_{\mathrm{min}}.`$ (11)
Since $`D(D_{\mathrm{min}},D_{\mathrm{av}})`$, there exists a unique $`\lambda ^{}<0`$ with $`\mathrm{\Lambda }^{}(\lambda ^{})=D`$, and therefore the Fenchel-Legendre transform of $`\mathrm{\Lambda }(\lambda )`$ evaluated at $`D`$ is

$$\mathrm{\Lambda }^{}(D)\stackrel{\mathrm{}}{=}\underset{\lambda 0}{sup}[\lambda D\mathrm{\Lambda }(\lambda )]=\lambda ^{}D\mathrm{\Lambda }(\lambda ^{}).$$

Now we can apply the Gärtner-Ellis theorem \[25, Theorem 2.3.6\] to deduce from (10) that with $``$-probability one

$$\frac{1}{n}\mathrm{log}Q^n(B(X_1^n,D))\mathrm{\Lambda }^{}(D).$$

The proof is complete upon noticing that $`\mathrm{\Lambda }^{}(D)`$ is nothing but $`R_1(P,Q,D)`$. This is stated and proved in the following proposition. $`\mathrm{}`$

Proposition 2. Characterization of the Rate Function: In the notation of the proof of Theorem 1, $`\mathrm{\Lambda }^{}(D)=R_1(P,Q,D)`$, for $`D(D_{\mathrm{min}},D_{\mathrm{av}})`$.

Proof Outline: Under additional assumptions on the distortion measure $`\rho `$ this has appeared in various papers (see, e.g., ). For completeness, we offer a proof sketch here.

In the notation of the above proof, consider the measure $`W`$ on $`A\times \widehat{A}`$ defined by

$$\frac{dW(x,y)}{dP\times Q}=\frac{e^{\lambda ^{}\rho (x,y)}}{E_Q[e^{\lambda ^{}\rho (x,Y)}]}.$$

Obviously the first marginal of $`W`$ is $`P`$ and it is easy to check that that $`E_W[\rho (X,Y)]=\mathrm{\Lambda }^{}(\lambda ^{})=D`$. Therefore, by the definitions of $`R_1(P,Q,D)`$ and $`W`$, and by the choice of $`\lambda ^{}`$:

$`R_1(P,Q,D)H(WP\times Q)=\lambda ^{}D\mathrm{\Lambda }(\lambda ^{})=\mathrm{\Lambda }^{}(D).`$ (12)
To prove the corresponding lower bound we first claim that for any measurable function $`\varphi :\widehat{A}(\mathrm{},0]`$, and any probability measure $`Q^{}`$ on $`\widehat{A}`$,

$`H(Q^{}Q)E_Q^{}(\varphi (Y))\mathrm{log}E_Q(e^{\varphi (Y)}).`$ (13)
Let $`Q_\varphi `$ denote the probability measure on $`\widehat{A}`$ such that $`dQ_\varphi /dQ=e^\varphi /E_Q(e^{\varphi (Y)})`$. Clearly, it suffices to prove (13) in case $`dQ^{}/dQ`$ exists, in which case the difference between the left and right hand sides is

$$E_Q^{}\left\{\mathrm{log}\frac{dQ^{}}{dQ}\right\}E_Q^{}\left\{\mathrm{log}\left(\frac{e^\varphi }{E_Q(e^\varphi )}\right)\right\}=H(Q^{}Q_\varphi )\mathrm{\hspace{0.33em}0}.$$

Given an arbitrary candidate $`W`$ as in the definition of $`R_1(P,Q,D)`$ and any $`xA`$, we take $`Q^{}=W(|x)`$ and $`\varphi (y)=\lambda ^{}\rho (x,y)`$ in (13) to get that

$$H(W(|x)Q())\lambda ^{}E_{W(Y|x)}[\rho (x,Y)]\mathrm{log}E_Q(e^{\lambda ^{}\rho (x,y)}).$$

Substituting $`X`$ for $`x`$, taking expectations of both sides with respect to $`P`$, and recalling that $`\lambda ^{}<0`$ and $`E_W[\rho (X,Y)]D`$, we get:

$$H(WQ)\lambda ^{}D\mathrm{\Lambda }(\lambda ^{})=\mathrm{\Lambda }^{}(D).$$

Since $`W`$ was arbitrary it follows that $`R_1(P,Q,D)\mathrm{\Lambda }^{}(D)`$, and together with (12) this completes the proof. $`\mathrm{}`$

### 2.3 Generalized AEP When $`𝒀`$ is Not I.I.D.

Next we present two versions of the generalized AEP that hold when $`𝒀`$ is a stationary dependent process, under some additional conditions.

Throughout this section we will assume that the distortion measure is essentially bounded

$`D_{\mathrm{max}}\stackrel{\mathrm{}}{=}\underset{(X_1,Y_1)P_1\times Q_1}{\mathrm{ess}\mathrm{sup}}\rho (X_1,Y_1)<\mathrm{}.`$ (14)
We let $`D_{\mathrm{av}}`$ be defined as earlier, $`D_{\mathrm{av}}=E_{P_1\times Q_1}[\rho (X_1,Y_1)]`$, and for $`n1`$ we let

$`D_{\mathrm{min}}^{(n)}\stackrel{\mathrm{}}{=}E_{P_n}\left[\underset{Y_1^nQ_n}{\mathrm{ess}\mathrm{inf}}\rho _n(X_1^n,Y_1^n)\right].`$
It is easy to see that $`nD_{\mathrm{min}}^{(n)}`$ is a finite, superadditive sequence, and therefore we can also define

$$D_{\mathrm{min}}=\underset{n\mathrm{}}{lim}D_{\mathrm{min}}^{(n)}=\underset{n1}{sup}D_{\mathrm{min}}^{(n)}.$$

As before, we will assume that the distortion measure $`\rho `$ is not essentially constant, that is, $`D_{\mathrm{min}}<D_{\mathrm{av}}.`$

We first state a version of the generalized AEP that was recently proved by Chi , for processes $`𝒀`$ satisfying a rather strong mixing condition: We say that the stationary process $`𝒀`$ is $`\psi ^\pm `$-mixing, if for all $`d`$ large enough there is a finite constant $`c_d`$ such that

$$c_d^1(A)(B)<(AB)<c_d(A)(B)$$

for all events $`A\sigma (Y_{\mathrm{}}^0)`$ and $`B\sigma (Y_d^{\mathrm{}})`$, where $`\sigma (Y_i^j)`$ denotes the $`\sigma `$-field generated by $`Y_i^j`$. Recall the usual definition according to which $`𝒀`$ is called $`\psi `$-mixing if in fact the constants $`c_d1`$ as $`d\mathrm{}`$; see  for more details. Clearly $`\psi ^\pm `$-mixing is weaker than $`\psi `$-mixing.

Theorem 3. Generalized AEP when $`𝐘`$ is $`\psi ^\pm `$-mixing : Let $`𝑿`$ and $`𝒀`$ be stationary ergodic processes. Assume that $`𝒀`$ is $`\psi ^\pm `$-mixing, and that the distortion measure $`\rho `$ is bounded. Then for all $`D(D_{\mathrm{min}},D_{\mathrm{av}})`$

$`{\displaystyle \frac{1}{n}}\mathrm{log}Q_n(B(X_1^n,D))R(,,D)\text{w.p.1}`$ (15)
where $`R(,,D)`$ is the rate-function defined by

$`R(,,D)=\underset{n\mathrm{}}{lim}R_n(P_n,Q_n,D)`$ (16)
where, for $`n1`$,

$`R_n(P_n,Q_n,D)\stackrel{\mathrm{}}{=}\underset{V_n}{inf}n^1H(V_nP_n\times Q_n)`$
and the infimum is taken over all joint distributions $`V_n`$ on $`A^n\times \widehat{A}^n`$ such that the $`A^n`$-marginal of $`V_n`$ is $`P_n`$ and $`E_{V_n}[\rho _n(X_1^n,Y_1^n)]D`$.

As we discussed in the previous section, the proof of most versions of the generalized AEP consistst of two steps: First a “conditional large deviations” result is proved for the random variables $`\{\rho _n(x_1^n,Y_1^n);n1\}`$, where $`x_1^{\mathrm{}}`$ is a fixed realization of the process $`𝑿`$. Second, the rate-function $`R(,,D)`$ is characterized as the limit of a sequence of minimizations in terms of relative entropy.

In a subseqeunt paper, Chi  showed that the first of these steps (the large deviations part) remains valid under a condition weaker than $`\psi ^\pm `$-mixing, condition $`(S)`$ of . In the following theorem we give a general version of the second step; we prove that the generalized AEP (15) and the formula (16) for the rate-function remain valid as long as the random variables $`\{\rho _n(x_1^n,Y_1^n);n1\}`$ satisfy a large deviations principle (LDP) with some deterministic, convex rate-function (see  for the precise meaning of this statement).

Theorem 4. Let $`𝑿`$ and $`𝒀`$ be stationary processes. Assume that $`\rho `$ is bounded, and that with $``$-probability one, conditional on $`X_1^{\mathrm{}}=x_1^{\mathrm{}}`$, the random variables $`\{\rho _n(x_1^n,Y_1^n);n1\}`$ satisfy a large deviations principle with some deterministic, convex rate-function. Then, both (15) and (16) hold for any $`D(D_{\mathrm{min}},D_{\mathrm{av}})`$, except possibly at the point $`D=D_{\mathrm{min}}^{(\mathrm{})}`$, where

$`D_{\mathrm{min}}^{(\mathrm{})}\stackrel{\mathrm{}}{=}inf\{D0:\underset{n1}{sup}R_n(P_n,Q_n,D)<\mathrm{}\}.`$ (17)
Since Theorem 4 has an exact analog in the case of random fields, we postpone its proof until the proof of the corresponding result (Theorem 27) in Section 6.

Remark 3: Suppose that the joint process $`(𝑿,𝒀)`$ is stationary, and that it satisfies a “process-level large deviations principle” (see Remark 6 in Section 6 for a somewhat more detailed statement) on the space of stationary probability measures on $`(A^{\mathrm{}}\times \widehat{A}^{\mathrm{}})`$ equipped with the topology of weak convergence. Assume, moreover, that this LDP holds with a convex, good rate-function $`I()`$. \[See \[26, Sec. 5.3, 5.4\]\[25, Sec. 6.5.3\] for a general discussion as well as specific examples of processes for which the above conditions hold. Apart from the i.i.d. case, these examples also include all ergodic finite-state Markov chains, among many others.\]

It is easy to check that, when $`\rho `$ is bounded and continuous on $`A\times \widehat{A}`$, then with $``$-probability one, conditional on $`x_1^{\mathrm{}}`$, the random variables $`\{\rho _n(x_1^n,Y_1^n)\}`$ satisfy the LDP upper bound with respect to the deterministic, convex rate-function $`J(D)=infI(\nu )`$, where the infimum is over all stationary probability measures $`\nu `$ on $`A^{\mathrm{}}\times \widehat{A}^{\mathrm{}}`$ such that the $`A^{\mathrm{}}`$-marginal of $`\nu `$ is $``$ and $`E_\nu [\rho (X_1,Y_1)]=D`$. Indeed, Comets  provides such an argument when $`𝑿`$ and $`𝒀`$ are both i.i.d. Moreover, he shows that in that case the corresponding LDP lower bound also holds, and hence Theorem 4 applies. Unfortunately, the conditional LDP lower bound has to be verified on a case-by-case basis.

Remark 4: Although quite strong, the $`\psi ^\pm `$-mixing condition of Theorem 3, and the $`(S)`$-mixing condition of , probably cannot be significantly relaxed: For example, in the special case when $`𝑿`$ is a constant process taking on just a single value, if Theorem 3 were to hold (for any bounded distortion measure) with a strictly monotone rate-function, then necessarily the empirical measures of $`Y_1^n`$ would satisfy the LDP in the space $`𝒫_a(\widehat{A})`$ (see  for details). But \[12, Example 1\] illustrates that this LDP may fail even when $`𝒀`$ is a stationary ergodic Markov chain with discrete alphabet $`\widehat{A}`$. In particular, the example in  has an exponential $`\varphi `$-mixing rate.

### 2.4 Generalized AEP for Optimal Lossy Compression

Here we present a version of the generalized AEP that is useful in proving direct coding theorems. Let $`𝑿`$ be a stationary ergodic process. For the distortion measure $`\rho `$ we adopt two simple regularity conditions. We assume the existence of a reference letter, i.e., an $`\widehat{a}\widehat{A}`$ such that

$$E_{P_1}[\rho (X_1,\widehat{a})]<\mathrm{}.$$

Also, following , we require that for any distortion level $`D>0`$ there is a scalar quantizer for $`𝑿`$ with finite rate.

Quantization Condition: For each $`D>0`$ there is a “quantizer” $`q:AB`$ for some countable (finite or infinite) subset $`B\widehat{A}`$, such that:

i. $`\rho (x,q(x))D`$ for all $`xA`$, and

ii. the entropy $`H(q(X_1))<\mathrm{}`$.

The following was implicitly proved in ; see also  for details.

Theorem 5. Generalized AEP for Optimal Lossy Compression : Let $`𝑿`$ be a stationary ergodic process. Assume that the distortion measure $`\rho `$ satisfies the quantization condition, that a reference letter exists, and that for each $`n1`$ the infimum of

$$E_{P_n}[\mathrm{log}Q_n(B(X_1^n,D))]$$

over all probability measures $`Q_n`$ on $`\widehat{A}^n`$ is achieved by some $`\stackrel{~}{Q}_n`$. Then for any $`D>0`$

$`{\displaystyle \frac{1}{n}}\mathrm{log}\stackrel{~}{Q}_n(B(X_1^n,D))R(D)\text{w.p.1}`$ (18)
where $`R(D)`$ is the rate-distortion function of the process $`𝑿`$.

Historical Remarks: The relevance of the quantities $`\mathrm{log}Q_n(B(X_1^n,D))`$ to information theory was first suggested implicitly by Kieffer  and more explicitly by Łuczak and Szpankowski . Since then, many papers have appeared proving the generalized AEP under different conditions; we mention here a subset of those proving some of the more general results. The case of finite alphabet processes was considered by Yang and Kieffer . The generalized AEP for processes with general alphabets and $`𝒀`$ i.i.d. was proved by Dembo and Kontoyiannis  and by Yang and Zhang . Finally, the case when $`𝒀`$ is not i.i.d. was (Theorem 3) treated by Chi . The observations of Theorem 4 about the rate-function $`R(,,D)`$ are new. Theorem 5 essentially comes from Kieffer’s work ; see also .

We should also mention that, in a somewhat different context, the intimate relationship between the AEP and large deviations is discussed in some detail by Orey in .

### 2.5 Densities vs. Balls

Let us recall the classical generalization of the AEP, due to Barron  and Orey , to processes with values in general alphabets. Suppose $`𝑿`$ as above is a general stationary ergodic process with marginals $`\{P_n\}`$ that are absolutely continuous with respect to the sequence of measures $`𝕄=\{M_n\}`$.

Theorem 6. AEP for Processes with Densities : Let $`𝑿`$ be a stationary ergodic process whose marginals $`P_n`$ have densities $`f_n=dP_n/dM_n`$ with respect to the $`\sigma `$-finite measures $`M_n`$, $`n1`$. Assume that the sequence $`𝕄`$ of dominating measures is Markov of finite order, with a stationary transition measure, and that the relative entropies

$`H_n\stackrel{\mathrm{}}{=}E_{P_n}\left[\mathrm{log}{\displaystyle \frac{f_n(X_1^n)}{f_{n1}(X_1^{n1})}}\right],n2,`$
have $`H_n>\mathrm{}`$ eventually. Then

$`{\displaystyle \frac{1}{n}}\mathrm{log}{\displaystyle \frac{dP_n}{dM_n}}(X_1^n)H(𝕄)\text{w.p.1}`$ (19)
where $`H(𝕄)`$ is the relative entropy rate defined as $`H(𝕄)=lim_nH_n=inf_nH_n`$.

The AEP for processes with densities is also know to hold when the reference measures $`M_n`$ do not form a Markov sequence, under some additional mixing conditions (see  where $`M_n`$ are taken to be non-Markov measures satisfying an additional mixing condition, and the more recent extension in  where the $`M_n`$ are taken to be discrete Gibbs measures.) Moreover, Kieffer  has given counterexamples illustrating that without some mixing conditions on $`\{M_n\}`$ the AEP (19) fails to hold.

There is a tempting analogy between the generalized AEP (15) and the AEP for processes with densities (19). The formal similarity between the two suggests that, if we identify the measures $`Q_n`$ with the reference measures $`M_n`$, corresponding results should hold in the two cases. Indeed, this does in general appear to be the case, as is illustrated by the various generalized AEPs stated above. Moreover, we can interpret the result of Theorem 5 as the natural analog of the classical discrete AEP (6) to the case of lossy data compression. As we argued in the introduction, the generalized AEPs of the previous sections play analogous roles in the proofs of the corresponding direct coding theorems.

Taking this analogy further indicates that there might be a relationship between these two different generalizations. In particular, when $`n`$ is large and the distortion level $`D`$ is small, the following heuristic calculation seems compelling:

$`H()`$ $`\stackrel{(a)}{}`$ $`{\displaystyle \frac{1}{n}}\mathrm{log}{\displaystyle \frac{dP_n}{dQ_n}}(X_1^n)`$
$`\stackrel{(b)}{}`$ $`{\displaystyle \frac{1}{n}}\mathrm{log}{\displaystyle \frac{P_n(B(X_1^n,D))}{Q_n(B(X_1^n,D))}}`$
$`=`$ $`{\displaystyle \frac{1}{n}}\mathrm{log}P_n(B(X_1^n,D))+{\displaystyle \frac{1}{n}}\mathrm{log}Q_n(B(X_1^n,D))`$
$`\stackrel{(c)}{}`$ $`R(,,D)R(,,D)`$
$`\stackrel{(d)}{}`$ $`H()`$
where $`(a)`$ holds in the limit as $`n\mathrm{}`$ by Theorem 6, $`(b)`$ should hold when $`D`$ is small by the assumption that $`P_n`$ has a density with respect to $`Q_n`$, $`(c)`$ would follow in the limit as $`n\mathrm{}`$ by an application of the generalized AEP, and it is natural to conjecture that $`(d)`$ holds in the limits as $`D0`$ by reading the above calculation backwards.

In the following two sections we formalize the above heuristic argument in two special cases: First when $`𝑿`$ is a discrete process taking values in a finite alphabet, and second when $`𝑿`$ is a continuous process taking values in $`^d`$.

#### 2.5.1 Discrete Case

Here we take $`𝑿`$ to be a stationary ergodic process taking values in a finite alphabet $`A`$, and $`𝒀`$ to be i.i.d. with first order marginal distribution $`Q=Q_1`$ on the same alphabet $`A=\widehat{A}`$. Similarly we write $`P=P_1`$ for the first order marginal of $`𝑿`$. In Theorem 7 we justify the above calculation by showing that the limits as $`D0`$ and as $`n\mathrm{}`$ can indeed be taken together in any fashion: We show that the double limit of the central expression

$`r_n(X_1^n,D)\stackrel{\mathrm{}}{=}{\displaystyle \frac{1}{n}}\mathrm{log}{\displaystyle \frac{P_n(B(X_1^n,D))}{Q_n(B(X_1^n,D))}}`$ (20)
is equal to $`H()`$ with probability 1, independently of how $`n`$ grows and $`D`$ decreases to zero. Its proof is given in Appendix A.

Theorem 7. Densities vs. Balls in the Discrete Case: Let $`𝑿`$ be a stationary ergodic process and $`𝒀`$ be i.i.d., both on the finite alphabet $`A`$. Assume that $`\rho (x,y)=0`$ if and only if $`x=y`$, and $`Q(x)>0`$ for all $`x`$. Then the following double limit exists:

$$\underset{\begin{array}{c}n\mathrm{}\\ D0\end{array}\text{ }}{lim}\frac{1}{n}\mathrm{log}\frac{P_n(B(X_1^n,D))}{Q^n(B(X_1^n,D))}=H()\text{w.p.1}$$

In particular, the repeated limit $`lim_nlim_D`$ exists with probability one and is equal to $`H()`$.

#### 2.5.2 Continuous Case

Here we state a weaker version of Theorem 7 in the case when $`A=\widehat{A}=^d`$ for some $`d1`$, and when $`𝑿`$ is an $`^d`$-valued, stationary ergodic process. Suppose that the marginals $`\{P_n\}`$ of $`𝑿`$ are absolutely continuous with respect to a sequence of reference measures $`\{Q_n\}`$. Throughout this section we take the $`Q_n`$ to be product measures, $`Q_n=Q^n,`$ for some fixed Borel probability measure $`Q`$ on $`^d`$. A typical example to keep in mind is when $`Q`$ a Gaussian measure on $``$ and $`𝑿`$ a real-valued stationary ergodic process all of whose marginals $`P_n`$ have continuous densities with respect to Lebesgue measure.

For simplicity, we take $`\rho `$ to be squared-error distortion, $`\rho (x,y)=(xy)^2`$, although the proof of Theorem 8, given in Appendix B, may easily be adapted to apply for somewhat more general difference distortion measures.

Theorem 8. Densities vs. Balls in the Continuous Case: Let $`𝑿`$ be an $`^d`$-valued stationary ergodic process, whose marginals $`P_n`$ have densities $`f_n=dP_n/dQ_n`$ with respect to a sequence of product measures $`Q_n=Q^n`$, $`n1`$, for a given probability measure $`Q`$ on $`^d`$. Let $`\rho (x,y)=(xy)^2`$ for any $`x,y^d`$.

(a) The following repeated limit holds:

$$\underset{n\mathrm{}}{lim}\underset{D0}{lim}\frac{1}{n}\mathrm{log}\frac{P_n(B(X_1^n,D))}{Q_n(B(X_1^n,D))}=H()\text{w.p.1.}$$

(b) Assume, moreover, that $`𝑿`$ is i.i.d. with marginal distribution $`P_1=P`$ on $`^d`$, and that the following conditions are satisfied: Both $`E_{P\times Q}[\rho (X,Y)]`$ and $`E_{P\times P}[\rho (X,Y)]`$ are finite and nonzero; the expectation

$$E_P[\mathrm{log}Q(B(X,D))]\text{is finite for all}D>0;$$

and a $`\delta >0`$ exists for which

$`E_P\left[\underset{0<D<\delta }{sup}\left|\mathrm{log}{\displaystyle \frac{P(B(X,D))}{Q(B(X,D))}}\right|\right]<\mathrm{}.`$ (21)
Then, the reverse repeated limit also holds:

$$\underset{D0}{lim}\underset{n\mathrm{}}{lim}\frac{1}{n}\mathrm{log}\frac{P_n(B(X_1^n,D))}{Q_n(B(X_1^n,D))}=H()\text{w.p.1.}$$

It is easy to check that all conditions of the theorem hold when $`Q`$ is a Gaussian measure on $``$ and $`P`$ has finite variance and a probability density function $`g`$ (with respect to Lebesgue measure) such that $`E_P(sup_{|yX|<\delta }|\mathrm{log}g(y)|)<\mathrm{}`$ for some $`\delta >0`$. For example, this is the case when both $`P`$ and $`Q`$ are Gaussian distributions on $``$.

As will be seen from the proof of the theorem, although we are primarily interested in the case when the relative entropy rate $`H()`$ is finite, the result remains true when $`H()=\mathrm{}`$, and in that case assumption (21) can be relaxed to

$$E_P\left[\underset{0<D<\delta }{sup}\mathrm{log}\frac{Q(B(X,D))}{P(B(X,D))}\right]<\mathrm{}.$$

Finally we note that, in the context of ergodic theory, Feldman  developed a different verison of the generalized AEP, and also discussed the relationship between the two types of asymptotics (as $`n\mathrm{}`$, and as $`D0`$).

## 3 Applications of the Generalized AEP

As outlined in the introduction, the generalized AEP can be applied to a number of problems in data compression and pattern matching. Following along the lines of the corresponding applications in the lossless case, below we present applications of the results of the previous section to: 1. Shannon’s random coding schemes; 2. mismatched codebooks in lossy data compression; 3. waiting times between stationary processes (corresponding to idealized Lempel-Ziv coding); 4. practical lossy Lempel-Ziv coding for memoryless sources; and 5. weighted codebooks in rate-distortion theory.

### 3.1 Shannon’s Random Codes

Shannon’s well-known construction of optimal codes for lossy data compression is based on the idea of generating a random codebook. We review here a slightly modified version of his construction  and describe how the performance of the resulting random code can be analyzed using the generalized AEP.

Given a sequence of probability distributions $`Q_n`$ on $`\widehat{A}^n`$, $`n1`$, we generate a random codebook according to the measures $`Q_n`$ as an infinite sequence of i.i.d. random vectors

$$Y_1^n(i),i1$$

with each $`Y_1^n(i)`$ having distribution $`Q_n`$ on $`\widehat{A}^n`$. Suppose that, for a fixed $`n`$, this codebook is available to both the encoder and decoder. Given a source string $`X_1^n`$ to be described with distortion $`D`$ or less, the encoder looks for a $`D`$-close match of $`X_1^n`$ into the codebook $`\{Y_1^n(i);i1\}`$. Let $`i_n`$ be the position of the first such match

$`i_n\stackrel{\mathrm{}}{=}inf\{i1:\rho _n(X_1^n,Y_1^n(i))D\}`$
with the convention that the infimum of the empty set equals $`+\mathrm{}`$. If a match is found, then the encoder describes to the decoder the position $`i_n`$ using Elias’ code for the integers . This takes no more than

$`\mathrm{log}_2i_n+2\mathrm{log}_2\mathrm{log}_2i_n+\text{Const.}\text{bits}.`$ (22)
If no match is found (something that asymptotically will not happen, with probability one), then the encoder describes $`X_1^n`$ with distortion $`D`$ or less using some other default scheme.

Let $`\mathrm{}_n(X_1^n)`$ denote the overall description length of the algorithm just described. In view of (22), in order to understand its compression performance, that is, to understand the asymptotic behavior of $`\mathrm{}_n(X_1^n)`$, it suffices to understand the behavior of the quantity

$$\mathrm{log}_2i_n,\text{for large }n\text{.}$$

Suppose that the probability $`Q_n(B(X_1^n,D))`$ of finding a $`D`$-close match for $`X_1^n`$ in the codebook is nonzero. Then, conditional on the source string $`X_1^n`$, the distribution of $`i_n`$ is geometric with parameter $`Q_n(B(X_1^n,D))`$. From this observation is easy to deduce that the behavior of $`i_n`$ is closely related to the behavior of the quantity $`1/Q_n(B(X_1^n,D))`$. The next theorem is an easy consequence of this fact so it is stated here without proof; see the corresponding arguments in .

Theorem 9. Strong Approximation: Let $`𝑿`$ be an arbitrary process and let $`\{Q_n\}`$ be a given sequence of codebook distributions. If $`Q_n(B(X_1^n,D))>0`$ eventually with probability one, then for any $`ϵ>0`$:

$`\mathrm{log}_2i_n`$ $``$ $`\mathrm{log}_2Q_n(B(X_1^n,D))+\mathrm{log}_2\mathrm{log}_2n+3\text{eventually, w.p.1}`$
$`\text{and}\mathrm{log}_2i_n`$ $``$ $`\mathrm{log}_2Q_n(B(X_1^n,D))\mathrm{log}_2n(1+ϵ)\mathrm{log}_2\mathrm{log}_2n\text{eventually, w.p.1.}`$
The above estimates can now be combined with the results of the generalized AEP in the previous section to determine the performance of codes based on random codebooks with respect to the “optimal” measures $`Q_n`$. To illustrate this approach we consider the special case of memoryless sources and finite reproduction alphabets, and show that the random code with respect to (almost) any random codebook realization is asymptotically optimal, with probability one. Note that corresponding results can be proved, in exactly the same way, under much more general assumptions. For example, utilizing Theorem 5 instead of Theorem 1 we can prove the analog of Theorem 10 below for arbitrary stationary ergodic sources.

Let $`𝑿`$ be an i.i.d. source with marginal distribution $`P_1=P`$ on $`A`$, and take the reproduction alphabet $`\widehat{A}`$ to be finite. For simplicity we will assume that the distortion measure $`\rho `$ is bounded, i.e., $`sup_{x,y}\rho (x,y)<\mathrm{},`$ and we also make the customary assumption that

$`\underset{xA}{sup}\underset{y\widehat{A}}{\mathrm{min}}\rho (x,y)=0.`$ (23)
\[See the remark at the end of Section 5.1.1 for a discussion of this condition and when it can be relaxed.\] As usual, we define the rate-distortion function of the memoryless source $`𝑿`$ by

$$R(D)=\underset{(X,Y)}{inf}I(X;Y)$$

where the infimum is over all jointly distributed random variables $`(X,Y)`$ with values in $`A\times \widehat{A}`$, such that $`X`$ has distribution $`P`$ and $`E[\rho (X,Y)]D`$. Let

$`\overline{D}\stackrel{\mathrm{}}{=}\underset{y\widehat{A}}{\mathrm{min}}E_P[\rho (X,y)]`$ (24)
and note that $`R(D)=0`$ for $`D\overline{D}`$. To avoid the trivial case when $`R(D)=0`$ for all $`D,`$ we assume that $`\overline{D}>0`$ and we restrict our attention to the interesting range of values $`D(0,\overline{D})`$. Recall  that for any such $`D`$, $`R(D)`$ can alternatively be written as

$$R(D)=\underset{Q}{inf}R_1(P,Q,D)$$

where the infimum is over all probability distributions $`Q`$ on $`\widehat{A}`$. Since we take $`\widehat{A}`$ to be finite, this infimum is always achieved (see ) by a probability distribution $`Q=Q^{}`$. To avoid cumbersome notation in the statements of the coding theorems given next and also in later parts of the paper, we also write $`(D)`$ for the rate-distortion function of the source $`𝑿`$ expressed in bits rather than in nats:

$$(D)\stackrel{\mathrm{}}{=}(\mathrm{log}_2e)R(D).$$

Finally, we write $`Q_n^{}`$ for the product measures $`(Q^{})^n`$ and call $`\{Q_n^{}\}`$ the optimal reproduction distributions at distortion level $`D`$.

Combining Theorem 9 with the generalized AEP of Theorem 1 implies the following strengthened direct coding theorem.

Theorem 10. Pointwise Coding Theorem for I.I.D. Sources : Let $`𝑿`$ be an i.i.d. source with distribution $`P`$ on $`A`$, and let $`Q_n^{}`$ denote the optimal reproduction distributions at distortion level $`D(0,\overline{D})`$. Then the codes based on almost any realization of the Shannon random codebooks according to the measures $`\{Q_n^{}\}`$ have codelengths $`\mathrm{}_n(X_1^n)`$ satisfying:

$$\underset{n\mathrm{}}{lim}\frac{1}{n}\mathrm{}_n(X_1^n)=(D)\text{bits per symbol, w.p.1.}$$

A simple modification of the above scheme can be used to obtain universal codebooks that achieve optimal compression for any memoryless source: Given a fixed block-length $`n`$, we consider the collection of all $`n`$-types on $`\widehat{A}`$, namely, all distributions $`Q`$ of the form $`Q(\widehat{a})=j/n`$, $`0jn`$, for $`\widehat{a}\widehat{A}`$. Instead of generating a single random codebook according to the optimal distribution $`Q_n^{}`$, we generate multiple codebooks, one for each product measure $`Q^n`$ corresponding to an $`n`$-type $`Q`$ on $`\widehat{A}`$. Then we (as the encoder) adopt a greedy coding strategy. We find the first $`D`$-close match for $`X_1^n`$ in each of the codebooks, and pick the one in which the match appears the earliest. To describe $`X_1^n`$ to the decoder with distortion $`D`$ or less we then describe two things: (a) the index of the codebook in which the earliest match was found, and (b) the position $`i_n`$ of this earliest match. Since there are at most polynomially many $`n`$-types (cf. ), the rate of the description of (a) is asymptotically negligible. Moreover, since the set of $`n`$-types is asymptotically dense among probability measures on $`\widehat{A}`$, we eventually do as well as if we were using the optimum codebook distribution $`Q_n^{}`$.

Theorem 11. Pointwise Universal Coding Theorem : Let $`𝑿`$ be an arbitrary i.i.d. source with distribution $`P`$ on $`A`$, let $`R(D)`$ be the rate-distortion function of this source at distortion level $`D(0,\overline{D})`$, and let $`(D)`$ denote its rate-distortion function in bits. The codes based on almost any realization of the universal Shannon random codebooks have codelengths $`\mathrm{}_n(X_1^n)`$ satisfying:

$$\underset{n\mathrm{}}{lim}\frac{1}{n}\mathrm{}_n(X_1^n)=(D)\text{bits per symbol, w.p.1.}$$

### 3.2 Mismatched Codebooks

In the last section we described how, for memoryless sources, the Shannon random codebooks with respect to the optimal reproduction distributions can be used to achieve asymptotically optimal compression performance. In this section we briefly consider the question of determining the rate achieved when an arbitrary (stationary ergodic) source $`𝑿`$ is encoded using a random codebook according to the i.i.d. distributions $`Q^n`$, for an arbitrary distribution $`Q`$ on $`\widehat{A}`$. For further discussion of the problem of mismatched codebooks see  and the references therein.

The following theorem is an immediate consequence of combining Theorem 1 with Theorem 9 and the discussion in Section 3.1 (see also Example 1 in Section 2.2).

Theorem 12. Mismatched Coding Rate: Let $`𝑿`$ be a stationary ergodic process with marginal distribution $`P_1=P`$ on $`A`$, let $`Q`$ be an arbitrary distribution on $`\widehat{A}`$, and define $`D_{\mathrm{min}}`$ and $`D_{\mathrm{av}}`$ as in Section 2.2.

* Arbitrary I.I.D. Codebooks: For any distortion level $`D(D_{\mathrm{min}},D_{\mathrm{av}})`$, the codes based on almost any realization of the Shannon random codebooks according to the measures $`\{Q^n\}`$ have codelengths $`\mathrm{}_n(X_1^n)`$ satisfying:

$$\underset{n\mathrm{}}{lim}\frac{1}{n}\mathrm{}_n(X_1^n)=(\mathrm{log}_2e)R_1(P,Q,D)\text{bits per symbol, w.p.1.}$$
* I.I.D. Gaussian Codebooks: Suppose $`\rho (x,y)=(xy)^2`$ and $`𝑿`$ is a real-valued process with finite variance $`\sigma ^2=\text{Var}(X_1)`$. Let $`Q`$ be the $`N(0,\tau ^2)`$ distribution on $``$. Then for any distortion level $`D(0,\sigma ^2+\tau ^2)`$, the codes based on almost any realization of the Gaussian codebooks according to the measures $`\{Q^n\}`$ have codelengths $`\mathrm{}_n(X_1^n)`$ satisfying:

$$\underset{n\mathrm{}}{lim}\frac{1}{n}\mathrm{}_n(X_1^n)=\frac{1}{2}\mathrm{log}_2\left(\frac{v}{D}\right)(\mathrm{log}_2e)\frac{(vD)(v\sigma ^2)}{2v\tau ^2}\text{bits per symbol, w.p.1,}$$

where

$$v\stackrel{\mathrm{}}{=}\frac{1}{2}\left[\tau ^2+\sqrt{\tau ^4+4D\sigma ^2}\right].$$

Lossless vs. Lossy Mismatch: Recall that, in the case of lossless data compression, if instead of the true source distribution $`P`$ a different coding distribution $`Q`$ is used, then the code-rate achieved is

$`H(P)+H(PQ).`$ (25)
Similarly in the current setting of lossy data compression, if instead of the optimal reproduction distribution $`Q^{}`$ we use a different codebook distribution $`Q`$, the rate we achieve is $`R_1(P,Q,D)`$. An upper bound for $`R_1(P,Q,D)`$ is obtained by taking $`(X,Y)`$ in the expression of Remark 1 to be the jointly distributed random variables that achieve the infimum in the definition of the rate-distortion function of $`P`$. Then the (mismatched) rate of the random code based on $`Q`$ instead of $`Q^{}`$ is:

$`R_1(P,Q,D)R(D)+H(Q^{}Q).`$ (26)
Equations (25) and (26) illustrate the analogy between the penalty terms in the lossless and lossy case due to mismatch.

Next we discuss two special cases of part (b) of the theorem that are of particular interest.

Example 2: Gaussian codebook with mismatched distribution: Consider the following coding scenario: We want to encode data generated by an i.i.d. Gaussian process with $`N(0,\sigma ^2)`$ distribution, with squared-error distortion $`D`$ or less. In this case, it is well-known  that for any $`D(0,\sigma ^2)`$ the optimal reproduction distribution $`Q^{}`$ is the $`N(0,\sigma ^2D)`$ distribution, so we construct random codebooks according to the i.i.d. distributions $`Q_n^{}=(Q^{})^n`$.

But suppose that, instead of an i.i.d. Gaussian, the source turns out to be some arbitrary stationary ergodic $`𝑿`$ with zero mean and variance $`\sigma ^2`$. Theorem 12 (b) implies that the asymptotic rate achieved by our i.i.d. Gaussian codebook is equal to

$$\frac{1}{2}\mathrm{log}_2\left(\frac{\sigma ^2}{D}\right)\text{bits per symbol.}$$

Since this is exactly the rate-distortion function of the i.i.d. $`N(0,\sigma ^2)`$ source, we conclude that the rate achieved is the same as what we would have obtained on the Gaussian source we originally expected. This offers yet another justification of the folk theorem that the Gaussian source is the hardest one to compress, among sources with a fixed variance. In fact, the above result is a natural fixed-distortion analog of \[53, Theorem 3\].

Example 3: Gaussian codebook with mismatched variance: Here we consider a different type of mismatch. As before, we are prepared to encode an i.i.d. Gaussian source, but we have an incorrect estimate of its variance, say $`\widehat{\sigma }^2`$ instead of the true variance $`\sigma ^2`$. So we are using a random codebook with respect to the optimal reproduction distribution $`Q_n^{}=(Q^{})^n`$, where $`Q^{}`$ is the $`N(0,\widehat{\sigma }^2D)`$ distribution, but the actual source is i.i.d. $`N(0,\sigma ^2)`$. In this case, the rate achieved by the random codebooks according to the distributions $`Q_n^{}`$ is given by the expression in Theorem 12 (b), with $`\tau ^2`$ replaced by $`\widehat{\sigma }^2D`$. Although the resulting expression is somewhat long and not easy to manipulate analytically, it is straightforward to evaluate numerically. For example, Figure 1 shows the asymptotic rate achieved, as a function of the error $`e=\sigma ^2\widehat{\sigma }^2`$ in the estimate of the true variance. As expected, the best rate is achieved when the codebook distribution is matched the source (corresponding to $`e=0`$), and it is equal to the rate-distortion function of the source. Moreover, as one might expect, it is more harmful to underestimate the variance than to overestimate it.

### 3.3 Waiting Times and Idealized Lempel-Ziv Coding

Given $`D0`$ and two independent realizations from the stationary ergodic processes $`𝑿`$ and $`𝒀`$, our main quantity of interest here is the waiting time $`W_n=W_n(D)`$ until a $`D`$-close version of the initial string $`X_1^n`$ first appears in $`Y_1^{\mathrm{}}`$. Formally

$`W_n=inf\{i1:\rho _n(X_1^n,Y_i^{i+n1})D\}`$ (27)
with the convention, as before, that the infimum of the empty set equals $`+\mathrm{}`$.

The motivation for studying the asymptotic behavior of $`W_n`$ for large $`n`$ is twofold.

Idealized Lempel-Ziv coding. The natural extension of the idealized scenario described in the introduction is to consider a message $`X_1^n`$ that is to be encoded with the help of a database $`Y_1^{\mathrm{}}`$. The source and the database are assumed to be independent, and the database distribution may or may not be the same as that of the source. In order to communicate $`X_1^n`$ to the decoder with distortion $`D`$ or less, the encoder simply describes $`W_n`$, using no more than

$$\mathrm{log}_2W_n+O(\mathrm{log}_2\mathrm{log}_2W_n)\text{bits.}$$

Therefore, the asymptotic performance of this idealized scheme can be completely understood in terms of the asymptotics of $`\mathrm{log}W_n`$, for large $`n`$.

DNA pattern matching. Here we imagine that $`X_1^n`$ represents a DNA or protein “template,” and we want to see whether it appears, either exactly or approximately, as a contiguous substring of a database DNA sequence $`Y_1^{\mathrm{}}`$. We are interested in quantifying the “degree of surprise” in the fact that a $`D`$-close match was found at position $`W_n`$. Specifically, was the match found “atypically” early, or is the value of $`W_n`$ consistent with the hypothesis that the template and the database are independent? For a detailed discussion, see, e.g., \[25, Section 3.2\] and the references therein.

If for a moment we consider the case when both $`𝑿`$ and $`𝒀`$ are i.i.d., we see that the waiting time $`W_n`$ is, at least intuitively, closely related to the index $`i_n`$ of Section 3.1. As the following result shows, although the distribution of $`W_n`$ is not exactly geometric, $`W_n`$ behaves very much like $`i_n`$, at least in the exponent. That is, the difference

$$\mathrm{log}W_n[\mathrm{log}Q_n(B(X_1^n,D))]$$

is “small,” eventually with probability one.

Recall the definition of $`\psi `$-mixing from Section 2.3, and also the definition of the $`\varphi `$-mixing coefficients of $`𝒀`$

$$\varphi (k)=sup\{|(B|A)(B)|:B\sigma (Y_k^{\mathrm{}}),A\sigma (Y_{\mathrm{}}^0),(A)>0\}$$

where, as before, $`\sigma (Y_i^j)`$ denotes the $`\sigma `$-field generated by $`Y_i^j`$. The process $`𝒀`$ is called $`\varphi `$-mixing if $`\varphi (k)0`$ as $`k\mathrm{}`$; see  for an extensive discussion of $`\varphi `$-mixing and related mixing conditions.

Theorem 13. Strong Approximation : Let $`𝑿`$ and $`𝒀`$ be stationary ergodic processes, and assume that $`𝒀`$ is either $`\psi `$-mixing or $`\varphi `$-mixing with summable $`\varphi `$-mixing coefficients, $`_{k1}\varphi (k)<\mathrm{}`$. If $`Q_n(B(X_1^n,D))>0`$ eventually with probability one, then for any $`ϵ>0`$:

$`(1+ϵ)\mathrm{log}n\mathrm{log}[W_nQ_n(B(X_1^n,D))](2+ϵ)\mathrm{log}n\text{eventually, w.p.1.}`$
Theorem 13 of course implies that

$`\mathrm{log}W_n=\mathrm{log}Q_n(B(X_1^n,D))+O(\mathrm{log}n)\text{w.p.1}`$ (28)
and combining this with the generalized AEP statements of Theorems 1 and 4 we immediately obtain the first order (or strong-law-of-large-numbers, SLLN) asymptotic behavior of the waiting times $`W_n`$:

Theorem 14. SLLN for Waiting Times: Let $`𝑿`$ and $`𝒀`$ be stationary ergodic processes.

(a) If $`𝒀`$ is i.i.d. and the average distortion $`D_{\mathrm{av}}`$ is finite, then for any $`D(D_{\mathrm{min}},D_{\mathrm{av}})`$

$`{\displaystyle \frac{1}{n}}\mathrm{log}W_nR_1(P_1,Q_1,D)\text{w.p.1.}`$ (29)
(b) If $`𝒀`$ is $`\psi `$-mixing and the distortion measure $`\rho `$ is bounded, then for any $`D(D_{\mathrm{min}},D_{\mathrm{av}})`$

$`{\displaystyle \frac{1}{n}}\mathrm{log}W_nR(,,D)\text{w.p.1.}`$ (30)
Note that similar results can be obtained under different assumptions on the process $`𝒀`$, using Theorems 3 and 5 in place of Theorems 1 and 4 as done above. When $`𝑿`$ is taken to be an arbitrary stationary ergodic process, it is natural to expect that the mixing conditions for $`𝒀`$ in Theorem 14 (b) cannot be substantially relaxed. In fact, even in the case of exact matching between finite-alphabet processes, Shields  has produced a counterexample demonstrating that the analog of Theorem 13 does not hold for arbitrary stationary ergodic $`𝒀`$.

Historical Remarks: Waiting times in the context of lossy data compression were studied by Steinberg and Gutman  and Łuczak and Szpankowski . Yang and Kieffer  identified the limiting rate-function for a wide range of finite alphabet sources, and Dembo and Kontoyiannis  and Chi  generalized these results to processes with general alphabets.

The strong approximation idea was introduced in  in the case of exact matching. For processes $`𝒀`$ with summable $`\varphi `$-mixing coefficients, Theorem 13 was proved in , and when $`𝒀`$ is $`\psi `$-mixing it was proved, for the case of no distortion, in . Examining the latter proof,  observed that it immediately generalizes to the statement of Theorem 13.

Related results were obtained by Kanaya and Muramatsu , who extended some of the results of  to processes with general alphabets, and by Koga and Arimoto  who considered non-overlapping waiting times between finite-alphabet processes and Gaussian processes. Finally, Shields  and Marton and Shields  considered waiting times with respect to Hamming distortion and for $`𝑿`$ and $`𝒀`$ having the same distribution over a finite alphabet. For the case of small distortion they showed, under some conditions, that approximate matching results like (29) and (30) reduce to their natural exact matching analogs as $`D0`$.

### 3.4 Match-Lengths and Practical Lempel-Ziv Coding

In the idealized coding scenario of the previous section we considered the case where a fixed-length message $`X_1^n`$ is to be compressed using an infinitely long database $`Y_1^{\mathrm{}}`$. But, in practice, the reverse situation is much more common: We typically have a “long” message $`(X_1,X_2,\mathrm{})`$ to be compressed, and only a finite-length database $`Y_1^m`$ is available to the encoder and decoder. It is therefore natural (following the corresponding development in the case of lossless compression) to try and match “as much as possible” from the message $`(X_1,X_2,\mathrm{})`$ into the database $`Y_1^m`$. With this in mind we define the match-length $`L_m`$ as the length $`\mathrm{}`$ of the longest prefix $`X_1^{\mathrm{}}`$ that matches somewhere in the database with distortion $`D`$ or less:

$`L_m=sup\{\mathrm{}1:\rho _{\mathrm{}}(X_1^{\mathrm{}},Y_j^{j+\mathrm{}1})D,\text{for some}j=1,2,\mathrm{},m\}.`$ (31)
Intuitively, there is a connection between match-lengths and waiting times. Long matches should mean short waiting times, and vice versa. In the case of exact matching this connection was precisely formalized by Wyner and Ziv , who observed that the following “duality” relationship always holds:

$`W_nmL_mn.`$ (32)
This is almost identical to the standard relationship in renewal theory between the number of events by a certain time and the time of the $`n`$th event (see, e.g., ). Wyner and Ziv  utilized (32) to translate their first order asymptotic results about $`W_n`$ to corresponding results about $`L_m`$.

Unfortunately this simple relationship no longer holds in the case of approximate matching, when a distortion measure is introduced. Instead, the following modified duality was employed in  to obtain corresponding results in approximate matching and lossy data compression:

$`W_nmL_mn\text{and}L_mn\underset{kn}{inf}W_km.`$ (33)
In  it is shown that (33) can be used to deduce the asymptotic behavior of $`L_m`$ from that of $`W_n`$, but this translation is not straightforward anymore. In fact, as we discuss in Section 5.2, a somewhat more delicate analysis is needed in this case. Nevertheless, once the behavior of the waiting times is understood, the first implication in (33) immediately yields asymptotic lower bounds on the behavior of the match-lengths. This is significant for data compression since long match-lengths usually mean good compression performance. Indeed, this observation allowed  to introduce a new lossy version of the Lempel-Ziv algorithm that achieves asymptotically optimal compression performance for memoryless sources. The key characteristics of the algorithm are that it has polynomial implementation complexity, and that it achieves redundancy comparable to that of its lossless counterpart, the FDLZ .

We also mention that, before , several practical (yet suboptimal) lossy versions of the Lempel-Ziv algorithm were introduced, perhaps most notably by Steinberg and Gutman  and Łuczak and Szpankowski . Roughly speaking, the reason for their suboptimal compression performance was that the coding was done with respect to a database that had the same distribution as the source. In view of the discussion in the previous section, it is clear that the asymptotic code-rate of these algorithms is $`R_1(P,P,D)`$, which is typically significantly larger than the optimal $`R(D)=inf_QR_1(P,Q,D)`$; see  or  for more detailed discussions.

### 3.5 Weighted Codebooks and Sphere-Covering

Here we describe a related question that was recently considered in . In the classical rate-distortion problem, one is interested in finding “efficient” codebooks for describing the output of some random source to within some tolerable distortion level. In terms of data compression, a codebook is “efficient” when it contains relatively few codewords, so that it yields a code with a low rate. Here we are interested in the more general problem of finding codebooks with small “mass.”

Let $`𝑿`$ be an i.i.d. process with marginal distribution $`P`$ on a finite alphabet $`A`$, and take $`\widehat{A}=A`$ and $`\rho `$ a distortion measure with the property that $`\rho (x,y)=0`$ if and only if $`x=y`$. Let $`M:A(0,\mathrm{})`$ be an arbitrary nonnegative function assigning mass $`M^n(C_n)`$ to subsets $`C_n`$ of $`A^n`$:

$$M^n(C_n)\stackrel{\mathrm{}}{=}\underset{y_1^nC_n}{}M^n(y_1^n)\stackrel{\mathrm{}}{=}\underset{y_1^nC_n}{}\underset{i=1}{\overset{n}{}}M(y_i).$$

The question of interest here can be stated as follows. Let $`C_n`$ be a subset $`A^n`$ (we think of $`C_n`$ as the codebook) that nearly $`D`$-covers all of $`A^n`$, i.e., with high probability, every string $`X_1^n`$ generated by the source will match at least one element of $`C_n`$ with distortion $`D`$ or less:

$`P^n\{\text{there is an }y_1^nC_n\text{ such that}\rho _n(X_1^n,y_1^n)D\}1.`$ (34)
If (34) holds, how small can the mass of $`C_n`$ be?

For example, taking $`M`$ identically equal to one, this problem reduces to the rate-distortion question. Taking $`M`$ to be a different probability measure $`Q`$, it reduces to the classical hypothesis testing question, whereas $`M=P`$ (the source distribution) yields “converses” to some measure-concentration inequalities; see  for a detailed treatment of these and more general cases.

The next result characterizes the best growth exponent for the mass of an arbitrary codebook $`C_n`$.

Theorem 15: Weighted Codebooks : Let $`𝑿`$ be an i.i.d. source on the finite alphabet $`A=\widehat{A}`$, and suppose that $`\rho (x,y)=0`$ if and only if $`x=y.`$

* Let $`C_n`$ be an arbitrary subset of $`A^n`$, and write $`D`$ for the expected distance of a source string $`X_1^n`$ from $`C_n`$:

$$D=E_{P^n}[\underset{y_1^nC_n}{\mathrm{min}}\rho _n(X_1^n,y_1^n)].$$

Then

$$M^n(C_n)e^{nr(D)}$$

where the rate-function $`r(D)=r(D;P,M)`$ is defined by

$$r(D)=r(D;P,M)=\underset{(X,Y)}{inf}\{I(X;Y)+E[\mathrm{log}M(Y)]\}$$

and the infimum is taken over all jointly distributed random variables $`(X,Y)`$ with values in $`A`$, such that $`XP`$ and $`E[\rho (X,Y)]D.`$
* For every $`D0`$ there is a sequence of codebooks $`\{C_n^{}\}`$ such that

$`\underset{n\mathrm{}}{lim\; sup}{\displaystyle \frac{1}{n}}\mathrm{log}M^n(C_n^{})r(D)`$
and $`\underset{n\mathrm{}}{lim\; sup}E_{P^n}[\underset{y_1^nC_n^{}}{\mathrm{min}}\rho _n(X_1^n,y_1^n)]D.`$

The main ingredient in the proof of the direct coding theorem in part $`()`$ above is provided by yet another version of the generalized AEP. Let $`(X^{},Y^{})`$ be a pair of random variables achieving the infimum in the definition of $`r(D)`$, and let $`Q^{}`$ be the distribution of $`Y^{}`$. Now for $`\delta >0`$ and $`n1`$ define the sets

$$𝒢_n=\{y_1^nA^n:\widehat{P}_{y_1^n}(b)Q^{}(b)+\delta ,bA\}$$

where $`\widehat{P}_{y_1^n}`$ denotes the empirical distribution induced by $`y_1^n`$ on $`A`$. For each $`n1`$ define the “conditioned” measure $`Q_n^{(c)}`$ on $`A^n`$ by conditioning the product measure $`(Q^{})^n`$ to the set $`𝒢_n`$. The next theorem provides the necessary version of the generalized AEP in this case.

Theorem 16: Generalized AEP for Conditioned Measures : With the conditioned measures $`Q_n^{(c)}`$ defined as above, we have:

$$\underset{n\mathrm{}}{lim\; sup}\frac{1}{n}\mathrm{log}Q_n^{(c)}(B(X_1^n,D))I(X^{};Y^{})\text{w.p.1.}$$

## 4 Refinements of the Generalized AEP

As we saw in Section 3, the generalized AEP can be used to determine the first order asymptotic behavior of a number of interesting objects arising in applications. For example, the generalized AEP of Theorem 1

$$\frac{1}{n}\mathrm{log}Q^n(B(X_1^n,D))R_1(P,Q,D)\text{w.p.1}$$

immediately translated (via the strong approximation of Theorem 13) to a strong-law-of-large-numbers (SLLN) result for the waiting times:

$$\frac{1}{n}\mathrm{log}W_nR_1(P,Q,D)\text{w.p.1.}$$

In this section we will prove refinements to the generalized AEP of Section 2.2, and in Section 5 we will revisit the applications of the previous section and use these refinements to prove corresponding second order asymptotic results.

To get some motivation, let us consider for a moment the simplest version of the classical AEP, for an i.i.d. process $`𝑿`$ with distribution $`P`$ on the finite alphabet $`A`$. The AEP here follows by a simple application of the law of large numbers,

$`{\displaystyle \frac{1}{n}}\mathrm{log}P^n(X_1^n)={\displaystyle \frac{1}{n}}{\displaystyle \underset{i=1}{\overset{n}{}}}[\mathrm{log}P(X_i)]H`$ (35)
where $`H`$ is the entropy of $`P`$. But (35) contains more information than that: It says that $`\mathrm{log}P^n(X_1^n)`$ is in fact equal to the partial sum $`S_n=_{i=1}^nZ_i`$ of the i.i.d. random variables $`Z_i=\mathrm{log}P(X_i)`$. Therefore we can apply the central limit theorem (CLT) or the law of the iterated logarithm (LIL) to get more precise information on the convergence of the AEP.

The same strategy can be carried out for non-i.i.d. processes: Initially Ibragimov  and then Philipp and Stout  showed that even when $`𝑿`$ is a Markov chain, or, more generally, a weakly dependent random process, the quantities $`\mathrm{log}P^n(X_1^n)`$ can be approximated by the partial sums of an associated weakly dependent process. These results have found a number of applications in lossless data compression and related areas .

In this and the following section we will carry out a similar program in the lossy case. Throughout this section we will adopt the notation and assumptions of Section 2.2: Let $`𝑿`$ be a stationary ergodic process with first order marginal $`P_1=P`$ on $`A`$, and let $`Q`$ be an arbitrary probability measure on $`\widehat{A}`$. Define $`D_{\mathrm{min}}`$ and $`D_{\mathrm{av}}`$, as before (as in equations (7) and (8)), and assume that $`D_{\mathrm{min}}<D_{\mathrm{av}}`$ so that the distortion measure $`\rho (X,Y)`$ is not essentially constant in $`Y`$ with positive probability. We also impose here the additional assumption that $`\rho `$ has a finite third moment:

$`D_3\stackrel{\mathrm{}}{=}E_{P\times Q}[\rho ^3(X,Y)]<\mathrm{}.`$ (36)
The first result of this section refines Theorem 1 by giving a more precise asymptotic estimate of the quantity $`\mathrm{log}Q^n(B(X_1^n,D))`$ in terms of the rate-function $`R_1(P,Q,D)`$ and the empirical measure $`\widehat{P}_n`$ induced by $`X_1^n`$ on $`A^n`$

$$\widehat{P}_n\stackrel{\mathrm{}}{=}\frac{1}{n}\underset{i=1}{\overset{n}{}}\delta _{X_i}$$

where $`\delta _x`$ denotes the measure assigning unit mass to $`xA`$.

Theorem 17: : Let $`𝑿`$ be a stationary ergodic process with marginal $`P`$ on $`A`$, and let $`Q`$ be an arbitrary probability measure on $`\widehat{A}.`$ Assume that $`D_3=E_{P\times Q}[\rho ^3(X,Y)]`$ is finite. Then for any $`D(D_{\mathrm{min}},D_{\mathrm{av}})`$:

$`\mathrm{log}Q^n(B(X_1^n,D))=nR_1(\widehat{P}_n,Q,D)+{\displaystyle \frac{1}{2}}\mathrm{log}n+O(1)\text{w.p.1.}`$ (37)
Next we show that the most significant term in (37) can be approximated by the partial sum of a weakly dependent random process. Recall the definition of the $`\alpha `$-mixing coefficients of $`𝑿`$

$$\alpha (k)=sup\{|(AB)(A)(B)|:A\sigma (X_{\mathrm{}}^0),B\sigma (X_k^{\mathrm{}})\}$$

where $`\sigma (X_i^j)`$ is the $`\sigma `$-field generated by $`X_i^j`$. The process $`𝑿`$ is called $`\alpha `$-mixing if $`\alpha (k)0`$ as $`k\mathrm{}`$; see  for more details.

We also need to recall some of the notation from the proof of Theorem 1 in Section 2.2. For $`xA`$ and $`\lambda `$, let $`\mathrm{\Lambda }_x(\lambda )`$ denote the log-moment generating function of the random variable $`\rho (x,Y)`$

$$\mathrm{\Lambda }_x(\lambda )\stackrel{\mathrm{}}{=}\mathrm{log}E_Q\left(e^{\lambda \rho (x,Y)}\right)$$

and note that the function $`\mathrm{\Lambda }(\lambda )`$ defined in (10) can be written as $`\mathrm{\Lambda }(\lambda )=E_P[\mathrm{\Lambda }_X(\lambda )]`$. Also recall that for any $`D(D_{\mathrm{min}},D_{\mathrm{av}})`$ there exists a unique $`\lambda ^{}<0`$ such that $`\mathrm{\Lambda }^{}(\lambda ^{})=D`$.

Theorem 18: : Let $`𝑿`$ be a stationary $`\alpha `$-mixing process with marginal $`P`$ on $`A`$, and let $`Q`$ be an arbitrary probability measure on $`\widehat{A}.`$ Assume that the $`\alpha `$-mixing coefficients of $`𝑿`$ satisfy

$`{\displaystyle \underset{k=1}{\overset{\mathrm{}}{}}}\alpha ^t(k)<\mathrm{},\text{for some }t(0,1/3)`$ (38)
and that $`D_3=E_{P\times Q}[\rho ^3(X,Y)]`$ is finite. Then for any $`D(D_{\mathrm{min}},D_{\mathrm{av}})`$:

$$nR_1(\widehat{P}_n,Q,D)=nR_1(P,Q,D)+\underset{i=1}{\overset{n}{}}g(X_i)+O(\mathrm{log}\mathrm{log}n)\text{w.p.1}$$

where

$`g(x)\stackrel{\mathrm{}}{=}\mathrm{\Lambda }(\lambda ^{})\mathrm{\Lambda }_x(\lambda ^{}),xA.`$ (39)
Theorem 18 is a small generalization of \[23, Theorem 3\]. Before giving its proof outline, we combine Theorems 17 and 18 to show that, as promised, $`\mathrm{log}Q^n(B(X_1^n,D))`$ can be accurately approximated as the partial sum of the weakly dependent random process $`\{g(X_n)\}`$.

Corollary 19: Second Order Generalized AEP: Let $`𝑿`$ be a stationary $`\alpha `$-mixing process with marginal $`P`$ on $`A`$, and let $`Q`$ be an arbitrary probability measure on $`\widehat{A}.`$ Assume that the $`\alpha `$-mixing coefficients of $`𝑿`$ satisfy (38) and that $`D_3=E_{P\times Q}[\rho ^3(X,Y)]`$ is finite. Then for any $`D(D_{\mathrm{min}},D_{\mathrm{av}})`$, and with $`g(x)`$ defined as in (39):

$$\mathrm{log}Q^n(B(X_1^n,D))=nR_1(P,Q,D)+\underset{i=1}{\overset{n}{}}g(X_i)+\frac{1}{2}\mathrm{log}n+O(\mathrm{log}\mathrm{log}n)\text{w.p.1.}$$

Proof Outline for Theorem 18: Adapting the argument leading from (22) to (24) of , one easily checks that the result of Theorem 18 holds as soon as

$`\underset{n\mathrm{}}{lim\; inf}\underset{|\theta |<\delta }{inf}B_n(\theta )`$ $`>`$ $`0\text{w.p.1}`$ (40)
$`\text{and}\underset{n\mathrm{}}{lim\; sup}{\displaystyle \frac{nA_n^2}{\mathrm{log}\mathrm{log}n}}`$ $`<`$ $`\mathrm{}\text{w.p.1}`$ (41)
where $`A_n=n^1_{k=1}^n\zeta _k`$ is the empirical mean of the centered random variables $`\zeta _k=\mathrm{\Lambda }_{X_k}^{}(\lambda ^{})D`$, and $`B_n(\theta )`$ is the empirical mean of the non-negative random variables $`\mathrm{\Lambda }_{X_k}^{\prime \prime }(\lambda ^{}+\theta )`$. By the ergodic theorem we have, with probability one,

$`\underset{n\mathrm{}}{lim\; inf}\underset{|\theta |<\delta }{inf}B_n(\theta )`$ $``$ $`\underset{n\mathrm{}}{lim\; inf}{\displaystyle \frac{1}{n}}{\displaystyle \underset{k=1}{\overset{n}{}}}\underset{|\theta |<\delta }{inf}\mathrm{\Lambda }_{X_k}^{\prime \prime }(\lambda ^{}+\theta )`$
$`=`$ $`E_P\left[\underset{|\theta |<\delta }{inf}\mathrm{\Lambda }_X^{\prime \prime }(\lambda ^{}+\theta )\right]`$
and by Fatou’s lemma and the continuity of the map $`\theta \mathrm{\Lambda }_x^{\prime \prime }(\lambda ^{}+\theta )`$ it follows that

$$\underset{\delta 0}{lim\; inf}E_P\left[\underset{|\theta |<\delta }{inf}\mathrm{\Lambda }_X^{\prime \prime }(\lambda ^{}+\theta )\right]E_P[\mathrm{\Lambda }_X^{\prime \prime }(\lambda ^{})]=\mathrm{\Lambda }^{\prime \prime }(\lambda ^{})>0.$$

This implies that (40) holds once $`\delta >0`$ is made small enough. \[Note that the above argument also avoids an incorrect – but also unnecessary – application of the uniform ergodic theorem in the derivation of \[23, eq. (26)\].\]

Turning to (41), since $`\lambda ^{}<0`$, it follows by the convexity of $`\mathrm{\Lambda }_x(\lambda )`$ that that for any $`xA`$:

$$0\mathrm{\Lambda }_x^{}(\lambda ^{})\mathrm{\Lambda }_x^{}(0)=E_Q[\rho (x,Y)].$$

Consequently, Hölder’s inequality and assumption (36) imply that the random variable

$$|\zeta _k|E_Q[\rho (X_k,Y)|X_k]+D$$

has a finite third moment. Recall  that the LIL holds for the partial sum $`A_n`$ of a zero-mean, stationary process $`\{\zeta _k\}`$ with a finite third moment, as soon as the $`\alpha `$-mixing coefficients of $`\{\zeta _k\}`$ satisfy (38). The observation that $`\zeta _k`$ is a deterministic function of $`X_k`$ for all $`k`$ completes the proof. $`\mathrm{}`$

## 5 Applications – Second Order Results

Here we revisit the applications considered in Section 3, and using the “second order generalized AEP” of Corollary 19 we prove second order refinements for many of the results from Section 3. In Section 5.1 we consider the problem of lossy data compression in the same setting as in Section 3.1. We use the second order AEP to determine the precise asymptotic behavior of the Shannon random codebooks, and show that, with probability one, they achieve optimal compression performance up to terms of order $`(\mathrm{log}n)`$ bits. Moreover, essentially the same compression performance can be achieved universally. For arbitrary variable-length codes operating at a fixed rate level, we show that the rate at which they can achieve the optimal rate of $`n(D)`$ bits is at best of order $`O(\sqrt{n})`$ bits. This is the best possible redundancy rate as long as the “minimal coding variance” of the source is strictly positive. For discrete i.i.d. sources, a characterization is given of when this variance can be zero.

In Section 5.2 we look at waiting times, and we prove a second order refinement to Theorem 14, and in Section 5.3 we consider the problem of determining the asymptotic behavior of longest match-lengths. As discussed briefly in Section 3.4, their asymptotics can be deduced from the corresponding waiting-times results via duality.

### 5.1 Lossy Data Compression

#### 5.1.1 Random Codes and Second Order Converses

Here we consider the exact same setup as in Section 3.1: An i.i.d. source $`𝑿`$ with distribution $`P`$ on $`A`$ is to be compressed with distortion $`D`$ or less with respect to a bounded distortion measure $`\rho `$, satisfying, as before, the usual assumption (23) – see the remark at the end of this section for its implications. We take the reproduction alphabet $`\widehat{A}`$ to be finite, define $`\overline{D}`$ as in (24), and assume that $`\overline{D}>0`$.

For $`D(0,\overline{D})`$, let $`Q_n^{}`$, $`n1`$, denote the optimal reproduction distributions at distortion level $`D`$. Combining the strong approximation Theorem 9 with the second order generalized AEP of Corollary 19 and the discussion in Section 3.1 yields:

Theorem 20: Pointwise Redundancy for I.I.D. Sources : Suppose $`𝑿`$ is an i.i.d. source with distribution $`P`$ on $`A`$, and with rate-distortion function $`(D)`$ (in bits). Let $`Q_n^{}`$ denote the optimal reproduction distributions at distortion level $`D(0,\overline{D})`$, and define the function $`h(x)=(\mathrm{log}_2e)g(x)`$, $`xA`$, with $`g`$ defined as in (39). Then:

* The codes based on almost any realization of the Shannon random codebooks according to the measures $`\{Q_n^{}\}`$ have codelengths $`\mathrm{}_n(X_1^n)`$ satisfying

$$\mathrm{}_n(X_1^n)n(D)+\underset{i=1}{\overset{n}{}}h(X_i)+4\mathrm{log}n\text{bits, eventually, w.p.1.}$$
* The codes based on almost any realization of the universal Shannon random codebooks have codelengths $`\mathrm{}_n(X_1^n)`$ satisfying

$$\mathrm{}_n(X_1^n)n(D)+\underset{i=1}{\overset{n}{}}h(X_i)+(4+|\widehat{A}|)\mathrm{log}n\text{bits, eventually, w.p.1.}$$

We remark that the coefficients of the $`(\mathrm{log}n)`$ terms in (a) and (b) above are not the best possible, and can be significantly improved; see  for more details.

Perhaps somewhat surprisingly, it turns out that the performance of the above random codes is optimal up to terms of order $`(\mathrm{log}n)`$ bits. Recall that a code $`C_n`$ operating at distortion level $`D0`$ is defined by a triplet $`(B_n,\varphi _n,\psi _n)`$ where:

* $`B_n`$ is a subset of $`\widehat{A}^n`$, called the codebook,
* $`\varphi _n:A^nB_n`$ is the encoder,
* $`\psi _n:B_n\{0,1\}^{}`$ is a uniquely decodable map,

such that

$$\rho _n(x_1^n,\varphi _n(x_1^n))D,\text{for all}x_1^nA^n.$$

The codelengths $`\mathrm{}_n(X_1^n)`$ achieved by such a code are simply:

$$\mathrm{}_n(x_1^n)=\text{length of}[\psi _n(\varphi _n(x_1^n))]\text{bits}.$$

Theorem 21: Pointwise Converse for I.I.D. Sources : Let $`𝑿`$ be an i.i.d. source with distribution $`P`$ on $`A`$, and let $`\{C_n\}`$ be an arbitrary sequence of codes operating at distortion level $`D(0,\overline{D})`$, with associated codelengths $`\{\mathrm{}_n\}`$. Then:

$$\mathrm{}_n(X_1^n)n(D)+\underset{i=1}{\overset{n}{}}h(X_i)\mathrm{log}n\text{bits, eventually, w.p.1}$$

where $`h(x)`$ is defined as in Theorem 20.

The proof of Theorem 21 in  uses techniques quite different to those developed in this paper. In particular, the key step in the proof is established by an application of the generalized Kuhn-Tucker conditions of Bell and Cover .

Theorems 20 and 21 are next combined to yield “second order” refinements to Shannon’s classical source coding theorem. For a source $`𝑿`$ as in Theorem 21 and a $`D(0,\overline{D})`$, the minimal coding variance $`\sigma ^2=\sigma ^2(P,D)`$ of source $`P`$ at distortion level $`D`$ is

$`\sigma ^2=\sigma ^2(P,D)\stackrel{\mathrm{}}{=}\text{Var}[h(X_1)]`$ (42)
with $`h(x)`$ as in Theorem 20.

Theorem 22: Second Order Source Coding Theorems : Let $`𝑿`$ be an i.i.d. source with distribution $`P`$ on $`A`$ and with rate-distortion function $`(D)`$ (in bits). For $`D(0,\overline{D})`$:

* (CLT) There is a sequence of random variables $`G_n=G_n(P,D)`$ such that, for any sequence of codes $`\{C_n,\mathrm{}_n\}`$ operating at distortion level $`D`$, we have

$`\mathrm{}_n(X_1^n)n(D)\sqrt{n}G_n\text{bits, eventually, w.p.1}`$ (43)
and the $`G_n`$ converge in distribution to a Gaussian random variable

$$G_n\stackrel{𝒟}{}N(0,\sigma ^2)$$

where $`\sigma ^2=\sigma ^2(P,D)`$ is the minimal coding variance.
* (LIL) With $`\sigma ^2`$ as above, for any sequence of codes $`\{C_n,\mathrm{}_n\}`$ operating at distortion level $`D`$:

$`\underset{n\mathrm{}}{lim\; sup}{\displaystyle \frac{\mathrm{}_n(X_1^n)n(D)}{\sqrt{2n\mathrm{log}\mathrm{log}n}}}`$ $``$ $`\sigma \text{w.p.1}`$
$`\underset{n\mathrm{}}{lim\; inf}{\displaystyle \frac{\mathrm{}_n(X_1^n)n(D)}{\sqrt{2n\mathrm{log}\mathrm{log}n}}}`$ $``$ $`\sigma \text{w.p.1.}`$
* ($`\mathbf{}`$) Moreover, there exist codes $`\{C_n,\mathrm{}_n\}`$ operating at distortion level $`D`$, that asymptotically achieve equality universally in all these lower bounds.

Remark on Assumption (23): When the distortion measure does not satisfy assumption (23) \[as, for example, when $`\rho (x,y)=(xy)^2`$ with $`A=`$ and $`\widehat{A}`$ a finite subset of $``$\], we can modify $`\rho `$ to $`\rho ^{}(x,y)=\rho (x,y)f(x)`$, with $`f(x)=\mathrm{min}_{y\widehat{A}}\rho (x,y)`$, so that $`\rho ^{}`$ satisfies (23). Then, to generate codes operating at distortion level $`D`$ with respect to $`\rho `$, we can construct random codebooks for as before but do the encoding with respect to $`\rho ^{}(x,y)`$ at the random distortion level $`D_n=DE_{\widehat{P}_n}(f(X))`$. It is not hard to check that \[23, Theorem 2\] can be extended to apply when $`D`$ is replaced by the sequence $`\{D_n\}`$. Since $`D_nDE_P(f(X))`$ as $`n\mathrm{}`$, this results with the first order approximation

$$\frac{1}{n}\mathrm{log}Q_n^{}(B(X_1^n,D_n))R_1^\rho ^{}(\widehat{P}_n,Q^{},D_n).$$

Simple algebra then shows that

$$R_1^\rho ^{}(\widehat{P}_n,Q^{},D_n)=R_1^\rho (\widehat{P}_n,Q^{},D)$$

implying that all the results of Section 5.1.1 remain valid \[despite the fact that $`\rho `$ does not satisfy (23)\], with the function $`h()`$ taken in terms of the log-moment generating function $`\mathrm{\Lambda }_x(\lambda )`$ of the original distortion measure $`\rho `$ (and not that of the modified $`\rho ^{}`$).

#### 5.1.2 Critical Behavior

In view of Theorems 20 and 21 above, the codelengths $`\mathrm{}_n^{}(X_1^n)`$ of the best code operating at distortion level $`D`$ have:

$$\mathrm{}_n^{}(X_1^n)n(D)+\underset{i=1}{\overset{n}{}}h(X_i)+O(\mathrm{log}n)\text{bits.}$$

This reveals an interesting dichotomy in the behavior of the “pointwise” redundancy of the best code:

* Either the minimal coding variance $`\sigma ^2`$ (recall (42)) is nonzero, in which case the best rate at which optimality can be achieved is of order $`\sqrt{n}`$ bits by the CLT;
* or $`\sigma ^2=0`$, and the best redundancy rate is of order $`(\mathrm{log}n)`$ bits (cf. ).

Under certain conditions, in this section we give a precise characterization of when each of these two cases can occur. Before stating it, we briefly discuss two examples to gain some intuition.

Example 4: Lossless Compression: Lossless data compression can be considered as an extreme case of lossy compression, where $`𝑿`$ is an i.i.d. source with distribution $`P`$ on a finite set $`A=\widehat{A}`$, and the distortion level $`D`$ is set to zero. Here it is well-known that (ignoring the integer length constraints) the best code is given by the idealized Shannon code, $`\mathrm{}_n(X_1^n)=\mathrm{log}_2P^n(X_1^n)`$. Accordingly, the upper and lower bounds of Theorems 21 and 22 say that the best code has codelengths

$$\mathrm{}_n(X_1^n)=n(P)+\underset{i=1}{\overset{n}{}}h(X_i)$$

where $`(P)`$ is the entropy of $`P`$ in bits, and with

$$h(x)\stackrel{\mathrm{}}{=}\mathrm{log}_2P(x)(P),xA.$$

When is $`\sigma ^2=0`$? By its definition (42), $`\sigma ^2`$ is zero if and only if the function $`h(x)`$ is constant over $`x`$, which, in this case, can only happen if $`P(x)`$ is constant over $`xA`$. Therefore, here: $`\sigma ^2=0`$ if and only if the source has a uniform distribution over $`A`$.

Example 5: Binary Source with Hamming Distortion: Consider the simplest non-trivial lossy example: Let $`𝑿`$ be an i.i.d. source with Bernoulli($`p`$) distribution (for some $`p(0,1/2]`$), let $`A=\widehat{A}=\{0,1\}`$, and take $`\rho `$ to be Hamming distortion: $`\rho (x,y)=|xy|`$. For $`D(0,p)`$ it is not hard to evaluate all the relevant quantities explicitly (see, e.g., \[6, Example 2.7.1\] or \[20, Theorem 13.3.1\]). In particular, the optimal reproduction distribution $`Q^{}`$ is Bernoulli($`q`$), with $`q=(pD)/(12D)`$, and our function of interest is:

$$h(x)=\mathrm{log}_2\left(\frac{P(x)}{1D}\right)E_P\left[\mathrm{log}_2\left(\frac{P(X_1)}{1D}\right)\right].$$

Recalling that the minimal coding variance is zero if and only if $`h(x)`$ is constant, from the above expression we see that, similarly to the previous example, also here: $`\sigma ^2=0`$ if and only if the source has a uniform distribution.

For discrete sources, the next result gives conditions under which the characterization suggested by these two examples remains valid. Suppose $`A=\widehat{A}=\{a_1,a_2,\mathrm{},a_k\}`$ is a finite set, write $`\rho _{ij}`$ for $`\rho (a_i,a_j)`$, and assume that $`\rho `$ is symmetric and that $`\rho _{ij}=0`$ if and only if $`i=j`$. We call $`\rho `$ a permutation distortion measure, if all rows of the matrix $`(\rho _{ij})_{i,j=1,\mathrm{},k}`$ are permutations of one another.

Theorem 23: Variance Characterization : Let $`𝑿`$ be a discrete source with distribution $`P`$ and rate-distortion function $`R(D)`$. Assume that $`R(D)`$ is strictly convex over $`(0,\overline{D})`$. There are exactly two possibilities:

* Either $`\sigma ^2=\sigma ^2(P,D)`$ is only zero for finitely many $`D(0,\overline{D}).`$
* Or $`\sigma ^2=\sigma ^2(P,D)0`$ for all $`D(0,\overline{D})`$, in which case $`P`$ is the uniform distribution on $`A`$ and $`\rho `$ is a permutation distortion measure.

A general discussion of this problem, including the case of continuous sources, is given in . Also, in the lossless case, the problem of characterizing when $`\sigma ^2=0`$ for sources with memory is dealt with in .

Before moving on to waiting times and match-lengths we mention that, in a somewhat similar vain, the problem of understanding the best expected redundancy rate in lossy data compression has also been recently considered in ).

### 5.2 Waiting Times

Next we turn to waiting times. Recall that, given $`D0`$ and two independent realizations of the stationary ergodic processes $`𝑿`$ and $`𝒀`$, the waiting time $`W_n`$ was defined as the time of the first appearance of $`X_1^n`$ in $`𝒀`$ with distortion $`D`$ or less (see (27) for the precise definition). In Theorem 14 we gave conditions that identified the first order limiting behavior of $`W_n`$. In particular, when $`𝒀`$ is i.i.d., it was shown in Theorem 14 (a) that

$`{\displaystyle \frac{\mathrm{log}W_n}{n}}R_1(P,Q,D)\text{w.p.1}`$ (44)
where $`P`$ and $`Q`$ are the first order marginals of $`𝑿`$ and $`𝒀`$, respectively.

The next result gives conditions under which the SLLN-type statement of (44) can be refined to a CLT and a LIL.

Theorem 24: CLT and LIL for Waiting Times: Let $`𝑿`$ be a stationary $`\alpha `$-mixing process and $`𝒀`$ be an i.i.d. process, with marginal distributions $`P`$ and $`Q`$, on $`A`$ and $`\widehat{A}`$, respectively. Assume that the $`\alpha `$-mixing coefficients of $`𝑿`$ satisfy (38) and that $`D_3=E_{P\times Q}[\rho ^3(X,Y)]`$ is finite. Then for any $`D(D_{\mathrm{min}},D_{\mathrm{av}})`$ the following series converges

$`\sigma ^2\stackrel{\mathrm{}}{=}E_P[g^2(X_1)]+2{\displaystyle \underset{k=2}{\overset{\mathrm{}}{}}}E_P[g(X_1)g(X_k)]`$ (45)
with $`g(x)`$ defined as in (39), and, moreover:

* (CLT) With $`R_1=R_1(P,Q,D)`$:

$$\frac{\mathrm{log}W_nnR_1}{\sqrt{n}}\stackrel{𝒟}{}N(0,\sigma ^2).$$
* (LIL) The set of limit points of the sequence

$$\left\{\frac{\mathrm{log}W_nnR_1}{\sqrt{2n\mathrm{log}\mathrm{log}n}}\right\},n3$$

coincides with $`[\sigma ,\sigma ]`$, with probability one.

Proof Outline: For a bounded distortion measure $`\rho `$, Theorem 24 was proved in . To obtain the more general statement above combine the strong approximation of Theorem 13 with the second order AEP in Corollary 19 to get:

$`\mathrm{log}W_n=nR_1(P,Q,D)+{\displaystyle \underset{i=1}{\overset{n}{}}}g(X_i)+O(\mathrm{log}n)\text{w.p.1.}`$ (46)
Since $`𝑿`$ satisfies the mixing assumption (38), so does the process $`\{g(X_n)\}`$. Also, since $`\lambda ^{}<0`$, the function $`\mathrm{\Lambda }_x(\lambda ^{})`$ is bounded above by zero, and by Jensen’s inequality it is bounded below by $`\lambda ^{}E_Q[\rho (x,Y)].`$ Therefore,

$$|\mathrm{\Lambda }_x(\lambda ^{})||\lambda ^{}|E_Q[\rho (x,Y)]$$

and this, together with Hölder’s inequality and the definition of $`g(x),`$ imply that $`E_P[|g(X_1)|^3]<\mathrm{}`$. Therefore we can apply the CLT of \[64, Theorem 1.7\] to the process $`\{g(X_n)\}`$ in order to deduce the CLT-part of the theorem from (46). Similarly, applying the LIL of  to $`\{g(X_n)\}`$, from (46) we get the LIL-part of the theorem. $`\mathrm{}`$

Remark 5: When the variance $`\sigma ^2`$ in (45) is positive, then the functional versions of the above CLT and LIL given in  still hold, under exactly the conditions of Theorem 24. (This follows by applying the functional CLT of \[64, Theorem 1.7\] and the functional LIL of \[60, Theorem 1 (IV)\].)

### 5.3 Match-Lengths and Duality

Finally we turn to our last application, match-lengths. Recall that, given a distortion level $`D0`$ and two independent realizations of the processes $`𝑿`$ and $`𝒀`$, the match-length $`L_m`$ is defined as the length $`\mathrm{}`$ of the longest prefix $`X_1^{\mathrm{}}`$ that appears (with distortion $`D`$ or less) starting somewhere in the “database” $`Y_1^m.`$ See (31) for the precise definition. As we briefly mentioned in Section 3.4, there is a duality relationship between match-lengths and waiting times: Roughly speaking, long matches mean short waiting times, and vice-versa; see (33).

Although the relation (33) is not as simple as the duality (32) for exact matching, it is still possible to use (33) to translate the asymptotic results for $`W_n`$ to corresponding results for $`L_m`$. These are given in Theorem 25 below. This translation, carried out in , is more delicate than in the case of exact matching. For example, in order to prove the CLT for the match-lengths $`L_m`$ one invokes the functional CLT for the waiting times (see Remark 5 above and the proof of Theorem 4 in ).

Theorem 25: Match-Lengths Asymptotics: Let $`𝑿`$ be a stationary process and $`𝒀`$ be an i.i.d. process, with marginal distributions $`P`$ and $`Q`$, on $`A`$ and $`\widehat{A}`$, respectively. Assume that $`D_3=E_{P\times Q}[\rho ^3(X,Y)]`$ is finite. Then for any $`D(D_{\mathrm{min}},D_{\mathrm{av}})`$ we have

$$\text{(LLN)}\frac{L_m}{\mathrm{log}m}\frac{1}{R_1}\text{w.p.1}$$

where $`R_1=R_1(P,Q,D)`$. If, moreover, the $`\alpha `$-mixing coefficients of $`𝑿`$ satisfy (38) and the variance $`\sigma ^2`$ in (45) is nonzero, then, with $`\tau ^2\stackrel{\mathrm{}}{=}\sigma ^2R_1^3`$, we have,

(CLT) $`{\displaystyle \frac{L_m\frac{\mathrm{log}m}{R_1}}{\sqrt{\mathrm{log}m}}}\stackrel{𝒟}{}N(0,\tau ^2)`$
(LIL) $`\underset{m\mathrm{}}{lim\; sup}{\displaystyle \frac{L_m\frac{\mathrm{log}m}{R_1}}{\sqrt{2\mathrm{log}m\mathrm{log}\mathrm{log}\mathrm{log}m}}}=\tau \text{w.p.1.}`$
The results of Theorem 25 were proved in  for any bounded distortion measure $`\rho `$. The slightly more general version stated above is proved in exactly the same way, using the results of Section 4 in place of Theorems 2 and 3 of .

## 6 Random Fields – First Order Results

This and the following section are devoted to generalizations of the results of Sections 2–5 to the case of random fields. Specifically, the role of the processes $`𝑿`$ and $`𝒀`$ will now be played by stationary ergodic random fields $`𝑿=\{X_u;u^d\}`$ and $`𝒀=\{Y_u;u^d\}`$. As we will see, many of the problems that we considered have natural analogs in this case, and the overall theme carries over: The generalized AEP and its refinement can be extended to random fields, and the corresponding questions in data compression and pattern matching can be answered following the same path as before.

### 6.1 Notation and Definitions

The following definitions and notation will remain in effect throughout Sections 6 and 7.

We consider two random fields $`𝑿=\{X_u;u^d\}`$ and $`𝒀=\{Y_u;u^d\}`$, $`d2`$, taking values in $`A`$ and $`\widehat{A}`$, respectively, and indexed by points $`u=(u_1,u_2,\mathrm{},u_d)`$ on the integer lattice $`^d`$. As before, $`A`$ and $`\widehat{A}`$ are complete, separable metric spaces, equipped with their Borel $`\sigma `$-fields $`𝒜`$ and $`\widehat{𝒜}`$, respectively. Let $``$ and $``$ denote the (infinite-dimensional) measures of the entire random fields $`𝑿`$ and $`𝒀`$. Unless explicitly stated otherwise, we always assume that $`𝑿`$ and $`𝒀`$ are independent of each other.

Throughout the rest of the paper we will assume that $`𝑿`$ and $`𝒀`$ are stationary and ergodic. To be precise, by that we mean that the Abelian group of translations $`\{T_u:u^d\}`$ acts on both $`(A^^d,𝒜^^d,)`$ and $`(\widehat{A}^^d,\widehat{𝒜}^^d,)`$ in a measure-preserving, ergodic manner; see  for a detailed exposition.

For $`v,w^d`$, the distance between $`v`$ and $`w`$ is defined by

$$d(v,w)\stackrel{\mathrm{}}{=}\underset{1id}{\mathrm{max}}|v_iw_i|$$

and the distance between two subsets $`V,W^d`$ is

$$d(V,W)\stackrel{\mathrm{}}{=}\underset{vV,wW}{inf}d(v,w).$$

Given $`v,w^d`$, we let $`[v,w]=\{u^d:v_ju_jw_j\text{ for all }j\}`$, where $`[v,w]`$ is empty in case $`v_j>w_j`$ for some $`j`$.

We write $`C(n)`$ for the $`d`$-dimensional cube of side $`n1`$,

$`C(n)=\{u^d:1u_jn\text{ for all }j\}`$
and $`[0,\mathrm{})`$ for the “infinite cube”

$$[0,\mathrm{})=\{u^d:u_j0\text{ for all }j\}.$$

For an arbitrary subset $`U^d`$ we let $`|U|`$ denote its size; for example, $`|C(n)|=n^d`$. Also for $`U^d`$ we write

$$X_U\stackrel{\mathrm{}}{=}\{X_u;uU\}$$

so that, in particular, $`X_{[0,\mathrm{})}=\{X_u;u_j0\text{ for all }j\}.`$ For $`V^d`$ and $`u^d`$ we let $`u+U`$ denote the translate

$$u+V=\{u+v:vV\}.$$

For each $`n1`$, let $`P_n`$ denote the marginal distribution of $`X_{C(n)}`$ on $`A^{n^d}`$, and similarly write $`Q_n`$ for the distribution of $`Y_{C(n)}`$. Let $`\rho :A\times \widehat{A}[0,\mathrm{})`$ be an arbitrary nonnegative (measurable) function, and define a sequence of single-letter distortion measures $`\rho _n:A^{n^d}\times \widehat{A}^{n^d}[0,\mathrm{})`$, $`n1`$, by

$`\rho _n(x_{C(n)},y_{C(n)})\stackrel{\mathrm{}}{=}{\displaystyle \frac{1}{n^d}}{\displaystyle \underset{uC(n)}{}}\rho (x_u,y_u)x_{C(n)}A^{n^d},y_{C(n)}\widehat{A}^{n^d}.`$
Given $`D0`$ and $`x_{C(n)}A^{n^d}`$, we write $`B(x_{C(n)},D)`$ for the distortion-ball of radius $`D`$:

$$B(x_{C(n)},D)=\{y_{C(n)}\widehat{A}^{n^d}:\rho _n(x_{C(n)},y_{C(n)})D\}.$$

### 6.2 Generalized AEP

It is well-known that the classical AEP

$`{\displaystyle \frac{1}{n}}\mathrm{log}P_n(X_1^n)H()\text{w.p.1}`$
generalizes to the case of finite-alphabet random fields on $`^d`$, as well as to other amenable group actions . In this section we give two versions of the generalized AEP of Theorems 1 and 4 to the case of random fields on $`^d`$.

##### $`𝒀`$ is i.i.d.

In the notation of Section 6.1, we take $`𝑿`$ to be a stationary ergodic random field with first order marginal $`P_1=P,`$ and $`𝒀`$ to be i.i.d. with first order marginal $`Q_1=Q`$. We define $`D_{\mathrm{min}}`$ and $`D_{\mathrm{av}}`$ as in the one-dimensional case (recall equations (7) and (8)), and assume that $`\rho (x,y)`$ is not essentially constant for ($``$-almost) all $`xA`$, that is, $`D_{\mathrm{min}}<D_{\mathrm{av}}.`$

A simple examination of the proof of Theorem 1 shows that it extends verbatim to the case of random fields, with the only difference that instead of the usual ergodic theorem we now need to invoke the ergodic theorem for $`^d`$ actions; see \[52, Chapter 6\]. We thus obtain:

Theorem 26. Generalized AEP when $`𝐘`$ is i.i.d.: Let $`𝑿`$ be a stationary ergodic random field on $`^d`$ and $`𝒀`$ be i.i.d., with marginal distributions $`P`$ and $`Q`$ on $`A`$ and $`\widehat{A}`$, respectively. Assume that $`D_{\mathrm{av}}=E_{P\times Q}[\rho (X,Y)]`$ is finite. Then for any $`D(D_{\mathrm{min}},D_{\mathrm{av}})`$

$`{\displaystyle \frac{1}{n^d}}\mathrm{log}Q^{n^d}(B(X_{C(n)},D))R_1(P,Q,D)\text{w.p.1}`$
with the (one-dimensional) rate-function $`R_1(P,Q,D)`$ defined as in Theorem 1.

##### $`𝒀`$ is not i.i.d.

Let $`𝑿`$ and $`𝒀`$ be stationary random fields and define $`D_{\mathrm{av}}`$ and $`D_{\mathrm{max}}`$ exactly as in the one-dimensional case (recall (8) and (14)). We assume that the distortion measure $`\rho `$ is essentially bounded, $`D_{\mathrm{max}}<\mathrm{}`$, and define

$`D_{\mathrm{min}}\stackrel{\mathrm{}}{=}\underset{n1}{sup}D_{\mathrm{min}}^{(n)}=\underset{n\mathrm{}}{lim}D_{\mathrm{min}}^{(n)}`$ (47)
where

$`D_{\mathrm{min}}^{(n)}\stackrel{\mathrm{}}{=}E_{P_n}[\underset{Y_{C(n)}Q_n}{\mathrm{ess}\mathrm{inf}}\rho _n(X_{C(n)},Y_{C(n)})].`$ (48)
To see that the limit in (47) exists and equals the supremum, first note that $`\{n^dD_{\mathrm{min}}^{(n)}\}`$ is an increasing sequence, and that $`D_{\mathrm{min}}^{(nk)}D_{\mathrm{min}}^{(k)}`$ for all $`n,k1`$. Now fix $`k1`$ arbitrary. Given $`nk`$ we write $`n=mk+r`$ for some $`0rk1`$, so that

$$n^dD_{\mathrm{min}}^{(n)}(mk)^dD_{\mathrm{min}}^{(mk)}(mk)^dD_{\mathrm{min}}^{(k)}.$$

Since $`n/mk1`$ as $`n\mathrm{}`$, this implies that

$$\underset{n\mathrm{}}{lim\; inf}D_{\mathrm{min}}^{(n)}D_{\mathrm{min}}^{(k)}.$$

Since $`k`$ was arbitrary we are done.

Finally, we assume once again that the distortion measure $`\rho `$ is not essentially constant, that is, $`D_{\mathrm{min}}<D_{\mathrm{av}}`$. Our next result is the random fields analog of Theorem 4; it is proved in Appendix C.

Theorem 27. Generalized AEP rate function. Let $`𝑿`$ and $`𝒀`$ be stationary random fields. Assume that $`\rho `$ is bounded, and that with $``$-probability one, conditional on $`X_{[0,\mathrm{})}=x_{[0,\mathrm{})}`$, the random variables $`\{\rho _n(x_{C(n)},Y_{C(n)})\}`$ satisfy a large deviations principle with some deterministic, convex rate-function. Then for all $`D(D_{\mathrm{min}},D_{\mathrm{av}})`$, except possibly at $`D=D_{\mathrm{min}}^{(\mathrm{})}`$,

$`\underset{n\mathrm{}}{lim}{\displaystyle \frac{1}{n^d}}\mathrm{log}Q_n(B(X_{C(n)},D))=R(,,D)\text{w.p.1}`$ (49)
where $`D_{\mathrm{min}}^{(\mathrm{})}`$ and the rate-function $`R(,,D)`$ are defined as in the one-dimensional case, by (17) and (16), respectively, and the rate-functions $`R_n(P_n,Q_n,D)`$ are now defined as

$`R_n(P_n,Q_n,D)=\underset{V_n}{inf}{\displaystyle \frac{1}{n^d}}H(V_nP_n\times Q_n)`$
with the infimum taken over all joint distributions $`V_n`$ on $`A^{n^d}\times \widehat{A}^{n^d}`$ such that the $`A^{n^d}`$-marginal of $`V_n`$ is $`P_n`$ and $`E_{V_n}[\rho _n(X_{C(n)},Y_{C(n)})]D`$.

Remark 6: Suppose that $`(𝑿,𝒀)`$ is a stationary random field satisfying a “process-level LDP” with a convex, good rate-function. To be precise, given $`x_{C(n)}A^{n^d}`$, write $`x^{(n)}`$ for the periodic extension of $`x_{C(n)}`$ to an infinite realization in $`A^{[0,\mathrm{})}`$ and let $`X^{(n)}`$ and $`Y^{(n)}`$ denote the periodic extensions of $`X_{C(n)}`$ and $`Y_{C(n)}`$, respectively. The process-level empirical measure $`_n`$ induced by $`𝑿`$ and $`𝒀`$ on $`(A^{[0,\mathrm{})}\times \widehat{A}^{[0,\mathrm{})})`$ is defined by

$$_n\stackrel{\mathrm{}}{=}\frac{1}{n^d}\underset{uC(n)}{}\delta _{(X_{u+[0,\mathrm{})}^{(n)},Y_{u+[0,\mathrm{})}^{(n)})}$$

where $`\delta _{s,s^{}}`$ denotes the measure assigning unit mass to the joint realization $`(s,s^{})A^{[0,\mathrm{})}\times \widehat{A}^{[0,\mathrm{})}`$, and $`X_{u+[0,\mathrm{})}^{(n)}`$ (or $`Y_{u+[0,\mathrm{})}^{(n)}`$) denotes $`X^{(n)}`$ (respectively, $`Y^{(n)}`$) shifted by $`u`$ \[i.e., the value of $`X_{u+[0,\mathrm{})}^{(n)}`$ at position $`v`$ is the same as the value of $`X^{(n)}`$ at position $`u+v`$; similarly for $`Y_{u+[0,\mathrm{})}^{(n)}`$.\] By assuming that $`(𝑿,𝒀)`$ satisfy a “process-level LDP” we mean that the sequence of measures $`\{_n\}`$ satisfies the LDP in the space of stationary probability measures on $`(A^{[0,\mathrm{})}\times \widehat{A}^{[0,\mathrm{})})`$ equipped with the topology of weak convergence, with some convex, good rate-function $`I()`$. These assumptions are satisfied by many of the random field models used in applications, and in particular by a large class of Gibbs fields (see, e.g.,  for general theory and  for examples in the areas of image processing and image analysis).

As in the one-dimensional case, suppose that the process-level LDP condition holds, and that the distortion measure $`\rho `$ is bounded and continuous on $`A\times \widehat{A}`$. Then with $``$-probability one, conditional on $`X_{[0,\mathrm{})}=x_{[0,\mathrm{})}`$, the sequence $`\{\rho _n(x_{C(n)},Y_{C(n)})\}`$ satisfies the LDP upper bound with respect to the deterministic, convex rate-function $`J()`$ as in Remark 3. Moreover, assuming sufficiently strong mixing properties for $`𝒀`$ one may also verify the corresponding lower bound (for example, by adapting the stochastic subadditivity approach of ).

### 6.3 Applications

In Sections 6.3.1 and 6.3.2 below we consider the random field analogs of the problems discussed in Section 3 in the context of one-dimensional processes. In the instances when our analysis was restricted to i.i.d. processes, the extension to random fields is trivial – an i.i.d. random field is no different from an i.i.d. process. For that reason, we only give the full statements of corresponding random fields results when the generalization from $`d=1`$ to $`d2`$ does involve some modifications. Otherwise, only a brief description of the corresponding results is mentioned.

#### 6.3.1 Lossy Data Compression

Here we very briefly discuss the problem of data compression, when the data is in the form of a two- or more generally a $`d`$-dimensional array. In this case, the underlying data source is naturally modeled as a $`d`$-dimensional random field. Extensive discussions of the general information-theoretic problems on random fields are given in  and the recent monograph ; see also .

First we discuss the results given in Section 3.1. The construction of the random codebooks described there generalizes to random fields in an obvious fashion, and the statement as well as the proof of Theorem 9 remain unchanged. Following the notation exactly as developed for i.i.d. sources, the strengthened coding theorems given in Theorems 10 and 11 follow by combining (the obvious generalization of) Theorem 9 with the generalized AEP of Theorem 26.

Similarly, the mismatched-codebook results of Section 3.2 only rely on Theorem 9 and the generalized AEP of Theorem 1, and therefore immediately generalize to the random field case. Finally Theorems 15 and 16 in Section 3.5 are only stated for i.i.d. processes, hence, as mentioned above, they trivially extend to random fields.

#### 6.3.2 Waiting Times

Here we consider the natural $`d`$-dimensional analogs of the waiting times questions considered in Section 3.3. Given two independent realizations of the random fields $`𝑿`$ and $`𝒀`$, our main quantity of interest here is how “far” we have to look in $`𝒀`$ until we find a match for the pattern $`X_{C(n)}`$ with distortion $`D`$ or less. Given $`n1`$ and a distortion level $`D0`$, we define the waiting time $`W_n`$ as the smallest length $`i`$ such that a copy of the pattern $`X_{C(n)}`$ appears somewhere in $`Y_{C(i+n1)}`$, with distortion $`D`$ or less. Formally,

$`W_n=inf\{i1:\rho _n(X_{C(n)},Y_{u+C(n)})D\text{for some}u[0,i1]^d\}`$
with the convention that the infimum of the empty set equals $`+\mathrm{}`$.

In the one-dimensional case our main tool in investigating the asymptotic behavior of the waiting times was the strong approximation in Theorem 13. Roughly speaking, Theorem 13 stated that the waiting time $`W_n`$ for a $`D`$-close match of $`X_1^n`$ in $`𝒀`$ is inversely proportional to the probability $`Q_n(B(X_1^n,D))`$ of such a match. In Theorem 28 below we generalize this result to the $`d`$-dimensional case by showing that the $`d`$-dimensional volume $`(W_n)^d`$ we have to search in $`𝒀`$ in order to find a $`D`$-close match for $`X_{C(n)}`$ is, roughly, inversely proportional to the probability $`Q_n(B(X_{C(n)},D))`$ of finding such a match.

Before stating Theorem 28 we need to recall the following definition. Dobrushin’s non-uniform $`\varphi `$-mixing coefficients of a stationary random field $`𝒀`$ are

$`\varphi _{\mathrm{}}(k)=sup\{|(B|A)(B)|:`$ $`B\sigma (Y_U),A\sigma (Y_V),(A)>0`$
$`|U|\mathrm{},|V|<\mathrm{},d(U,V)k\}`$
where $`\sigma (Y_U)`$ denotes the $`\sigma `$-field generated by the random variables $`Y_U`$, $`U^d`$. See \[54, Chapter 6\] or  for detailed discussions of the coefficients $`\{\varphi _{\mathrm{}}(k)\}`$ and their properties.

Theorem 28. Strong Approximation: Let $`𝑿`$ and $`𝒀`$ be stationary ergodic random fields, and assume that the non-uniform $`\varphi `$-mixing coefficients of $`𝒀`$ satisfy

$`\underset{n\mathrm{}}{lim\; sup}{\displaystyle \underset{j=1}{\overset{\mathrm{}}{}}}(j+1)^{d1}\varphi _n(jn)<\mathrm{}.`$ (50)
If $`Q_n(B(X_{C(n)},D))>0`$ eventually with probability one, then for any $`ϵ>0`$:

$`(1+ϵ)\mathrm{log}n\mathrm{log}[W_n^dQ_n(B(X_{C(n)},D))](d+1+ϵ)\mathrm{log}n\text{eventually, w.p.1.}`$
The proof of Theorem 28 is a straightforward modification of the corresponding one-dimensional argument in ; it is given in Appendix D.

Remark 7: The mixing condition (50) is satisfied by a rather large class of stationary random fields. For example in the case of Markov random fields, it is easy to check that under Dobrushin’s uniqueness condition the limit in (50) is finite; see \[34, Section 8.2\] or  for more details.

Next we combine the above strong approximation result with the generalized AEPs of Theorems 26 and 27, to read off the first order asymptotic behavior of the waiting times. Theorem 29 below generalizes Theorem 14 to the random field case.

Theorem 29. SLLN for Waiting Times: Let $`𝑿`$ and $`𝒀`$ be stationary ergodic random fields:

(a) If $`𝒀`$ is i.i.d. and the average distortion $`D_{\mathrm{av}}`$ is finite, then for any $`D(D_{\mathrm{min}},D_{\mathrm{av}})`$

$`{\displaystyle \frac{1}{n^d}}\mathrm{log}W_n^dR_1(P_1,Q_1,D)\text{w.p.1.}`$
(b) Suppose that the conditions of Theorem 27 are satisfied, and that $`𝒀`$ also satisfies the mixing assumption (50). Then, for any $`D(D_{\mathrm{min}}^{(\mathrm{})},D_{\mathrm{av}})`$:

$`{\displaystyle \frac{1}{n^d}}\mathrm{log}W_n^dR(,,D)\text{w.p.1.}`$
## 7 Random-Fields – Second Order Results

Finally we turn to the random field extensions of the second order results of Sections 4 and 5. In Section 7.1 we state the random field analog of the second order generalized AEP, and in 7.2 we discuss its application to the problems of lossy data compression and pattern matching.

### 7.1 Refinements of Generalized AEP

Let $`𝑿`$ be a stationary ergodic random field with marginal distribution $`P`$ on $`A`$, and let $`Q`$ be a fixed probability measure on $`\widehat{A}`$. We will assume throughout that the distortion measure $`\rho `$ has a finite third moment,

$`D_3\stackrel{\mathrm{}}{=}E_{P\times Q}[\rho ^3(X,Y)]<\mathrm{}`$ (51)
and that it is not essentially constant, i.e., $`D_{\mathrm{min}}<D_{\mathrm{av}}`$, with $`D_{\mathrm{min}}`$ and $`D_{\mathrm{av}}`$ defined as before (cf. (7) and (8)).

The goal of this section is to give the random field analogs of Theorems 17 and 18 and of Corollary 19 from the one-dimensional case.

An examination of the proof of Theorem 17 in  shows that its proof only depends on the ergodicity of $`𝑿`$ and the i.i.d. structure of the product measures $`Q^n`$. Simply replacing the application of the ergodic theorem by the ergodic theorem for $`^d`$ actions \[52, Chapter 6\] immediately yields the following generalization: As long as condition (51) is satisfied, for all $`D(D_{\mathrm{min}},D_{\mathrm{av}})`$ we have

$`\mathrm{log}Q^{n^d}(B(X_{C(n)},D))=n^dR_1(\widehat{P}_n,Q,D)+{\displaystyle \frac{d}{2}}\mathrm{log}n+O(1)\text{w.p.1}`$ (52)
where $`\widehat{P}_n`$ is now the empirical measure induced by $`X_{C(n)}`$ on $`A`$.

In order to generalize Theorem 18 to $`^d`$ we need to introduce a measure of dependence analogous to $`\alpha `$-mixing in the one-dimensional case. For a stationary random field $`𝑿`$ on $`^d`$ we define the uniform $`\alpha `$-mixing coefficients of $`𝑿`$ by

$`\alpha (k)=sup\{|(AB)(A)(B)|:`$ $`A\sigma (X_U),B\sigma (X_V),d(U,V)k\}`$
where, as before, $`\sigma (X_U)`$ denotes the $`\sigma `$-field generated by the random variables $`Y_U`$. See  for more details.

Apart from ergodicity, the main technical ingredient in the proof of Theorem 18 above (see also the proof of \[23, Theorem 3\]) is the LIL for $`𝑿`$. Similarly to the one-dimensional case, the LIL for a random field $`𝑿`$ holds as soon as the following mixing condition is satisfied

$`\alpha (k)Ck^{3d(1+ϵ)},\text{for some }ϵ>0\text{ and }C<\mathrm{}.`$ (53)
\[This follows from the almost sure invariance principle in \[8, Theorem 1\].\]

Assuming that (53) and the third moment condition (51) both hold, we get the following generalization of Theorem 18. For all $`D(D_{\mathrm{min}},D_{\mathrm{av}})`$,

$`n^dR_1(\widehat{P}_n,Q,D)=n^dR_1(P,Q,D)+{\displaystyle \underset{uC(n)}{}}g(X_u)+O(\mathrm{log}\mathrm{log}n)\text{w.p.1}`$ (54)
with $`g(x)`$ defined exactly as in the one-dimensional case (39).

Combining (52) and (54) gives the following generalization of Corollary 19:

Theorem 30: Second Order Generalized AEP: Let $`𝑿`$ be a stationary ergodic random field with marginal distribution $`P`$ on $`A`$, and let $`Q`$ be an arbitrary probability measure on $`\widehat{A}.`$ Assume that the uniform $`\alpha `$-mixing coefficients of $`𝑿`$ satisfy (53) and that $`D_3=E_{P\times Q}[\rho ^3(X,Y)]`$ is finite. Then for any $`D(D_{\mathrm{min}},D_{\mathrm{av}})`$, and with $`g(x)`$ defined as in (39),

$$\mathrm{log}Q^{n^d}(B(X_1^n,D))=n^dR_1(P,Q,D)+\underset{uC(n)}{}g(X_u)+\frac{d}{2}\mathrm{log}n+O(\mathrm{log}\mathrm{log}n)\text{w.p.1.}$$

### 7.2 Applications

Next we discuss applications of the second order generalized AEP to the $`d`$-dimensional analogs of the data compression and pattern matching problems of Section 4. As in Section 6.3, the only results stated explicitly are those whose extensions to $`^d`$ require modifications.

As mentioned in Section 6.3.1, the one-dimensional construction of the random codes, as well as the main tool used in their analysis, Theorem 9, immediately generalize to the random field case. And since all the second order results of Section 5.1 (Theorems 20–23) are stated for i.i.d. sources, their statements as well as proofs carry over verbatim to this case.

For the problem of waiting times, we can use the second order generalized AEP of Theorem 30 to refine the SLLN of Theorem 29

$`{\displaystyle \frac{1}{n^d}}\mathrm{log}W_n^dR_1(P,Q,D)\text{w.p.1}`$
to a corresponding CLT and LIL as in the one-dimensional case. These refinements are stated in Theorem 31 below. Its proof is identical to that of Theorem 24 in the one dimensional case. The only difference here is that we need to invoke the CLT and LIL for the partial sums of the random field $`\{g(X_u);u^d\}`$. Under the conditions of the theorem, these follow from the almost sure invariance principle of \[8, Theorem 1\].

Theorem 31: Let $`𝑿`$ be a stationary ergodic random field and $`𝒀`$ be i.i.d., with marginal distributions $`P`$ and $`Q`$ on $`A`$ and $`\widehat{A}`$, respectively. Assume that the uniform $`\alpha `$-mixing coefficients of $`𝑿`$ satisfy (53) and that $`D_3=E_{P\times Q}[\rho ^3(X,Y)]`$ is finite. Then for any $`D(D_{\mathrm{min}},D_{\mathrm{av}})`$ the following series is absolutely convergent

$`\sigma ^2\stackrel{\mathrm{}}{=}{\displaystyle \underset{u^d}{}}E_P[g(X_\mathrm{𝟎})g(X_u)]`$ (55)
with $`g(x)`$ defined as in (39), and, moreover:

* (CLT) With $`R_1=R_1(P,Q,D)`$:

$$\frac{\mathrm{log}W_n^dn^dR_1}{n^{d/2}}\stackrel{𝒟}{}N(0,\sigma ^2).$$
* (LIL) The set of limit points of the sequence

$$\left\{\frac{\mathrm{log}W_n^dn^dR_1}{\sqrt{2n^d\mathrm{log}\mathrm{log}n}}\right\},n3$$

coincides with $`[\sigma ,\sigma ]`$, with probability one.

## Acknowledgments

We thank Tamás Linder and Yuval Peres for useful discussions regarding Theorems 7 and 8.

## Appendix A Proof of Theorem 7

We prove the upper and lower bounds separately. For the upper bound, recalling the definition of $`r_n(X_1^n)`$ in (20) we observe that

$$r_n(X_1^n,D)\frac{1}{n}\mathrm{log}P_n(B(X_1^n,D))\frac{1}{n}\mathrm{log}Q^n(X_1^n)$$

where the second term converges to $`H(P)+H(PQ)`$ as $`n\mathrm{}`$, by the ergodic theorem. Since the first term is increasing in $`D`$, for any fixed $`D>0`$ we have with $``$-probability one:

$`\underset{\begin{array}{c}n\mathrm{}\\ D0\end{array}\text{ }}{lim\; sup}r_n(X_1^n,D)H(P)+H(PQ)+\underset{n\mathrm{}}{lim\; sup}{\displaystyle \frac{1}{n}}\mathrm{log}P_n(B(X_1^n,D)).`$ (58)
Now the pointwise source coding theorem (see \[51, Theorems 1 and 5\]) implies that

$`\underset{n\mathrm{}}{lim\; inf}{\displaystyle \frac{1}{n}}\mathrm{log}P_n(B(X_1^n,D))R(D)\text{w.p.1}`$ (59)
where $`R(D)`$ is the rate-distortion function of the source $`𝑿`$ (in nats). From equations (58) and (59) we get

$`\underset{\begin{array}{c}n\mathrm{}\\ D0\end{array}\text{ }}{lim\; sup}r_n(X_1^n,D)`$ $``$ $`H(P)+H(PQ)R(D)`$
$``$ $`H(P)+H(PQ)H()+H(P)R_1(D)\text{w.p.1}`$
where $`R_1(D)`$ denotes the first order rate-distortion function of $`𝑿`$, $`H()`$ is the entropy rate of $`𝑿`$ (both in nats), and the second inequality follows from the Wyner-Ziv bound; see \[74, Remark 4\]. The assumption that $`\rho (x,y)=0`$ if and only if $`x=y`$ implies that $`lim_{D0}R_1(D)=H(P)`$, so letting $`D0`$ the above right hand side becomes $`H(P)+H(PQ)H()`$ and it is an easy calculation to verify that this is indeed the same as $`H()`$. This gives the required upped bound.

For the lower bound we proceed similarly by noting that

$$r_n(X_1^n,D)\frac{1}{n}\mathrm{log}P_n(X_1^n)\frac{1}{n}\mathrm{log}Q^n(B(X_1^n,D)),$$

where the first term converges to $`H()`$ by the classical AEP (as $`n\mathrm{}`$). Since the second term is decreasing in $`D`$, for any fixed $`D>0`$ small enough we have with probability one:

$`\underset{\begin{array}{c}n\mathrm{}\\ D0\end{array}\text{ }}{lim\; inf}r_n(X_1^n,D)`$ $``$ $`H()\underset{n\mathrm{}}{lim\; sup}{\displaystyle \frac{1}{n}}\mathrm{log}Q^n(B(X_1^n,D))`$
$`=`$ $`H()+R_1(P,Q,D)`$
where the last step follows from the generalized AEP in Theorem 1 (note that $`D_{\mathrm{min}}=0`$ here). By the characterization of the rate-function in Proposition 2 we know that

$$R_1(P,Q,D)=\underset{\lambda ^{}0}{sup}[\lambda ^{}D\mathrm{\Lambda }(\lambda ^{})][\lambda D\mathrm{\Lambda }(\lambda )]=E_P\left[\mathrm{log}E_Q\left(e^{\lambda (\rho (X,Y)D)}\right)\right]$$

for any fixed $`\lambda <0`$. Therefore, for any $`D`$ small enough and $`\lambda <0`$ we have

$`\underset{\begin{array}{c}n\mathrm{}\\ D0\end{array}\text{ }}{lim\; inf}r_n(X_1^n,D)H()E_P\left[\mathrm{log}E_Q\left(e^{\lambda (\rho (X,Y)D)}\right)\right]\text{w.p.1.}`$
Letting $`D0`$ and then $`\lambda \mathrm{}`$, by the dominated convergence theorem (and the assumption $`\rho (x,y)=0`$ iff $`x=y`$) the right hand side above converges to $`H()+H(PQ)+H(P)=H(),`$ proving the lower bound.

Finally, since for each fixed $`n`$ the limit as $`D0`$ of $`r_n(X_1^n,D)`$ exists, it follows that the repeated limit $`lim_nlim_D`$ also exists and is equal to the double limit $`H(PQ)`$. $`\mathrm{}`$

## Appendix B Proof of Theorem 8

Part (a): Fixing $`n`$, let $`f_n=dP_n/dQ_n`$ and consider the set

$$A_n\stackrel{\mathrm{}}{=}\{x_1^n:Q_n(B(x_1^n,D))>0D>0,f_n(x_1^n)=\underset{D0}{lim\; sup}\frac{P_n(B(x_1^n,D))}{Q_n(B(x_1^n,D))}=\underset{D0}{lim\; inf}\frac{P_n(B(x_1^n,D))}{Q_n(B(x_1^n,D))}\}.$$

By the Radon-Nikodym theorem (cf. \[29, Theorems 1.6.1, 1.6.2\]), we know that $`Q_n(A_n)=1`$, hence also $`P_n(A_n)=1`$. With $`(_nA_n^c)=0`$, we conclude the proof of part (a) by applying Theorem 6 for $`M_n=Q^n`$ (in which case $`H_n0`$).

Part (b): As $`Q(A_1)=1`$, in particular $`Q(B(x,D))>0`$ for all $`D>0`$ and $`Q`$-almost every $`x^d`$ (hence also for $`P=P_1`$-almost every $`x^d`$), implying that $`D_{\mathrm{min}}`$ of (7) is zero. The same argument yields also that $`P(B(x,D))>0`$ for all $`D>0`$ and $`P`$-almost every $`x`$, hence $`D_{\mathrm{min}}`$ is still zero if we replace $`Q`$ by $`P`$. Thus, for all $`D<\mathrm{min}\{E_{P\times Q}[\rho (X,Y)],E_{P\times P}[\rho (X,Y)]\}`$, applying Theorem 1 twice we get

$$\underset{n\mathrm{}}{lim}r_n(X_1^n,D)=R_1(P,Q,D)R_1(P,P,D)\text{w.p.1.}$$

For any probability measure $`\mu `$ and any $`\lambda 0`$, let

$$\mathrm{\Lambda }(\lambda ;\mu )=\left[\mathrm{log}e^{\lambda \rho (x,y)}𝑑\mu (y)\right]𝑑P(x).$$

Fixing $`D>0`$ small enough, we have by Proposition 2 that $`R_1(P,P,D)=\lambda D\mathrm{\Lambda }(\lambda ;P)`$ for the unique $`\lambda =\lambda (D)<0`$ such that $`\mathrm{\Lambda }^{}(\lambda ;P)=D`$, whereas $`R_1(P,Q,D)\lambda D\mathrm{\Lambda }(\lambda ;Q)`$. Since $`E_{P\times P}[\rho (X,Y)]>0`$, we have also that $`\lambda (D)\mathrm{}`$ as $`D0`$ (see (11)). Consequently,

$$\underset{D0}{lim\; inf}\{R_1(P,Q,D)R_1(P,P,D)\}\underset{\lambda \mathrm{}}{lim\; inf}\{\mathrm{\Lambda }(\lambda ;P)\mathrm{\Lambda }(\lambda ;Q)\}$$

Similarly, by Proposition 2 we have $`R_1(P,Q,D)=\stackrel{~}{\lambda }D\mathrm{\Lambda }(\stackrel{~}{\lambda };Q)`$ for $`\stackrel{~}{\lambda }<0`$ such that $`\mathrm{\Lambda }^{}(\stackrel{~}{\lambda };Q)=D`$, $`R_1(P,P,D)\stackrel{~}{\lambda }D\mathrm{\Lambda }(\stackrel{~}{\lambda };P)`$, and with $`E_{P\times Q}[\rho (X,Y)]>0`$, also $`\stackrel{~}{\lambda }\mathrm{}`$ when $`D0`$. Therefore, it suffices to show that

$`\underset{\lambda \mathrm{}}{lim}\{\mathrm{\Lambda }(\lambda ;P)\mathrm{\Lambda }(\lambda ;Q)\}=H(PQ).`$ (63)
To this end, for any $`\lambda <0`$ and $`x^d`$, let

$$h_\lambda (x)\stackrel{\mathrm{}}{=}\frac{E_P(e^{\lambda \rho (x,Y)})}{E_Q(e^{\lambda \rho (x,Y)})}$$

noting that

$$\mathrm{\Lambda }(\lambda ;P)\mathrm{\Lambda }(\lambda ;Q)=\mathrm{log}h_\lambda (x)𝑑P(x).$$

Using the change of variable $`U=\rho (x,Y)0`$ followed by integration by parts, we see that

$$h_\lambda (x)=\frac{_0^{\mathrm{}}e^{\lambda u}g_x(u)𝑑u}{_0^{\mathrm{}}e^{\lambda u}k_x(u)𝑑u},$$

where $`g_x(r)=P(B(x,r))`$ and $`k_x(r)=Q(B(x,r))`$ are nonnegative, nondecreasing and bounded above by $`1`$. Considering separately $`u2\eta `$ and $`u>2\eta `$, it is easy to check that for any $`\eta >0`$,

$`\underset{0<r2\eta }{sup}{\displaystyle \frac{g_x(r)}{k_x(r)}}+\psi _{\lambda ,x}h_\lambda (x)\underset{0<r2\eta }{inf}{\displaystyle \frac{g_x(r)}{k_x(r)}}{\displaystyle \frac{1}{1+\psi _{\lambda ,x}}}`$ (64)
where

$`\psi _{\lambda ,x}\stackrel{\mathrm{}}{=}{\displaystyle \frac{_{2\eta }^{\mathrm{}}e^{\lambda u}𝑑u}{_0^{2\eta }e^{\lambda u}k_x(u)𝑑u}}{\displaystyle \frac{1}{\eta |\lambda |k_x(\eta )}}.`$ (65)
Fix $`xA_1`$ of part (a), in which case $`k_x(r)>0`$ for all $`r>0`$ and $`g_x(r)/k_x(r)f_1(x)`$ as $`r0`$. Letting $`\lambda \mathrm{}`$ and then $`\eta 0`$, it follows by (64) and (65) that

$$\underset{\lambda \mathrm{}}{lim}h_\lambda (x)=f_1(x).$$

Recall that $`P(A_1)=1`$ and our assumption that $`\mathrm{log}k_x(\eta )𝑑P(x)>\mathrm{}`$ for any $`\eta >0`$. By our integrability conditions, the function $`\mathrm{min}\{0,inf_{\lambda 1}\mathrm{log}h_\lambda (x)\}`$ is $`P`$-integrable, hence, by Fatou’s lemma,

$$\underset{\lambda \mathrm{}}{lim\; inf}\mathrm{log}h_\lambda (x)𝑑P(x)\mathrm{log}f_1(x)𝑑P(x)=H(PQ).$$

Moreover, in case $`H(PQ)<\mathrm{}`$, our assupmtions imply that $`sup_{\lambda 1}|\mathrm{log}h_\lambda (x)|`$ is $`P`$-integrable, hence by dominated convergence, $`\mathrm{log}h_\lambda (x)𝑑P(x)\mathrm{log}f_1(x)𝑑P(x)`$ for $`\lambda \mathrm{}`$, as required to complete the proof of (63). $`\mathrm{}`$

## Appendix C Proof of Theorem 27

Recall our assumption that, for $``$-a.e. $`x_{[0,\mathrm{})]}`$, conditional on $`X_{[0,\mathrm{})]}=x_{[0,\mathrm{})]}`$ the random variables $`\{\rho _n(x_{C(n)},Y_{C(n)})\}`$ satisfy the LDP with a deterministic convex good rate-function denoted hereafter $`R(,,)`$. Since $`\rho `$ is bounded, by Varadhan’s lemma and convex duality, this implies that

$`R(,,D)=\underset{\lambda }{sup}[\lambda D\mathrm{\Lambda }_{\mathrm{}}(\lambda )]\stackrel{\mathrm{}}{=}\mathrm{\Lambda }_{\mathrm{}}^{}(D)`$ (66)
where for any $`\lambda `$, the finite, deterministic limit

$$\mathrm{\Lambda }_{\mathrm{}}(\lambda )\stackrel{\mathrm{}}{=}\underset{n\mathrm{}}{lim}\frac{1}{n^d}\mathrm{log}e^{\lambda _{uC(n)}\rho (x_u,y_u)}𝑑Q_n(y_{C(n)})$$

exists for $``$-a.e. $`x_{[0,\mathrm{})}`$ (cf. \[25, Theorem 4.5.10\]). By bounded convergence, $`\mathrm{\Lambda }_{\mathrm{}}(\lambda )`$ is also the limit of

$$\mathrm{\Lambda }_n(\lambda )\stackrel{\mathrm{}}{=}\frac{1}{n^d}\left[\mathrm{log}e^{\lambda _{uC(n)}\rho (x_u,y_u)}𝑑Q_n(y_{C(n)})\right]𝑑P_n(x_{C(n)}).$$

By stationarity,

$`D_{\mathrm{av}}=E_{P_n\times Q_n}(\rho _n(X_{C(n)},Y_{C(n)})),n1`$ (67)
so replacing $`P_1`$, $`Q_1`$ and $`\rho (x,y)`$ of Proposition 2 by $`P_n`$, $`Q_n`$ and $`n^d\rho _n(x_{C(n)},y_{C(n)})`$, respectively, we see that

$`R_n(P_n,Q_n,D)=\underset{\lambda }{sup}[\lambda D\mathrm{\Lambda }_n(\lambda )]\stackrel{\mathrm{}}{=}\mathrm{\Lambda }_n^{}(D).`$ (68)
Note that $`|\mathrm{\Lambda }_n(\lambda )\mathrm{\Lambda }_n(\lambda ^{})|c|\lambda \lambda ^{}|`$ for some $`c<\mathrm{}`$ and all $`n`$, $`\lambda ,\lambda ^{}`$, hence the convergence of $`\mathrm{\Lambda }_n()`$ to $`\mathrm{\Lambda }_{\mathrm{}}()`$ is uniform on compact subsets of $``$. In particular, the convex, continuous functions $`\mathrm{\Lambda }_n()`$ converge infimally to $`\mathrm{\Lambda }_{\mathrm{}}()`$, and consequently, by \[72, Theorem 5\], the convex functions $`\mathrm{\Lambda }_n^{}()`$ converge infimally to $`\mathrm{\Lambda }_{\mathrm{}}^{}()`$, that is

$`\mathrm{\Lambda }_{\mathrm{}}^{}(D)=\underset{\delta 0}{lim}\underset{n\mathrm{}}{lim\; sup}\underset{|\widehat{D}D|<\delta }{inf}\mathrm{\Lambda }_n^{}(\widehat{D})=\underset{\delta 0}{lim}\underset{n\mathrm{}}{lim\; inf}\underset{|\widehat{D}D|<\delta }{inf}\mathrm{\Lambda }_n^{}(\widehat{D}).`$ (69)
It follows from (67) and Jensen’s inequality that $`\mathrm{\Lambda }_n(\lambda )\lambda D_{\mathrm{av}}`$ for all $`n`$ and $`\lambda `$, hence, for $`DD_{\mathrm{av}}`$ suffices to consider $`\lambda 0`$ in (66) and in (68). Thus, for $`1n\mathrm{}`$, $`\mathrm{\Lambda }_n^{}`$ are non-negative, convex, and monotone non-increasing on $`[0,D_{\mathrm{av}}]`$, with $`\mathrm{\Lambda }_n^{}(D_{\mathrm{av}})=0`$. For $`1n\mathrm{}`$, let

$$D_{\mathrm{min}}^{(n)}\stackrel{\mathrm{}}{=}\underset{\lambda \mathrm{}}{lim}\frac{\mathrm{\Lambda }_n(\lambda )}{\lambda },$$

so that $`\mathrm{\Lambda }_n^{}(D)=\mathrm{}`$ for $`D<D_{\mathrm{min}}^{(n)}`$, while $`\mathrm{\Lambda }_n^{}(D)<\mathrm{}`$ for $`D>D_{\mathrm{min}}^{(n)}`$. Note that for $`n<\mathrm{}`$ this coincides with the definition of $`D_{\mathrm{min}}^{(n)}`$ given in (48). It is easy to check then that (69) implies the pointwise convergence of $`\mathrm{\Lambda }_n^{}()=R_n(,,)`$ to $`\mathrm{\Lambda }_{\mathrm{}}^{}()=R(,,)`$ at any $`D`$ for which $`\mathrm{\Lambda }_{\mathrm{}}^{}(D\delta )\mathrm{\Lambda }_{\mathrm{}}^{}(D)`$, that is, for all $`DD_{\mathrm{min}}^{(\mathrm{})}`$. In particular, necessarily $`D_{\mathrm{min}}^{(\mathrm{})}[D_{\mathrm{min}},D_{\mathrm{av}}]`$, and $`D_{\mathrm{min}}^{(\mathrm{})}`$ may also be defined via (17). The continuity of $`R(,,D)`$ at $`D(D_{\mathrm{min}},D_{\mathrm{av}})`$, $`DD_{\mathrm{min}}^{(\mathrm{})}`$ implies the equality in (49) for such $`D`$, thus completing the proof of the theorem. $`\mathrm{}`$

## Appendix D Proof of Theorem 28

For each $`m1`$, let $`G_m`$ be the collection of “good” realizations $`x_^dA^^d`$

$$G_m=\{x_^dA^^d:Q_n(B(x_{C(n)},D))>0\text{for all}nm\}$$

so that the assumption that $`Q_n(B(X_{C(n)},D))>0`$ eventually, with probability one translates to

$`\{_{m1}G_m\}=1.`$ (70)
To prove the lower bound we choose and fix an $`m1`$ and a realization $`x_^dG_m`$. Then for any $`K>1`$:

$`\text{Pr}\{W_n^d<K|X_{C(n)}=x_{C(n)}\}`$ $``$ $`{\displaystyle \underset{u[0,K^{1/d}1]^d}{}}Q_n\{Y_{u+C(n)}B(x_{C(n)},D)\}`$
$``$ $`KQ_n(B(x_{C(n)},D)).`$
Since, by its definition, $`W_n`$ is always greater than or equal to one, this inequality trivially holds also for $`K(0,1]`$. Setting $`K=[n^{1+ϵ}Q_n(B(x_{C(n)},D))]^1`$ above gives, for all $`nm`$,

$`\text{Pr}\{\mathrm{log}[W_n^dQ_n(B(X_{C(n)},D))]<(1+ϵ)\mathrm{log}n|X_{C(n)}=x_{C(n)}\}{\displaystyle \frac{1}{n^{1+ϵ}}}.`$
Since this bound is uniform over $`x_^dG_m`$ and summable, the Borel-Cantelli lemma and assumption (70) imply that

$`\mathrm{log}[W_n^dQ_n(B(X_{C(n)},D))](1+ϵ)\mathrm{log}n\text{eventually, w.p.1.}`$ (71)
For the upper bound we choose and fix an $`m1`$ and a realization $`x_^dG_m`$, and take $`K(n+1)^d`$. Note that

$$\text{Pr}\{W_n^d>K|X_{C(n)}=x_{C(n)}\}\mathrm{Pr}\left\{\underset{u[0,M]^d}{}𝕀_{\{Y_{nu+C(n)}B(X_{C(n)},D)\}}=0\right\}$$

where the sum is over the $`(M+1)^d`$ integer positions $`u[0,M]^d^d`$, $`nu`$ denotes the point $`(nu_1,nu_2,\mathrm{},nu_d)^d`$, and

$$M=M(K,n)\stackrel{\mathrm{}}{=}\frac{K^{1/d}1}{n}.$$

Let $`\mathrm{\Sigma }_n`$ denote the sum in the above probability,

$$\mathrm{\Sigma }_n=\underset{u[0,M]^d}{}I_n(u)$$

where $`I_n(u)`$ is the indicator function of the event $`\{Y_{nu+C(n)}B(X_{C(n)},D)\}`$. In this notation:

$`\text{Pr}\{W_n^d>K|X_{C(n)}=x_{C(n)}\}\{\mathrm{\Sigma }_n=0\}{\displaystyle \frac{\text{Var}_{}(\mathrm{\Sigma }_n)}{[E_{}(\mathrm{\Sigma }_n)]^2}}.`$ (72)
By stationarity

$`E_{}(\mathrm{\Sigma }_n)=[M+1]^dQ_n(B(x_{C(n)},D))`$ (73)
and by the definition of the $`\varphi `$-mixing coefficients, if $`uv`$,

$$E_{}\{I_n(u)I_n(v)\}Q_n(B(x_{C(n)},D))[\varphi _n(nd(u,v)n+1)+Q_n(B(x_{C(n)},D))].$$

Using the last two estimates we can bound the variance as

$`\text{Var}_{}\{\mathrm{\Sigma }_n\}`$ $`=`$ $`{\displaystyle \underset{u,v[0,M]^d}{}}\text{Cov}_{}(I_n(u),I_n(v))`$ (74)
$``$ $`[M+1]^dQ_n(B(x_{C(n)},D))`$
$`+{\displaystyle \underset{u,v[0,M]^d,uv}{}}\left[Q_n(B(x_{C(n)},D))\varphi _n(nd(u,v)n+1)\right]`$
$``$ $`[M+1]^dQ_n(B(x_{C(n)},D))\left[1+{\displaystyle \underset{j=1}{\overset{M}{}}}c_dj^{d1}\varphi _n(njn+1)\right]`$
where $`c_dj^{d1}`$ bounds the number of possible points $`u`$ that can be at a distance exactly $`j`$ from a given point $`v`$ (for some constant $`c_d`$). By assumption (50) we can find a finite constant $`\mathrm{\Phi }`$ such that the expression in square brackets in (74) is bounded above by $`\mathrm{\Phi }`$, uniformly in $`n`$. Substituting this bound, together with (73) and (74), in (72), gives

$`\text{Pr}\{W_n>K|X_{C(n)}=x_{C(n)}\}`$ $``$ $`{\displaystyle \frac{\mathrm{\Phi }}{[M+1]^dQ_n(B(x_{C(n)},D))}}.`$ (75)
Let $`ϵ>0`$ arbitrary, take $`n`$ large enough so that $`n^{(1+ϵ)/d}2`$, and let $`K=n^{d+1+ϵ}/Q_n(B(x_{C(n)},D)).`$ Simple algebra shows that with this choice of $`K`$ we have

$$[M+1]^dQ_n(B(x_{C(n)},D))\frac{1}{2}n^{1+ϵ}$$

and substituting this in (75) yields

$`\text{Pr}\{\mathrm{log}[W_n^dQ_n(B(x_{C(n)},D))]>(d+1+ϵ)\mathrm{log}n|X_{C(n)}=x_{C(n)}\}{\displaystyle \frac{2\mathrm{\Phi }}{n^{1+ϵ}}}.`$
This bound is uniform over $`x_^dG_m`$ and summable, so the Borel-Cantelli lemma and (70) imply that

$`\mathrm{log}[W_n^dQ_n(B(X_{C(n)},D))](d+1+ϵ)\mathrm{log}n\text{eventually, w.p.1.}`$ (76)
Combining (76) and (71) completes the proof. $`\mathrm{}`$