Sending Samples Without Bits-Back
Intro
I’ll describe a fun little problem in information theory, and a solution–a compression algorithm–based on rejection sampling. This problem is motivated by the coding interpretation of the variational bound, which seems to be a valuable source of intuition. The compression algorithm I describe is distinct from the well-known idea of bits-back coding and gives a more direct interpretation of the variational bound objective. It’s terribly computationally inefficient, but I think it’s interesting as a proof of principle.
The Problem. Alice and Bob initially agree on a “prior” distribution , and they have a shared random number generator (RNG). Later, Alice is given a different distribution . How long of a message does Alice need to send to Bob so that by combining the message with the RNG, he can produce a sample ?
More precisely, Alice and Bob agree on a deterministic function of the RNG state and the message . Alice computes the message as a function of , and the distribution of must equal .
Let’s analyze the problem for a couple of simple cases:
- If , then the message length is zero: Alice can just tell Bob to take his first sample from .
- If , i.e. an indicator on one value , then the best Alice can do is to send with message length .
Note that this problem is subtlely different from the problem where Alice samples (using a non-shared RNG) and then must send it to Bob. Sending arbitrary requires expected code-length . If Alice samples and sends it to Bob using the code from , it would require more bits than necessary. In particular, it would take bits in the case that rather than zero.
You might guess that the general answer is , which gives the correct answer in examples (1) and (2) above. That guess is correct! I’ll prove it below (after adding some pesky details). But first, I’ll explain the motivation for this communication problem.
Variational Upper Bound
Many concepts of probability have a corresponding interpretation in terms of codes and compression. A key idea, needed for models with latent variables (like the variational autoencoder (VAE)) is variational upper bound (VUB). It’s usually called the variational lower bound, but we’ll flip the sign so it’ll correspond to code-length.
The VUB is the objective used for fitting probabilistic models with latent variables. Given a model , we typically want to maximize , but there’s an intractable sum over . The VUB introduces a sample distribution , giving an upper bound on the log-loss.
The LHS of the inequality reads “the number of bits Alice needs to send to Bob to transmit x, given that they previously agreed on distribution ”. Can the RHS be interpreted as a concrete compression scheme for , involving a code that partially encodes x?
We’d like to say something like this:
- (*) is the number of bits Alice must send Bob, so Bob gets a sample .
- (**) is the expected cost for Bob to fully reconstruct , given the he received.
The second point, interpreting (E_{z \sim q}[\logpinv(x|z)]) as the code-length of given , is clearly true. The first point is non-obvious, and it’s precisely the problem stated above.
The variational upper bound is indeed the code-length under a well-known compression scheme, called bits-back coding. However, bits-back coding doesn’t quite match the simple two-part-code interpretation given above. In bits-back coding, Alice samples using some auxiliary data as the entropy source, then sends the whole sample to Bob at an expected cost of . Then, she sends at a cost of . Finally, using to infer the distribution , Bob recovers the bits of auxiliary data, giving a net code-length of (E_q[\logpinv(z)]+E_q[\logpinv(x | z)]-E_q[\log q^{-1}(z)]=\klqp + E_q[\logpinv(x | z)]).
Bits-back is a pretty slick idea, but I’ve always wondered if the interpretation as a two-part code can be directly implemented. In particular, can the code-word be communicated using cost , without using at all?
Naive Rejection Sampling (Suboptimal)
Let’s return to the problem, where Alice needs to send Bob a message that lets him sample . One natural idea is to use rejection sampling. Rejection sampling allows you to sample from by (stochastically) filtering samples from a different distribution . Alice uses her RNG to generate a sequence of IID samples from , but applies the rejection criterion so that the first accepted sample is a sample from . Then she sends to Bob the index of the first accepted sample. Bob runs the same process on his end and takes the th sample, which is the same as Alice’s th sample due to the shared RNG.
Now let’s look at the expected code-length of this protocol. In rejection sampling, we sample (z \sim p(z)) and accept with probability (\paccz = \minv\frac{q(z)}{p(z)}), where .
The probability of accepting a sample is . Given that an event has probability , the expected number of samples until it occurs is . Hence, the expected number of trials of the rejection sampling process is just . The code-length of this integer is (\log M=\log \max_z \frac{q(z)}{p(z)} = \max_z \log \frac{q(z)}{p(z)}).
Hence, this rejection sampling procedure attains a code-length . But we’ve claimed above that the optimal code-length is . So rejection sampling is suboptimal in general, replacing the expectation by a max .
Modified Rejection Sampling
The rejection sampling approach almost works, but it gives suboptimal code-length. Like many ideas in coding theory, we can fix the problem by grouping together a bunch of messages and use the law of large numbers. We’ll group together samples and do rejection sampling with (\log M \approx n\klqp).
Let’s modify the communication problem to have Alice send Bob samples at a time. In the modified problem, Alice and Bob agree on ((p_1, p_2, \dots, p_n)); Alice needs to send Bob a sample from . To simplify the argument, let all of the distributions be the equal; ; . The argument can easily be modified for the case where these distributions are not equal.
As for notation, let denote an n-tuple of samples, and let and denote the joint distributions over n-tuples of samples.
We’ll define the communication protocol as follows. Alice repeatedly samples , accepting with probability (\min\left(1, \minv\frac{q^n(z^n)}{p^n(z^n)}\right)), where , and is a small number that as (n \rightarrow \infty). Then she sends Bob an integer –the number of trials until acceptance, and he takes the th sample from .
To show that this protocol works, we will prove the following two statements:
- The expected message length per sample approaches as (n \rightarrow \infty).
- The total variation divergence between each decoded and approaches zero as (n \rightarrow \infty).
The proof will be based on the idea of typical sets introduced by Shannon. We’ll also explain how to slightly modify the protocol to send exactly instead of an approximation (at the cost of some extra bits).
Consider the log ratio
Let be a small number. As , the sample average of approaches its mean value, , so we get
Alice does rejection sampling by sampling and then accepting with probability (\Pr(\text{accept \ } z^n) = \min(1, \minv\frac{q^n(z^n)}{p^n(z^n)})), where .
For the second part of the proposition, let’s define to be the decoded distribution over when following the rejection sampling protocol.
Finally, it’s a bit unsatisfying that Alice doesn’t send exactly , she sends an approximation . We can easily fix this issue and have Alice send exactly at the cost of some extra bits. Here’s a sketch. With probability , we perform the protocol above. With probability , Alice directly sends , sampled the compliment of , at a cost of . Overall, the extra cost is .
Discussion
This procedure is computationally intractable, since it requires Alice to generate a sequence of samples from an exponentially large set of tuples . This contrasts with bits-back coding, which can be implemented efficiently. In fact, a recent paper showed how to implement bits-back coding with VAEs, cleverly using ANS (a relative of arithmetic coding).
It’s possible that there’s a procedure like arithmetic coding that solves our problem, giving an efficient algorithm in the case that lives in a small discrete set. If is high-dimensional, then it seems unlikely that we can solve the transmission problem efficiently without additional assumptions–all we can do is enumerate samples from and index into them.
Finally, I wouldn’t be surprised if this problem is well-known–it seems like a natural way of formalizing the idea of lossy data transmission. If so, please send me a pointer.
Thanks to Nik Tezak and Beth Barnes for helpful feedback.