Appendix B

Probability and information theory

Action models are statistical objects. The policy π(as)\pi(a \mid s) is a conditional distribution; the loss in §3.4 is an expected negative log-likelihood; the KL divergence appears in PPO’s clipping objective, in the ELBO of a VAE-style world model, and in the contrastive loss that trained CLIP. The body of the book invokes these objects without re-deriving them. This appendix is the bench manual: every concept is stated precisely once, illustrated with one robotics example, and linked back to the section where it does its real work.

B.1 Probability spaces, random variables, and distributions

A probability space is a triple (Ω,F,P)(\Omega, \mathcal{F}, P): a sample space Ω\Omega, a σ\sigma-algebra F\mathcal{F} of subsets of Ω\Omega called events, and a probability measure PP that assigns each event a number in [0,1][0, 1] with P(Ω)=1P(\Omega) = 1. For the body of this book the measure-theoretic scaffolding can stay implicit; what matters is that there is a procedure (sometimes physical, sometimes simulated) that produces outcomes, and a function that assigns probabilities to sets of those outcomes.

A random variable X:ΩXX : \Omega \to \mathcal{X} is a function from the sample space to a value space. When X\mathcal{X} is a finite or countable set, XX is discrete; when X=Rn\mathcal{X} = \mathbb{R}^{n}, it is continuous. A discrete random variable is fully described by its probability mass function p(x)=P(X=x)p(x) = P(X = x); a continuous one by its probability density function p(x)p(x), where P(XB)=Bp(x)dxP(X \in B) = \int_{B} p(x)\, dx for measurable sets BB. The notation XpX \sim p means ”XX is distributed according to pp” and is the line you will see at the top of every algorithm box from §3.3 onward.

Three distributions appear in this book often enough to be worth naming. The Bernoulli Bern(θ)\mathrm{Bern}(\theta) describes a coin flip with bias θ\theta and is the distribution behind every binary classification head. The categorical Cat(θ1,,θK)\mathrm{Cat}(\theta_1, \ldots, \theta_K) describes a single draw from KK options with probabilities θi\theta_i; the action-token distribution of RT-1 (arXiv:2212.06817) and OpenVLA (arXiv:2406.09246) is a categorical over 256 bins per action dimension. The multivariate Gaussian N(μ,Σ)\mathcal{N}(\mu, \Sigma) with mean μRn\mu \in \mathbb{R}^{n} and positive-definite covariance ΣRn×n\Sigma \in \mathbb{R}^{n \times n} has density

p(x)=1(2π)n/2Σ1/2exp ⁣(12(xμ)Σ1(xμ)),p(x) = \frac{1}{(2\pi)^{n/2} |\Sigma|^{1/2}} \exp\!\Big({-\tfrac{1}{2}} (x - \mu)^\top \Sigma^{-1} (x - \mu)\Big),

and is the workhorse model for sensor noise, dynamics noise, and the action distribution of every Gaussian policy in §7.

B.2 Expectation, variance, and the law of large numbers

The expectation of a random variable is its probability-weighted average:

E[X]={xxp(x)discrete,xp(x)dxcontinuous.\mathbb{E}[X] = \begin{cases} \sum_{x} x\, p(x) & \text{discrete}, \\ \int x\, p(x)\, dx & \text{continuous}. \end{cases}

Expectation is linear: E[αX+βY]=αE[X]+βE[Y]\mathbb{E}[\alpha X + \beta Y] = \alpha\, \mathbb{E}[X] + \beta\, \mathbb{E}[Y], with no independence required. This single property is why so much of the math in reinforcement learning works: the expected return decomposes into a sum of expected per-step rewards regardless of how the random states and actions are correlated through the policy. The variance Var[X]=E[(XE[X])2]\mathrm{Var}[X] = \mathbb{E}[(X - \mathbb{E}[X])^{2}] measures spread. For a vector-valued random variable, the analogue is the covariance matrix Σ=E[(Xμ)(Xμ)]\Sigma = \mathbb{E}[(X - \mu)(X - \mu)^\top], symmetric and positive semi-definite as Appendix A.6 promised.

The law of large numbers says that the empirical mean of NN independent samples from pp converges to E[X]\mathbb{E}[X] as NN \to \infty. This is the mathematical license for Monte Carlo estimation: Ep[f(X)]1Ni=1Nf(Xi)\mathbb{E}_{p}[f(X)] \approx \frac{1}{N} \sum_{i=1}^{N} f(X_i) with XiX_i drawn from pp. The central limit theorem sharpens the law into a rate: the standard error of the empirical mean scales as 1/N1/\sqrt{N}, which is why doubling your training data only reduces the policy gradient estimator’s noise by about 30%. Every “we trained for 5 seeds and report mean ± std” line in a robot-learning paper is a finite-sample version of these two theorems.

B.3 Conditional probability, independence, and Bayes’ rule

Two events AA and BB are independent if P(AB)=P(A)P(B)P(A \cap B) = P(A) P(B). The conditional probability of AA given BB is

P(AB)=P(AB)P(B),P(A \mid B) = \frac{P(A \cap B)}{P(B)},

defined whenever P(B)>0P(B) > 0. Bayes’ rule is the same identity rearranged: P(AB)=P(BA)P(A)/P(B)P(A \mid B) = P(B \mid A) P(A) / P(B). In the body of the book, Bayes’ rule shows up in the IRL discussion of §6.4 (recover the reward RR given demonstrations τ\tau by computing P(Rτ)P(R \mid \tau)), in the diffusion-model derivation of §10.1 (the reverse process is the conditional density of the cleaner sample given the noisier one), and implicitly in every Kalman-filter-style state estimator a real robot runs under its perception stack.

The closely related concept is conditional independence: XX and YY are conditionally independent given ZZ if P(X,YZ)=P(XZ)P(YZ)P(X, Y \mid Z) = P(X \mid Z) P(Y \mid Z). The Markov property in §5.1 is precisely the claim that the future is conditionally independent of the past given the present state, and it is the single assumption that makes the MDP formalism tractable.

B.4 KL divergence and the Kullback-Leibler family

The Kullback-Leibler divergence between two distributions pp and qq on the same space is

KL(pq)=Ep ⁣[logp(X)q(X)]=p(x)logp(x)q(x)dx.\mathrm{KL}(p \,\|\, q) = \mathbb{E}_{p}\!\left[\log \frac{p(X)}{q(X)}\right] = \int p(x) \log \frac{p(x)}{q(x)}\, dx.

KL is non-negative and zero only when p=qp = q almost everywhere. It is not symmetric — KL(pq)KL(qp)\mathrm{KL}(p \| q) \neq \mathrm{KL}(q \| p) in general — and it is not a metric, but it is the correct divergence for almost every information-theoretic argument in machine learning. Three concrete uses to keep in mind. PPO (Schulman et al., 2017, arXiv:1707.06347) penalizes KL(πnewπold)\mathrm{KL}(\pi_{\text{new}} \| \pi_{\text{old}}) to prevent destructive policy updates and the size of that penalty is the single most-tuned hyperparameter of the algorithm. The VAE objective of §3.4 includes a KL(qp)\mathrm{KL}(q \| p) term that pushes the encoder distribution toward a Gaussian prior; Kingma and Welling (2014, arXiv:1312.6114) is the canonical reference. Diffusion training loss is, after rearrangement, a sum of per-timestep KL divergences between the true and learned reverse transitions; the noise-prediction objective most VLAs use is the “reparameterization” of that KL sum.

A practical note: KL is finite only when qq assigns positive probability everywhere pp does. When q(x)=0q(x) = 0 but p(x)>0p(x) > 0, the KL is infinite. Numerical implementations therefore add a small ϵ\epsilon inside the log or smooth the distributions; if a training run’s loss suddenly spikes to NaN, “a distribution went to zero in the support of the other” is the second culprit to check, after “the learning rate is too high.”

B.5 Entropy and cross-entropy

The entropy of a discrete distribution pp is

H(p)=xp(x)logp(x)=Ep[logp(X)].H(p) = -\sum_{x} p(x) \log p(x) = \mathbb{E}_{p}[-\log p(X)].

Entropy is non-negative and is maximized by the uniform distribution on a given support. It measures the average number of nats (or bits, if base 2) needed to describe a sample from pp. In control, high policy entropy means the policy is exploring; low policy entropy means it has committed. SAC (Haarnoja et al., 2018, ICML 2018) makes entropy maximization an explicit term in its objective, which is the mechanism that keeps it exploring while learning.

The cross-entropy between pp and qq is

H(p,q)=xp(x)logq(x)=H(p)+KL(pq).H(p, q) = -\sum_{x} p(x) \log q(x) = H(p) + \mathrm{KL}(p \| q).

If pp is fixed (as it is when pp is the empirical distribution of training data), minimizing the cross-entropy in qq is equivalent to minimizing KL(pq)\mathrm{KL}(p \| q). This is the equivalence behind every “cross-entropy loss = log-likelihood loss” claim in §3.4: the empirical-data distribution plays the role of pp, the model distribution plays the role of qq, and Bayes’ optimal predictor is the qq that minimizes H(p,q)H(p, q). Behavior cloning (§6.2) is exactly cross-entropy minimization between the demonstrator’s action distribution and the policy’s action distribution.

B.6 Likelihood, log-likelihood, and maximum likelihood

A likelihood is a probability density read as a function of the parameters θ\theta that produced it, with the data held fixed: L(θ;D)=pθ(D)\mathcal{L}(\theta; D) = p_{\theta}(D). The log-likelihood is its logarithm, (θ;D)=logpθ(D)\ell(\theta; D) = \log p_{\theta}(D), and is the quantity actually optimized in practice — products turn into sums, underflow disappears, and the derivative is easier. The maximum likelihood estimator (MLE) is θ^=argmaxθ(θ;D)\hat\theta = \arg\max_{\theta} \ell(\theta; D).

Three uses, all already in the book by Chapter 12. The supervised loss in §3.4 is a negative log-likelihood. The reward of an MDP is sometimes inferred via maximum likelihood from demonstrations (maximum-entropy IRL is the classic example, treated lightly in §6.4). The training objective of every autoregressive language model that gets repurposed as a VLA backbone — Llama-2 for OpenVLA, PaLI-X for RT-2 — is the next-token log-likelihood of the training corpus.

Two known failure modes of MLE worth knowing about. First, MLE is consistent (converges to the truth as NN \to \infty) but not necessarily efficient at finite NN, and on small datasets a Bayesian or regularized estimator may dominate it. Second, MLE is model-misspecification-sensitive: if the chosen family pθp_\theta does not include the data-generating distribution, MLE finds the θ\theta that minimizes KL(pdatapθ)\mathrm{KL}(p_{\text{data}} \| p_\theta), not the truth, and the asymmetry of KL means the result is the support-covering mode rather than the most likely one. This asymmetry is why mode collapse in GAN-style generators is a different failure than mode covering in MLE-trained density models.

B.7 The reparameterization trick and gradients of expectations

A recurring problem in ML is to compute gradients of an expectation Epθ[f(X)]\mathbb{E}_{p_\theta}[f(X)] with respect to θ\theta, the parameters of the distribution. Two strategies dominate. The score- function estimator (used in REINFORCE and policy gradient, §7.2) rewrites the gradient as

θEpθ[f(X)]=Epθ ⁣[f(X)θlogpθ(X)].\nabla_\theta \mathbb{E}_{p_\theta}[f(X)] = \mathbb{E}_{p_\theta}\!\left[ f(X)\, \nabla_\theta \log p_\theta(X)\right].

This is correct in expectation, but has high variance and is the reason policy gradient methods need millions of environment steps.

The reparameterization trick applies when XX can be written as a deterministic function of θ\theta and an auxiliary noise variable ϵp(ϵ)\epsilon \sim p(\epsilon): X=gθ(ϵ)X = g_\theta(\epsilon). Then

θEpθ[f(X)]=Ep(ϵ) ⁣[θf(gθ(ϵ))].\nabla_\theta \mathbb{E}_{p_\theta}[f(X)] = \mathbb{E}_{p(\epsilon)}\!\left[ \nabla_\theta f(g_\theta(\epsilon))\right].

The gradient slides inside the expectation because ϵ\epsilon does not depend on θ\theta. For a Gaussian with parameters μ,σ\mu, \sigma, the reparameterization is X=μ+σϵX = \mu + \sigma\, \epsilon with ϵN(0,1)\epsilon \sim \mathcal{N}(0, 1). This trick is what makes the VAE trainable in §3.4 and what makes the noise-injection in Diffusion Policy (§10.2) differentiable end-to-end. When you can reparameterize, you should; the variance reduction over the score-function estimator is dramatic.

B.8 The ELBO and variational inference

For a latent-variable model pθ(x,z)=pθ(xz)p(z)p_\theta(x, z) = p_\theta(x \mid z) p(z), the log-likelihood of an observation xx is

logpθ(x)=logpθ(xz)p(z)dz,\log p_\theta(x) = \log \int p_\theta(x \mid z) p(z)\, dz,

an integral that is intractable in essentially every interesting case. The variational trick introduces an approximate posterior qϕ(zx)q_\phi(z \mid x) and decomposes the log-likelihood as

logpθ(x)=Eqϕ[logpθ(xz)]KL(qϕ(zx)p(z))ELBO(θ,ϕ;x)+KL(qϕ(zx)pθ(zx)).\log p_\theta(x) = \underbrace{\mathbb{E}_{q_\phi}[\log p_\theta(x \mid z)] - \mathrm{KL}(q_\phi(z \mid x) \| p(z))}_{\text{ELBO}(\theta, \phi; x)} + \mathrm{KL}(q_\phi(z \mid x) \| p_\theta(z \mid x)).

The second KL on the right is non-negative, so the ELBO (evidence lower bound) is a lower bound on the log-likelihood. Maximizing the ELBO simultaneously fits the model (θ\theta) and tightens the variational approximation (ϕ\phi). This is the entire machinery of the VAE (Kingma and Welling, 2014, arXiv:1312.6114) and the latent dynamics model in DreamerV3 (Hafner et al., 2023, arXiv:2301.04104) that Chapter 9 treats in detail.

B.9 Information-theoretic asides used in the book

A handful of additional information-theoretic notions appear in the body of the book and are worth a one-line gloss.

Mutual information I(X;Y)=KL(p(x,y)p(x)p(y))I(X; Y) = \mathrm{KL}(p(x, y) \| p(x) p(y)) measures how much knowing one variable tells you about the other. Contrastive losses (CLIP, InfoNCE) are lower-bound estimators of mutual information.

Differential entropy of a continuous random variable extends the discrete entropy formula with an integral and a sign convention. A Gaussian with covariance Σ\Sigma has differential entropy 12log((2πe)nΣ)\frac{1}{2} \log((2\pi e)^{n} |\Sigma|), which is why “maximum-entropy Gaussian prior” is the default well-behaved prior.

Jensen’s inequality says that for any convex function ϕ\phi and random variable XX, ϕ(E[X])E[ϕ(X)]\phi(\mathbb{E}[X]) \leq \mathbb{E}[\phi(X)] (reversed for concave ϕ\phi). This is the inequality behind the ELBO derivation, behind every “lower-bound argument” in variational inference, and behind the proof that KL is non-negative.

B.10 A practitioner’s checklist

Three reminders for the kind of bug that probability theory creates in practice. First, never let a probability go to zero in code; clamp densities away from zero by a tiny ϵ\epsilon, or work in log-space throughout. Second, never use a softmax(logits) followed by log; use the numerically stable log_softmax your framework provides. Third, when you sample from a Gaussian for any reason — VAE, diffusion, policy noise — verify the covariance you are using is the one you mean: a 7-vector “with variance 0.1” might mean covariance 0.1I0.1 \cdot I or covariance 0.12I=0.01I0.1^{2} \cdot I = 0.01 \cdot I, and the field uses both conventions inconsistently. Read the data loader; do not trust the paper.

That, plus the linear-algebra background of Appendix A and the PyTorch glue of Appendix C, is the math the rest of the book leans on.

References

  1. Bishop, C. M. (2006). Pattern Recognition and Machine Learning. Springer.
  2. Cover, T. M., & Thomas, J. A. (2006). Elements of Information Theory (2nd ed.). Wiley.
  3. Kingma, D. P., & Welling, M. (2014). Auto-Encoding Variational Bayes. arXiv:1312.6114.