Skip to content
AIAI Wranglers

2 Probability and Statistics

Generative modelling is, at its mathematical core, the study of probability distributions. Every generative model, whether a Gaussian mixture, a variational autoencoder, or a diffusion model, is ultimately an attempt to represent, approximate, or sample from a probability distribution over high-dimensional data. This chapter reviews the probability and statistics needed to make that statement precise.

We assume the reader has encountered probability in an introductory course and focus on developing the concepts that will recur throughout the book. Readers comfortable with multivariate distributions, the change-of-variables formula, and maximum likelihood estimation may skim this chapter and return to it as a reference.

Random Variables and Distributions

Definition 1 (Random Variable).

A random variable X is a measurable function from a sample space Ω to the real numbers . Informally, it assigns a numerical value to each outcome of a random experiment.

Random variables come in two flavours:

  • Discrete random variables take on a countable set of values (e.g., the number of heads in 10 coin tosses).

  • Continuous random variables take on values in an uncountable set, typically an interval of (e.g., the intensity of a pixel in a photograph).

Probability Mass Functions

A discrete random variable X is characterised by its probability mass function (PMF):

Definition 2 (Probability Mass Function).

The PMF of a discrete random variable X is the function pX:[0,1] defined by pX(x)=P(X=x). It satisfies pX(x)0 for all x and xpX(x)=1.

Example 1 (Fair Die).

Rolling a fair six-sided die defines a random variable X{1,2,3,4,5,6} with PMF pX(k)=16 for each k.

Probability Density Functions

A continuous random variable X is characterised by its probability density function (PDF):

Definition 3 (Probability Density Function).

The PDF of a continuous random variable X is a non-negative function fX:[0,) such that for any interval [a,b], P(aXb)=abfX(x)dx. The PDF satisfies fX(x)dx=1.

Remark 1.

A common source of confusion: fX(x) is not a probability. It is a probability density; it can exceed 1. Only the integral of fX over an interval gives a probability. For instance, a uniform distribution on [0,0.5] has fX(x)=2 for x[0,0.5].

Cumulative Distribution Functions

Definition 4 (Cumulative Distribution Function).

The cumulative distribution function (CDF) of a random variable X is FX(x)=P(Xx). For continuous random variables, FX(x)=xfX(t)dt, so fX(x)=FX(x).

Common Discrete Distributions

Bernoulli Distribution

The simplest random experiment has two outcomes: success (1) or failure (0).

Definition 5 (Bernoulli Distribution).

A random variable X follows a Bernoulli distribution with parameter p[0,1], written XBernoulli(p), if P(X=1)=p,P(X=0)=1p.

Insight.

A single pixel in a binary (black-and-white) image can be modelled as a Bernoulli random variable. A generative model for binary images assigns a Bernoulli parameter pi[0,1] to each pixel i; this is exactly what the output layer of a VAE decoder does when generating binary MNIST digits.

Binomial Distribution

Definition 6 (Binomial Distribution).

If X1,,XniidBernoulli(p), then Y=i=1nXiBinomial(n,p) with PMF P(Y=k)=(nk)pk(1p)nk,k=0,1,,n.

Geometric Distribution

Definition 7 (Geometric Distribution).

A random variable XGeometric(p) models the number of trials until the first success: P(X=k)=(1p)k1p,k=1,2,3, The geometric distribution is the only discrete distribution with the memoryless property: P(X>s+t|X>s)=P(X>t).

Poisson Distribution

Definition 8 (Poisson Distribution).

A random variable XPoisson(λ) with rate parameter λ>0 has PMF P(X=k)=λkeλk!,k=0,1,2, It models the number of events occurring in a fixed interval of time or space, given a constant average rate λ.

Example 2 (Word Counts).

The number of times a particular word appears in a document of fixed length can be modelled as a Poisson random variable. Topic models and language models use this observation to build generative models of text.

Categorical and Multinomial Distributions

Definition 9 (Categorical Distribution).

A random variable X taking values in {1,2,,K} follows a categorical distribution with parameters 𝝅=(π1,,πK), where πk0 and k=1Kπk=1, if P(X=k)=πk.

Definition 10 (Multinomial Distribution).

If X1,,Xn are i.i.d. Categorical(𝝅), the vector of counts 𝐍=(N1,,NK) where Nk=#{i:Xi=k} follows a multinomial distribution: P(N1=n1,,NK=nK)=n!n1!nK!π1n1πKnK, where n=n1++nK.

Insight.

The categorical distribution is the workhorse of autoregressive language models. When GPT generates the next word (token), it produces a categorical distribution over a vocabulary of K50,000 tokens. Sampling from this distribution gives the next word. The entire generative process is a sequence of categorical samples, one per token.

Common Continuous Distributions

Uniform Distribution

Definition 11 (Uniform Distribution).

A random variable XUniform(a,b) has PDF fX(x)={1baif axb,0otherwise.

The uniform distribution serves as the “noise source” in many generative models: to sample from a complex distribution, we often start with uniform (or Gaussian) random numbers and transform them.

Gaussian (Normal) Distribution

The Gaussian distribution is the single most important distribution in generative modelling. It appears as the noise prior in GANs, VAEs, normalizing flows, and diffusion models; it defines the likelihood in Gaussian mixture models; and it is the stationary distribution of many stochastic processes.

Definition 12 (Gaussian Distribution).

A random variable X𝒩(μ,σ2) has PDF fX(x)=1σ2πexp((xμ)22σ2), where μ is the mean and σ2>0 is the variance.

Gaussian probability density functions with different means and variances. Changing μ shifts the curve; changing σ2 controls its width.

The Gaussian distribution owes its ubiquity to several remarkable properties:

  1. It is the maximum entropy distribution among all distributions with a given mean and variance: it makes the fewest assumptions beyond these two moments.

  2. Sums of independent random variables converge to a Gaussian (Central Limit Theorem).

  3. It is closed under linear transformations, marginalisation, and conditioning.

  4. Its log-density is quadratic, making optimisation tractable.

Exponential Distribution

Definition 13 (Exponential Distribution).

A random variable XExponential(λ) with rate λ>0 has PDF fX(x)=λeλx,x0. It is the continuous analogue of the geometric distribution and models waiting times.

Beta Distribution

Definition 14 (Beta Distribution).

A random variable XBeta(α,β) with shape parameters α,β>0 has PDF fX(x)=xα1(1x)β1B(α,β),x[0,1], where B(α,β)=Γ(α)Γ(β)Γ(α+β) is the Beta function.

The Beta distribution is the conjugate prior for the Bernoulli parameter p, making it central to Bayesian inference (see Bayesian Inference). It can model any shape on [0,1]: uniform (α=β=1), U-shaped (α=β<1), or peaked (α=β>1).

Expectation, Variance, and Moments

Expectation

Definition 15 (Expectation).

The expectation (or mean) of a random variable X is 𝔼[X]={xxpX(x)(discrete),xfX(x)dx(continuous). More generally, for any function g, 𝔼[g(X)]=xg(x)pX(x) or g(x)fX(x)dx.

Key properties. Expectation is linear: for any constants a,b and random variables X,Y, 𝔼[aX+bY]=a𝔼[X]+b𝔼[Y]. This holds even when X and Y are not independent.

Variance and Standard Deviation

Definition 16 (Variance).

The variance of a random variable X with mean μ=𝔼[X] is 𝖵ar(X)=𝔼[(Xμ)2]=𝔼[X2](𝔼[X])2. The standard deviation is σ=𝖵ar(X).

Key properties. For constants a,b: 𝖵ar(aX+b)=a2𝖵ar(X). For independent X,Y: 𝖵ar(X+Y)=𝖵ar(X)+𝖵ar(Y).

Covariance and Correlation

Definition 17 (Covariance and Correlation).

The covariance of random variables X and Y is 𝖢ov(X,Y)=𝔼[(X𝔼[X])(Y𝔼[Y])]=𝔼[XY]𝔼[X]𝔼[Y]. The correlation coefficient normalises covariance to [1,1]: ρ(X,Y)=𝖢ov(X,Y)𝖵ar(X)𝖵ar(Y). If X and Y are independent, then 𝖢ov(X,Y)=0. The converse is not generally true.

Remark 2.

For a random vector 𝐗=(X1,,Xd), the covariance matrix is the d×d matrix 𝚺=𝔼[(𝐗𝝁)(𝐗𝝁)],[𝚺]ij=𝖢ov(Xi,Xj). This matrix encodes the variance of each component (on the diagonal) and the pairwise correlations (off-diagonal). It is symmetric and positive semi-definite. The covariance matrix is a central object in this book: it defines the shape of Gaussian distributions, appears in the FID metric, and governs the geometry of latent spaces.

Moments and Moment Generating Functions

Definition 18 (Moments).

The k-th moment of X is 𝔼[Xk]. The k-th central moment is 𝔼[(Xμ)k]. The first moment is the mean; the second central moment is the variance.

Definition 19 (Moment Generating Function).

The moment generating function (MGF) of X is MX(t)=𝔼[etX], provided the expectation exists in a neighbourhood of t=0. The k-th moment can be recovered as 𝔼[Xk]=MX(k)(0). If two random variables have the same MGF, they have the same distribution.

Joint, Marginal, and Conditional Distributions

When modelling data, we almost always deal with multiple random variables simultaneously. An image has millions of pixel values; a sentence has dozens of token indices. Understanding the relationships between these variables requires joint, marginal, and conditional distributions.

Joint Distributions

Definition 20 (Joint Distribution).

For continuous random variables X and Y, the joint PDF fX,Y(x,y) satisfies P((X,Y)A)=AfX,Y(x,y)dxdy for any region A2, and fX,Y(x,y)dxdy=1.

Marginal Distributions

Given the joint distribution of (X,Y), we can recover the distribution of X alone by marginalising out Y: fX(x)=fX,Y(x,y)dy. For discrete variables, replace the integral with a sum.

Key Idea.

Marginalisation is one of the most important operations in generative modelling. When we write the marginal likelihood of a latent-variable model as pθ(𝐱)=pθ(𝐱|𝐳)p(𝐳)d𝐳, we are marginalising out the latent variable 𝐳 to obtain the distribution over observed data 𝐱. The intractability of this integral for complex models is the central challenge that variational inference and VAEs are designed to address.

Conditional Distributions

Definition 21 (Conditional Distribution).

The conditional PDF of Y given X=x is fY|X(y|x)=fX,Y(x,y)fX(x),provided fX(x)>0.

Rearranging gives the product rule: fX,Y(x,y)=fY|X(y|x)fX(x). Applying this repeatedly to a vector 𝐱=(x1,,xd) yields the chain rule of probability: (Chain RULE)p(𝐱)=p(x1)p(x2|x1)p(x3|x1,x2)p(xd|x1,,xd1)=i=1dp(xi|x<i). This decomposition is exact: no approximation is involved, and it is the foundation of autoregressive generative models (PixelCNN, GPT, WaveNet).

Independence

Definition 22 (Independence).

Random variables X and Y are independent if and only if fX,Y(x,y)=fX(x)fY(y)for all x,y. Equivalently, fY|X(y|x)=fY(y): knowing X tells you nothing about Y.

Independence is a very strong assumption. In an image, pixels are not independent; neighbouring pixels are highly correlated. The gap between the independent (factored) model and the true joint distribution is precisely what generative models must learn to bridge.

Bayes' Theorem

Theorem 1 (Bayes' Theorem).

For continuous random variables X and Y with fY(y)>0, fX|Y(x|y)=fY|X(y|x)fX(x)fY(y)=fY|X(y|x)fX(x)fY|X(y|x)fX(x)dx.

In the language of Bayesian inference: fX|Y(x|y)posterior=fY|X(y|x)likelihoodfX(x)priorfY(y)evidence. The denominator fY(y)=fY|X(y|x)fX(x)dx is a normalising constant that ensures the posterior integrates to 1. Computing this integral is often intractable, motivating the approximate inference methods developed in Chapter 8.

The Multivariate Gaussian Distribution

The multivariate Gaussian is the cornerstone of probabilistic generative modelling. It parameterises the prior in VAEs, defines the likelihood in Gaussian mixture models, serves as the base distribution in normalizing flows, and governs the noise process in diffusion models. We develop its properties in detail.

Definition 23 (Multivariate Gaussian Distribution).

A random vector 𝐱d follows a multivariate Gaussian (or normal) distribution, written 𝐱𝒩(𝝁,𝚺), if its PDF is (MVN PDF)f(𝐱)=1(2π)d/2|𝚺|1/2exp(12(𝐱𝝁)𝚺1(𝐱𝝁)), where 𝝁d is the mean vector and 𝚺d×d is a symmetric positive definite covariance matrix.

Contour lines of bivariate Gaussian distributions. Left: 𝚺=𝐈 gives circular contours (uncorrelated, equal variance in all directions). Right: off-diagonal entries produce tilted ellipses whose axes align with the eigenvectors of 𝚺. The shape and orientation of the ellipses are entirely determined by the covariance matrix.

Geometry of the Multivariate Gaussian

The exponent (𝐱𝝁)𝚺1(𝐱𝝁) is the Mahalanobis distance from 𝐱 to 𝝁, measured in the metric defined by 𝚺1. The level sets of the density are ellipsoids centred at 𝝁:

  • The axes of the ellipsoid are aligned with the eigenvectors of 𝚺.

  • The lengths of the axes are proportional to the square roots of the eigenvalues.

  • If 𝚺=σ2𝐈 (all eigenvalues equal), the ellipsoid becomes a sphere, and the distribution is isotropic.

Marginals and Conditionals of a Gaussian

One of the most remarkable properties of the multivariate Gaussian is that both marginals and conditionals are again Gaussian. Partition 𝐱=(𝐱1𝐱2) with corresponding partition of the mean and covariance: 𝝁=(𝝁1𝝁2),𝚺=(𝚺11𝚺12𝚺21𝚺22).

Proposition 1 (Marginal of a Gaussian).

The marginal distribution of 𝐱1 is 𝐱1𝒩(𝝁1,𝚺11).

Proposition 2 (Conditional of a Gaussian).

The conditional distribution of 𝐱1 given 𝐱2=𝐚 is 𝐱1|𝐱2=𝐚𝒩(𝝁1+𝚺12𝚺221(𝐚𝝁2),𝚺11𝚺12𝚺221𝚺21).

Insight.

These formulas have a beautiful interpretation. The conditional mean 𝝁1+𝚺12𝚺221(𝐚𝝁2) is the best linear prediction of 𝐱1 given 𝐱2=𝐚: it shifts the prior mean by an amount proportional to how much 𝐱2 deviates from its own mean. The conditional covariance 𝚺11𝚺12𝚺221𝚺21 (the Schur complement) is always smaller than the marginal covariance 𝚺11: observing 𝐱2 always reduces our uncertainty about 𝐱1.

This property is used extensively in Gaussian processes, Kalman filters, and the derivation of the ELBO for linear Gaussian models.

Linear Transformations

Proposition 3 (Affine Transformation of a Gaussian).

If 𝐱𝒩(𝝁,𝚺) and 𝐲=𝐀𝐱+𝐛 for a matrix 𝐀m×d and vector 𝐛m, then 𝐲𝒩(𝐀𝝁+𝐛,𝐀𝚺𝐀).

Remark 3.

This closure under affine transformations is one reason why the standard Gaussian 𝒩(𝟎,𝐈) is the default choice for the latent prior in generative models: any Gaussian can be obtained from 𝐳𝒩(𝟎,𝐈) via the transformation 𝐱=𝝁+𝐋𝐳, where 𝚺=𝐋𝐋 (Cholesky decomposition). This is the basis of the reparameterisation trick used in VAE training.

Fundamental Theorems and Inequalities

Law of Large Numbers

Theorem 2 (Weak Law of Large Numbers).

Let X1,X2,,Xn be i.i.d. random variables with mean μ and finite variance σ2. Then the sample mean Xn=1ni=1nXi converges to μ in probability: limnP(|Xnμ|ϵ)=0,ϵ>0.

Proof.

By Chebyshev's inequality (Theorem 5 below), P(|Xnμ|ϵ)𝖵ar(Xn)ϵ2=σ2nϵ2n0.

Key Idea.

The Law of Large Numbers justifies Monte Carlo estimation: we can approximate 𝔼[g(X)] by averaging g(Xi) over i.i.d. samples. This is how we estimate the ELBO in VAE training and the adversarial loss in GAN training, by averaging over minibatches.

Central Limit Theorem

Theorem 3 (Central Limit Theorem).

Let X1,X2,,Xn be i.i.d. with mean μ and finite variance σ2>0. Then the standardised sum converges in distribution to a standard Gaussian: Zn=i=1nXinμσnd𝒩(0,1)as n.

The CLT explains why the Gaussian appears so frequently in nature and in modelling: whenever a quantity is the result of many small, independent contributions, its distribution is approximately Gaussian.

Concentration Inequalities

The following inequalities provide non-asymptotic bounds on how random variables deviate from their expectations.

Theorem 4 (Markov's Inequality).

For any non-negative random variable X and a>0, P(Xa)𝔼[X]a.

Theorem 5 (Chebyshev's Inequality).

For any random variable X with mean μ and variance σ2, and any k>0, P(|Xμ|kσ)1k2.

Proof.

Apply Markov's inequality to the non-negative random variable (Xμ)2 with threshold a=k2σ2: P(|Xμ|kσ)=P((Xμ)2k2σ2)𝔼[(Xμ)2]k2σ2=σ2k2σ2=1k2.

Theorem 6 (Jensen's Inequality).

If φ is a convex function and X is a random variable with finite expectation, then φ(𝔼[X])𝔼[φ(X)]. If φ is concave, the inequality reverses.

Insight.

Jensen's inequality is the mathematical engine behind the ELBO. Since log is concave, Jensen gives log𝔼[f(X)]𝔼[logf(X)]. Applied to the marginal likelihood logp(𝐱)=log𝔼p(𝐳)[p(𝐱|𝐳)], this yields a tractable lower bound, the starting point for variational inference. We will derive this in detail in Chapter 8.

Theorem 7 (Cauchy–Schwarz Inequality).

For any random variables X and Y with finite second moments, |𝔼[XY]|2𝔼[X2]𝔼[Y2]. Equivalently, |𝖢ov(X,Y)|2𝖵ar(X)𝖵ar(Y), which shows that |ρ(X,Y)|1.

Theorem 8 (Union Bound).

For any events A1,A2,,An, P(i=1nAi)i=1nP(Ai).

Change of Variables

The change-of-variables formula tells us how a probability distribution transforms under a mapping. This is one of the most important technical tools in this book: it is the mathematical foundation of normalizing flows and appears in the derivation of many other generative models.

Univariate Case

Theorem 9 (Change of Variables - Univariate).

Let X be a continuous random variable with PDF fX(x), and let Y=g(X) where g is a strictly monotone, differentiable function. Then the PDF of Y is fY(y)=fX(g1(y))|ddyg1(y)|.

The factor |(d/dy)g1(y)| accounts for how g stretches or compresses the probability mass. If g expands a region, the density must decrease to keep the total probability equal to 1.

Example 3 (Log-Normal Distribution).

Let X𝒩(μ,σ2) and Y=eX. Since g1(y)=lny and |dg1/dy|=1/y, we get fY(y)=1yσ2πexp((lnyμ)22σ2),y>0. This is the log-normal distribution.

Non-Injective Transformations

When g is not one-to-one (e.g., Y=X2), multiple values of X map to the same Y. We sum over all pre-images: fY(y)={x:g(x)=y}fX(x)|dgi1dy|, where the sum ranges over all branches of the inverse.

Example 4 (Chi-Squared from Standard Normal).

If X𝒩(0,1) and Y=X2, both x=y and x=y map to y. Each branch contributes |d/dy|=1/(2y), giving fY(y)=12πyey/2,y>0, which is the χ2(1) distribution.

Multivariate Case

Theorem 10 (Change of Variables - Multivariate).

Let 𝐱d have density f𝐱(𝐱), and let 𝐲=𝐠(𝐱) where 𝐠:dd is a differentiable bijection. Then (COV Multivariate)f𝐲(𝐲)=f𝐱(𝐠1(𝐲))|det𝐠1𝐲|=f𝐱(𝐠1(𝐲))|det𝐉𝐠1(𝐲)|, where 𝐉𝐠1 is the Jacobian matrix of 𝐠1.

Key Idea.

The multivariate change-of-variables formula is the mathematical heart of normalizing flows. A normalizing flow defines an invertible neural network 𝐠θ:dd and uses (COV Multivariate) to compute the exact likelihood of any data point 𝐲: logpθ(𝐲)=logp𝐳(𝐠θ1(𝐲))+log|det𝐉𝐠θ1(𝐲)|. The challenge is designing architectures where both 𝐠θ1 and its Jacobian determinant are efficient to compute. We will explore this in detail in the normalizing flows chapter.

Statistical Estimation

Having developed the probabilistic tools, we now turn to the question: given observed data, how do we estimate the parameters of a distribution? This is the problem that training a generative model must solve.

Point Estimation: Bias, Variance, and Consistency

Definition 24 (Estimator, Bias, and MSE).

An estimator θ^n of a parameter θ is a function of the observed data X1,,Xn.

  • The bias is B(θ^n)=𝔼[θ^n]θ. If B=0, the estimator is unbiased.

  • The mean squared error is MSE(θ^n)=𝔼[(θ^nθ)2]=𝖵ar(θ^n)+B(θ^n)2.

Definition 25 (Consistent Estimator).

An estimator θ^n is consistent if θ^nPθ as n, i.e., limnP(|θ^nθ|ϵ)=0ϵ>0.

Proposition 4.

If limnMSE(θ^n)=0, then θ^n is consistent.

Proof.

By Markov's inequality, P(|θ^nθ|ϵ)=P(|θ^nθ|2ϵ2)MSE(θ^n)/ϵ20.

Maximum Likelihood Estimation

Definition 26 (Maximum Likelihood Estimator).

Given i.i.d. observations x1,,xn from a distribution pθ, the likelihood function is L(θ)=i=1npθ(xi). The log-likelihood is (θ)=i=1nlogpθ(xi). The maximum likelihood estimator (MLE) is θ^MLE=arg maxθ(θ).

Example 5 (MLE for a Gaussian).

Let x1,,xniid𝒩(μ,σ2). The log-likelihood is (μ,σ2)=n2log(2πσ2)12σ2i=1n(xiμ)2. Setting derivatives to zero gives the MLEs: μ^MLE=1ni=1nxi=x,σ^MLE2=1ni=1n(xix)2. The mean estimator is unbiased; the variance estimator has bias σ2/n (dividing by n1 instead of n gives the unbiased version).

Key Idea.

Training a generative model by maximum likelihood is conceptually simple: we choose the parameters θ that make the observed training data most probable under the model. In practice, the log-likelihood is averaged over minibatches and optimised with stochastic gradient descent: θθ+η1||iθlogpθ(xi). This is the training procedure for autoregressive models, normalizing flows, and (with modifications) for VAEs and diffusion models.

Bayesian Inference

While MLE gives a single “best” parameter value, Bayesian inference maintains a full distribution over parameters, incorporating prior knowledge and quantifying uncertainty.

The setup: we have a prior p(θ) expressing our beliefs before seeing data, and a likelihood p(𝐱|θ). After observing data 𝐱, Bayes' theorem gives the posterior: p(θ|𝐱)=p(𝐱|θ)p(θ)p(𝐱),p(𝐱)=p(𝐱|θ)p(θ)dθ.

Definition 27 (MAP Estimation).

The maximum a posteriori (MAP) estimate is the mode of the posterior: θ^MAP=arg maxθp(θ|𝐱)=arg maxθ[logp(𝐱|θ)+logp(θ)].

Comparing with MLE: θ^MAP=arg maxθ[(θ)+logp(θ)]. The prior logp(θ) acts as a regulariser. For example, a Gaussian prior θ𝒩(0,σ02) adds an L2 penalty θ2/(2σ02), which is precisely weight decay in neural network training.

Example 6 (Conjugate Bayesian Inference for a Bernoulli).

Suppose we observe k successes in n Bernoulli trials and use a Beta(α,β) prior on the success probability p. The posterior is p|dataBeta(α+k,β+nk). This is a conjugate update: the posterior is in the same family as the prior. As n, the posterior concentrates around the MLE p^=k/n, and the prior becomes irrelevant. As α,β0, the MAP estimate approaches the MLE.

Remark 4.

The intractability of the posterior p(θ|𝐱) for complex models (deep neural networks have millions of parameters) is a central challenge in Bayesian deep learning. Variational inference, which we will develop in Chapter 8, approximates the posterior with a simpler distribution by minimising the KL divergence between them.

Exercises

Exercise 1.

Let X be a discrete random variable taking values in {1,2,3,4,5} with P(X=k)=k/15 for k=1,,5. Compute the expectation 𝔼[X] and the variance 𝖵ar(X).

Exercise 2.

A medical test for a rare disease has a sensitivity (true positive rate) of 0.95 and a specificity (true negative rate) of 0.90. The prevalence of the disease is 0.01.

  1. Using Bayes' theorem, compute the probability that a person who tests positive actually has the disease.

  2. Interpret your result. Why is the positive predictive value so low despite the test's high sensitivity?

  3. How does this relate to the challenge of evaluating generative models? Hint: think about the base rate of “real” vs. “generated” images in a dataset.

Exercise 3.

Let X1,,XniidBernoulli(p).

  1. Derive the maximum likelihood estimator p^MLE.

  2. Show that p^MLE is unbiased.

  3. Show that p^MLE is consistent.

Exercise 4.

Let X and Y have joint PDF fX,Y(x,y)=6(1y) for 0xy1 and 0 otherwise.

  1. Compute the marginal PDFs fX(x) and fY(y).

  2. Compute the conditional PDF fX|Y(x|y).

  3. Are X and Y independent? Justify your answer.

Exercise 5.

Derive Chebyshev's inequality from Markov's inequality by applying Markov's inequality to the random variable (Xμ)2.

Exercise 6.

Let x1,,xniid𝒩(μ,σ2) with both μ and σ2 unknown.

  1. Derive the MLEs μ^ and σ^2.

  2. Show that σ^MLE2 is biased and compute its bias.

  3. Propose an unbiased estimator of σ2.

Exercise 7.

Let X𝒩(0,1) and Y=X2. Use the change-of-variables formula for non-injective transformations to derive the PDF of Y. Identify the resulting distribution by name.

Exercise 8.

Let X have prior X𝒩(μ0,σ02), and suppose we observe Y=X+W where W𝒩(0,σW2) is independent of X.

  1. Show that the posterior X|Y=y is Gaussian and find its mean and variance.

  2. Derive the MAP estimate x^MAP and express it as a weighted average of μ0 and y.

  3. What happens as σ02? Interpret this limit.

  4. What happens as σW20? Interpret this limit.

Exercise 9.

Let 𝐱=(X1,X2)𝒩((00),(4223)).

  1. Find the marginal distributions of X1 and X2.

  2. Find the conditional distribution of X1|X2=1.

  3. Verify that the conditional variance is less than the marginal variance.

Exercise 10.

Let 𝐳𝒩(𝟎,𝐈2) and define 𝐱=𝐠(𝐳) where 𝐠(z1,z2)=(z1,z2+z12).

  1. Show that 𝐠 is invertible and find 𝐠1.

  2. Compute the Jacobian matrix 𝐉𝐠1(𝐱) and its determinant.

  3. Write the density f𝐱(𝐱) using the change-of-variables formula.

  4. Is f𝐱 a Gaussian distribution? Why or why not?

This exercise illustrates how a normalizing flow can transform a simple Gaussian into a non-Gaussian distribution using an invertible mapping.

Exercise 11.

Let X be a positive random variable.

  1. Using Jensen's inequality with φ=log (a concave function), show that 𝔼[logX]log𝔼[X].

  2. Now let p(𝐱,𝐳)=p(𝐱|𝐳)p(𝐳) be a joint distribution and let q(𝐳) be any distribution over 𝐳. Show that logp(𝐱)𝔼q(𝐳)[logp(𝐱,𝐳)q(𝐳)]. This inequality is the evidence lower bound (ELBO), the foundation of variational inference.