A beginner-friendly walkthrough of the mathematical prerequisites for reading the Denoising Diffusion Probabilistic Models (DDPM) paper by Jonathan Ho, Ajay Jain, and Pieter Abbeel. This first installment doesn't touch the main method — it clears away the "background" hurdles so that, by the end, you can read Section 2 (Background) without getting stuck.

Why this series exists

If your math is, let's say, average — and if you haven't spent much time around AIGC (text-to-image, text-to-video, and friends) — then opening the DDPM paper for the first time is rough. You glance at the title, Denoising Diffusion Probabilistic Models, and by the time you hit the second paragraph of the Background section you're already lost in a thicket of notation.

Here's the thing: you've almost certainly learned all of this math before. You just quietly handed it back to your teachers somewhere along the way. So when people call DDPM "zero-barrier," my honest reaction the first time through was: this isn't zero-barrier — it's barriers everywhere.

The goal of this post is to lower that barrier. If you're already an expert, feel free to skip this entirely — we're only collecting the prerequisite math and the little stumbling blocks you hit while reading the Background section, all in one place. By the end you'll have the six things you need to read the paper comfortably.


Setting the stage: the notation that trips everyone up

The Background section opens with:

Diffusion models are latent variable models of the form pθ(x0):=∫pθ(x0:T) dx1:T,p_\theta(x_0) := \int p_\theta(x_{0:T})\, dx_{1:T}, where x1,…,xTx_1, \dots, x_T are latents of the same dimensionality as the data x0∼q(x0)x_0 \sim q(x_0).

The first thing that stops you cold is x0:Tx_{0:T}. What is that?

It's just shorthand for the whole sequence:

x0:T:=x0,x1,…,xT.x_{0:T} := x_0, x_1, \dots, x_T.

Written as a probability, it's the joint distribution over x0x_0 through xTx_T:

pθ(x0:T)=pθ(x0,x1,…,xT).p_\theta(x_{0:T}) = p_\theta(x_0, x_1, \dots, x_T).

Once you know that, the defining equation reads cleanly:

  • pθ(⋅)p_\theta(\cdot) — anything with the subscript θ\theta is produced by our model (a deep neural network). We're using the network to predict a distribution.
  • pθ(x0)=∫pθ(x0:T) dx1:Tp_\theta(x_0) = \int p_\theta(x_{0:T})\, dx_{1:T} — here dx1:Tdx_{1:T} means dx1 dx2⋯dxTdx_1\, dx_2 \cdots dx_T. We integrate out every latent variable x1,…,xTx_1, \dots, x_T, and the only variable left standing is x0x_0. So the integral of the joint over all the latents gives back the marginal pθ(x0)p_\theta(x_0).

This is just the basic marginalization rule from probability.

A note on rigor: Anything at or below a high-school level we'll use without proof. For some post-high-school results I'll sketch a proof; for the genuinely messy ones I'll skip the derivation to keep the pace. If you want a particular formula derived, that can go in a follow-up.

That's hurdle one cleared. On to the next.


Prerequisite 1: The reverse process

The joint distribution pθ(x0:T)p_\theta(x_{0:T}) is called the reverse process, and the paper defines it as a Markov chain with learned Gaussian transitions starting at p(xT)=N(xT;0,I)p(x_T) = \mathcal{N}(x_T; \mathbf{0}, \mathbf{I}):

pθ(x0:T):=p(xT)∏t=1Tpθ(xt−1∣xt),pθ(xt−1∣xt):=N(xt−1; μθ(xt,t), Σθ(xt,t)).p_\theta(x_{0:T}) := p(x_T) \prod_{t=1}^{T} p_\theta(x_{t-1} \mid x_t), \qquad p_\theta(x_{t-1} \mid x_t) := \mathcal{N}\big(x_{t-1};\ \mu_\theta(x_t, t),\ \Sigma_\theta(x_t, t)\big).

What does "reverse" mean here?

It refers to time. In DDPM:

  • Forward direction: x0→xTx_0 \to x_T (the index increases — clean image gets progressively noisier).
  • Reverse direction: xT→x0x_T \to x_0 (the index decreases — noise gets progressively denoised).

We start from p(xT)p(x_T), the prior distribution, which we simply define to be a standard Gaussian (pure Gaussian noise). The whole model is the journey from that prior back to the data distribution.

Deriving the product form

The transition term pθ(xt−1∣xt)p_\theta(x_{t-1} \mid x_t) seems to appear out of nowhere. Let's derive it on a small example so it stops feeling like magic.

Start from the only tool we need — the conditional probability rule you learned in high school:

P(A,B)=P(A∣B) P(B)=P(B∣A) P(A).P(A, B) = P(A \mid B)\, P(B) = P(B \mid A)\, P(A).

There are two ways to split P(A,B)P(A,B). Which split we pick is the trick, and it's dictated by the direction of the process. The reverse process runs backward in time, so we want to peel off variables along decreasing time — which means the conditioning variable should be the later (larger-index) one.

Take a three-variable example, P(x0,x1,x2)P(x_0, x_1, x_2). Group (x0,x1)(x_0, x_1) together as one block and condition on x2x_2:

P(x0,x1,x2)=P(x0,x1∣x2) P(x2).P(x_0, x_1, x_2) = P(x_0, x_1 \mid x_2)\, P(x_2).

Now split the block P(x0,x1∣x2)P(x_0, x_1 \mid x_2) the same way — keep time decreasing, so x0x_0 is conditioned on x1x_1:

P(x0,x1∣x2)=P(x0∣x1,x2) P(x1∣x2).P(x_0, x_1 \mid x_2) = P(x_0 \mid x_1, x_2)\, P(x_1 \mid x_2).

Putting it together:

P(x0,x1,x2)=P(x0∣x1,x2) P(x1∣x2) P(x2).P(x_0, x_1, x_2) = P(x_0 \mid x_1, x_2)\, P(x_1 \mid x_2)\, P(x_2).

Applying the Markov property

DDPM assumes the Markov property: a state depends only on the adjacent time step. Anything further back can be dropped. So in P(x0∣x1,x2)P(x_0 \mid x_1, x_2), the x2x_2 condition is non-adjacent to x0x_0 and can be crossed out:

P(x0∣x1,x2)=P(x0∣x1).P(x_0 \mid x_1, x_2) = P(x_0 \mid x_1).

Which gives:

P(x0,x1,x2)=P(x0∣x1) P(x1∣x2) P(x2).P(x_0, x_1, x_2) = P(x_0 \mid x_1)\, P(x_1 \mid x_2)\, P(x_2).

Generalizing from {x0,x1,x2}\{x_0, x_1, x_2\} to x0:Tx_{0:T}, you can write it in one step — pull out the last term p(xT)p(x_T) and take the product:

 pθ(x0:T)=p(xT)∏t=1Tpθ(xt−1∣xt) \boxed{\,p_\theta(x_{0:T}) = p(x_T) \prod_{t=1}^{T} p_\theta(x_{t-1} \mid x_t)\,}

This is a reverse process: the larger time index sits in the condition, the smaller one is what we predict.


Prerequisite 2: The forward process

Next comes the forward process (forward process), also a Markov chain — the paper tells you so directly:

q(x1:T∣x0):=∏t=1Tq(xt∣xt−1),q(xt∣xt−1):=N(xt; 1−βt xt−1, βtI).q(x_{1:T} \mid x_0) := \prod_{t=1}^{T} q(x_t \mid x_{t-1}), \qquad q(x_t \mid x_{t-1}) := \mathcal{N}\big(x_t;\ \sqrt{1 - \beta_t}\, x_{t-1},\ \beta_t \mathbf{I}\big).

The forward process is the noising direction: we're given a clean image x0x_0 and progressively add Gaussian noise. Because it's forward, the Markov dependence points to the next time step, and crucially the condition x0x_0 is given.

Deriving the product form

Same trick, opposite direction. Consider P(x3,x2,x1∣x0)P(x_3, x_2, x_1 \mid x_0). Ignore the given x0x_0 for a moment and just split P(x3,x2,x1)P(x_3, x_2, x_1).

For the forward process we want the conditioning index to be smaller than the predicted one. Peel off x1x_1 first (the smallest), conditioning the rest on it:

P(x3,x2,x1)=P(x3,x2∣x1) P(x1).P(x_3, x_2, x_1) = P(x_3, x_2 \mid x_1)\, P(x_1).

Split again the same way:

P(x3,x2∣x1)=P(x3∣x2,x1) P(x2∣x1).P(x_3, x_2 \mid x_1) = P(x_3 \mid x_2, x_1)\, P(x_2 \mid x_1).

So:

P(x3,x2,x1)=P(x3∣x2,x1) P(x2∣x1) P(x1).P(x_3, x_2, x_1) = P(x_3 \mid x_2, x_1)\, P(x_2 \mid x_1)\, P(x_1).

Now reattach the given x0x_0 as a "carry-along" condition on every term:

P(x3,x2,x1∣x0)=P(x3∣x2,x1,x0) P(x2∣x1,x0) P(x1∣x0).P(x_3, x_2, x_1 \mid x_0) = P(x_3 \mid x_2, x_1, x_0)\, P(x_2 \mid x_1, x_0)\, P(x_1 \mid x_0).

Apply the Markov property — each state depends only on the immediately previous one (x3x_3 depends only on x2x_2, not on x1x_1 or x0x_0):

P(x3,x2,x1∣x0)=P(x3∣x2) P(x2∣x1) P(x1∣x0).P(x_3, x_2, x_1 \mid x_0) = P(x_3 \mid x_2)\, P(x_2 \mid x_1)\, P(x_1 \mid x_0).

Switching from PP to qq and generalizing to TT terms:

 q(x1:T∣x0)=∏t=1Tq(xt∣xt−1) \boxed{\,q(x_{1:T} \mid x_0) = \prod_{t=1}^{T} q(x_t \mid x_{t-1})\,}

Reverse vs. forward — the one rule to remember

When you decompose a joint with conditional probability, P(A,B)P(A, B) can become P(A∣B)P(B)P(A \mid B)P(B) or P(B∣A)P(A)P(B \mid A)P(A). Which one you pick depends on the direction:

Process Direction Conditioning index Why
Reverse xT→x0x_T \to x_0 the larger time index We solve for images going backward, so the larger time sits in the condition.
Forward x0→xTx_0 \to x_T the smaller time index We're given x0x_0 and add noise, so the smaller time sits in the condition.

The two split in opposite ways — that's the whole subtlety, and it's easy once you've worked the small examples by hand.


Prerequisite 3: The variational bound (and Jensen's inequality)

Now the paper hits you with the training objective:

E[−log⁡pθ(x0)]≤Eq ⁣[−log⁡pθ(x0:T)q(x1:T∣x0)]=Eq ⁣[−log⁡p(xT)−∑t≥1log⁡pθ(xt−1∣xt)q(xt∣xt−1)]=:L.\mathbb{E}\big[-\log p_\theta(x_0)\big] \le \mathbb{E}_q\!\left[-\log \frac{p_\theta(x_{0:T})}{q(x_{1:T} \mid x_0)}\right] = \mathbb{E}_q\!\left[-\log p(x_T) - \sum_{t \ge 1} \log \frac{p_\theta(x_{t-1} \mid x_t)}{q(x_t \mid x_{t-1})}\right] =: L.

This is the "variational bound on negative log likelihood." At first glance the left and right sides look unrelated — and that ≤\le sign is doing a lot of quiet work. Let's reconstruct it.

The objective

In image generation we want the probability of generating the image we want to be large — we want our samples to be real images, not noise or garbage. So our goal is to maximize log⁡pθ(x0)\log p_\theta(x_0). Since this is an optimization problem, maximizing is equivalent to minimizing the negative:

max⁡ log⁡pθ(x0)  ⟺  min⁡ (−log⁡pθ(x0)).\max\ \log p_\theta(x_0) \iff \min\ \big(-\log p_\theta(x_0)\big).

The sign is a matter of convenience; ignore it for now and analyze the quantity itself.

Reusing earlier results

Good papers are logically tight — every formula they already wrote down tends to get reused. We have two such formulas sitting around: the marginalization rule, and the q(x1:T∣x0)q(x_{1:T}\mid x_0) decomposition. Let's force both into play.

Step 1 — marginalize. Using pθ(x0)=∫pθ(x0:T) dx1:Tp_\theta(x_0) = \int p_\theta(x_{0:T})\, dx_{1:T}:

log⁡pθ(x0)=log⁡∫pθ(x0:T) dx1:T.\log p_\theta(x_0) = \log \int p_\theta(x_{0:T})\, dx_{1:T}.

Step 2 — multiply and divide by qq. We still haven't used the forward decomposition, so let's "force" it in by multiplying and dividing by q(x1:T∣x0)q(x_{1:T} \mid x_0). Since we're integrating over x1:Tx_{1:T}, we need a distribution over x1:Tx_{1:T} to take an expectation against:

log⁡pθ(x0)=log⁡∫q(x1:T∣x0) pθ(x0:T)q(x1:T∣x0) dx1:T.\log p_\theta(x_0) = \log \int q(x_{1:T} \mid x_0)\, \frac{p_\theta(x_{0:T})}{q(x_{1:T} \mid x_0)}\, dx_{1:T}.

Step 3 — recognize the expectation. An integral of the form ∫q(⋅) [ ⋅ ] dx\int q(\cdot)\, [\,\cdot\,]\, dx is exactly an expectation with respect to qq:

log⁡pθ(x0)=log⁡ Eq(x1:T∣x0) ⁣[pθ(x0:T)q(x1:T∣x0)].\log p_\theta(x_0) = \log\ \mathbb{E}_{q(x_{1:T} \mid x_0)}\!\left[\frac{p_\theta(x_{0:T})}{q(x_{1:T} \mid x_0)}\right].

The subscript on E\mathbb{E} matters enormously. Always be clear which distribution you're taking the expectation over — here it's q(x1:T∣x0)q(x_{1:T} \mid x_0).

We're now almost at the paper's form. The only difference is the order of log⁡\log and E\mathbb{E}. Can we just swap them? No — and that's where Jensen's inequality comes in.

Jensen's inequality (with the trap that catches everyone)

Start with the definition of a convex function (Chinese: 下凸, "convex from below"). A real-valued function ff on a convex subset CC is convex if for any two points x1,x2∈Cx_1, x_2 \in C and 0≤t≤10 \le t \le 1:

t f(x1)+(1−t) f(x2)≥f(tx1+(1−t)x2).t\, f(x_1) + (1 - t)\, f(x_2) \ge f\big(t x_1 + (1 - t) x_2\big).

(The weighted average of the function values lies above the function of the weighted average — the chord sits above the curve.)

Generalizing to many points gives Jensen's inequality for a convex ff, with weights λi≥0\lambda_i \ge 0 (in fact λi>0\lambda_i > 0) and ∑i=1Mλi=1\sum_{i=1}^{M} \lambda_i = 1:

f ⁣(∑i=1Mλixi)≤∑i=1Mλif(xi).f\!\left(\sum_{i=1}^{M} \lambda_i x_i\right) \le \sum_{i=1}^{M} \lambda_i f(x_i).

Because ∑iλi=1\sum_i \lambda_i = 1 with λi>0\lambda_i > 0, the weights act exactly like a probability distribution (the discrete analogue of ∫p(x) dx=1\int p(x)\,dx = 1). So this is precisely:

f(E[X])≤E[f(X)](f convex).f\big(\mathbb{E}[X]\big) \le \mathbb{E}\big[f(X)\big] \qquad (f \text{ convex}).

Here is the trap. Our ff is log⁡\log, and log⁡\log is concave (Chinese: 上凸, "convex from above"), not convex. A lot of blog posts quote only the convex version — and don't even tell you their ff is convex. If you sketch log⁡\log you'll see immediately it curves the other way, so the inequality flips:

f(E[X])≥E[f(X)](f concave, e.g. log⁡).f\big(\mathbb{E}[X]\big) \ge \mathbb{E}\big[f(X)\big] \qquad (f \text{ concave, e.g. } \log).

Geometrically: take x1,x2x_1, x_2 on the log⁡\log curve and t=12t = \tfrac12. The point on the curve above the midpoint 12x1+12x2\tfrac12 x_1 + \tfrac12 x_2 is higher than the midpoint of the chord 12f(x1)+12f(x2)\tfrac12 f(x_1) + \tfrac12 f(x_2). That's concavity, and it's the reason the inequality reverses.

Putting it together

Apply the concave (flipped) Jensen to our expression — log⁡\log moves inside the expectation and the relation becomes ≥\ge:

log⁡pθ(x0)=log⁡ Eq ⁣[pθ(x0:T)q(x1:T∣x0)] ≥ Eq ⁣[log⁡pθ(x0:T)q(x1:T∣x0)].\log p_\theta(x_0) = \log\ \mathbb{E}_{q}\!\left[\frac{p_\theta(x_{0:T})}{q(x_{1:T}\mid x_0)}\right] \ \ge\ \mathbb{E}_{q}\!\left[\log \frac{p_\theta(x_{0:T})}{q(x_{1:T} \mid x_0)}\right].

This already matches the paper's right-hand side — except for a missing negative sign. Easy: negate both sides (which flips ≥\ge to ≤\le), consistent with "maximize ⇒\Rightarrow minimize the negative":

 −log⁡pθ(x0) ≤ Eq ⁣[−log⁡pθ(x0:T)q(x1:T∣x0)]=:L \boxed{\,-\log p_\theta(x_0) \ \le\ \mathbb{E}_{q}\!\left[-\log \frac{p_\theta(x_{0:T})}{q(x_{1:T} \mid x_0)}\right] =: L\,}

That's the variational bound. The paper never tells you it relies on Jensen's inequality — so without knowing it, you simply can't reproduce this step. The rest of the bound's expansion into per-step terms we'll cover next time.


Prerequisite 4: The normal distribution PDF

For a Gaussian X∼N(μ,σ2)X \sim \mathcal{N}(\mu, \sigma^2), the probability density is:

p(x)=12π σ exp⁡ ⁣(−(x−μ)22σ2).p(x) = \frac{1}{\sqrt{2\pi}\,\sigma}\, \exp\!\left(-\frac{(x - \mu)^2}{2\sigma^2}\right).

You've seen this since high school / early college. It shows up everywhere downstream — including the eventual derivation of the posterior mean μ\mu.


Prerequisite 5: Sum of independent Gaussians

If

X1∼N(μ1,σ12),X2∼N(μ2,σ22),X_1 \sim \mathcal{N}(\mu_1, \sigma_1^2), \qquad X_2 \sim \mathcal{N}(\mu_2, \sigma_2^2),

then their sum is again Gaussian, with means adding and variances adding:

X1+X2∼N(μ1+μ2, σ12+σ22).X_1 + X_2 \sim \mathcal{N}\big(\mu_1 + \mu_2,\ \sigma_1^2 + \sigma_2^2\big).

That the mean and variance add follows from the basic linearity/variance properties of expectation. The harder part — proving that the sum is itself normally distributed — uses the convolution formula (the same convolution you know from CNNs):

pX1+X2(z)=∫pX1(x) pX2(z−x) dx.p_{X_1 + X_2}(z) = \int p_{X_1}(x)\, p_{X_2}(z - x)\, dx.


Prerequisite 6: KL divergence

The Kullback–Leibler (KL) divergence measures how similar two distributions are:

DKL(P∥Q)=∫p(x) log⁡p(x)q(x) dx.D_{\mathrm{KL}}\big(P \parallel Q\big) = \int p(x)\, \log \frac{p(x)}{q(x)}\, dx.

Key intuitions:

  • Smaller KL ⇒\Rightarrow more similar distributions (not the other way around).
  • DKL≥0D_{\mathrm{KL}} \ge 0 always.
  • If P=QP = Q, the ratio is always 11, log⁡1=0\log 1 = 0, so DKL=0D_{\mathrm{KL}} = 0.
  • The further apart PP and QQ are, the larger the value.

So in training we want this value to be small — we're driving two distributions together. When both PP and QQ are Gaussian, substituting the normal PDF yields a clean closed-form expression (which we'll use later).


The six things — your checklist

If you're solid on these six, you can read the DDPM Background section with zero barriers:

  1. Joint-distribution notation & marginalization — x0:T=x0,…,xTx_{0:T} = x_0,\dots,x_T, and pθ(x0)=∫pθ(x0:T) dx1:Tp_\theta(x_0) = \int p_\theta(x_{0:T})\,dx_{1:T}.
  2. Reverse process decomposition — conditional probability + Markov property; condition on the larger time index.
  3. Forward process decomposition — same tools, condition on the smaller time index.
  4. Variational bound — maximize log⁡pθ(x0)  ⟺  \log p_\theta(x_0) \iff minimize its negative, plus Jensen's inequality (remember: log⁡\log is concave, so the inequality flips).
  5. Normal distribution PDF and the sum-of-Gaussians rule (via convolution).
  6. KL divergence — definition, non-negativity, and "smaller = more similar."

Everything after this in the paper is mostly elementary math — the formulas get long, but they no longer require clever tricks.


What's next

Next time we'll tackle the method itself: the tractable forward posterior

q(xt−1∣xt,x0)=N(xt−1; μ~t(xt,x0), β~tI),q(x_{t-1} \mid x_t, x_0) = \mathcal{N}\big(x_{t-1};\ \tilde{\mu}_t(x_t, x_0),\ \tilde{\beta}_t \mathbf{I}\big),

with

μ~t(xt,x0):=αˉt−1 βt1−αˉt x0+αt (1−αˉt−1)1−αˉt xt,β~t:=1−αˉt−11−αˉt βt,\tilde{\mu}_t(x_t, x_0) := \frac{\sqrt{\bar\alpha_{t-1}}\,\beta_t}{1 - \bar\alpha_t}\, x_0 + \frac{\sqrt{\alpha_t}\,(1 - \bar\alpha_{t-1})}{1 - \bar\alpha_t}\, x_t, \qquad \tilde{\beta}_t := \frac{1 - \bar\alpha_{t-1}}{1 - \bar\alpha_t}\,\beta_t,

where αt:=1−βt\alpha_t := 1 - \beta_t and αˉt:=∏s=1tαs\bar\alpha_t := \prod_{s=1}^{t} \alpha_s. We'll see why we must condition on x0x_0 to turn the unknown into the known, derive the mean and variance, and then use reparameterized sampling to iterate xt→xt−1x_t \to x_{t-1} all the way from pure noise xTx_T back to a clean image x0x_0.

See you in the next one.


Notes taken from a video tutorial on DDPM (Part 1 of the series).


References

  • Ho, J., Jain, A., & Abbeel, P. (2020). Denoising Diffusion Probabilistic Models. NeurIPS 2020. arXiv:2006.11239