Lecture 11 · Robot Policies · November 25
Diffusion and Diffusion Policy
From noisy vectors to robot action sequences
One observation. Several successful action sequences.
input / noise · demonstrations · generated actions
Mathematics for Robotics · ROB-GY 6013 · NYU Tandon · Jing Zhang · Fall 2026
Diffusion Policy §4.1 · Chi et al. (2023/2024)
Prerequisite recall
Diffusion and Diffusion Policy
Four familiar tools meet one new task
Recall: Lecture 8 pp.12–18; Lecture 5 pp.11,29; Lecture 6 pp.30,62.
$$\E\|Y-g(X)\|^2$$
- $X,Y$
- random input and target
- $g$
- prediction rule
DL §3.8; DDPM §3.2 · Ho, Jain & Abbeel (2020) · Goodfellow et al. (2016)
Motivation
Multimodal actions
Two valid actions can have an invalid mean
$$P(A=-2\mid o)=P(A=2\mid o)=\tfrac12$$
- $A$
- scalar action
- $o$
- fixed observation
Diffusion Policy §4.1 · Chi et al. (2023/2024)
General rule
Multimodal actions
Squared error selects a conditional mean
$$\E[(A-u)^2\mid o]=\operatorname{Var}(A\mid o)+(u-\E[A\mid o])^2$$
- $u$
- chosen scalar prediction
- $A,o$
- action and observation
Return to the result and check its symbols and assumptions.
Derivation 1 / 2
Expand around the conditional mean
Fix o. Let m=E[A|o], u the chosen scalar prediction, and assume a finite second moment.
- $A-u=(A-m)+(m-u)$.
- $(A-u)^2=(A-m)^2+2(A-m)(m-u)+(m-u)^2$.
- $\E[A-m\mid o]=0$, so the averaged cross term is zero.
Derivation 2 / 2
Only one term depends on the prediction
m is fixed when we change u.
- $\E[(A-u)^2\mid o]=\operatorname{Var}(A\mid o)+(m-u)^2$.
- The variance is independent of u; the remaining square is minimized at zero.
- Thus $u^*=m=\E[A\mid o]$.
DL §3.8; course derivation · Goodfellow et al. (2016)
Worked example
Multimodal actions
Worked example: the average misses both modes
$$R(u)=\tfrac12(u+2)^2+\tfrac12(u-2)^2=u^2+4$$
- $R$
- conditional squared-error risk
- $u$
- action prediction
Diffusion Policy §4.1; course example · Chi et al. (2023/2024)
Your turn
Multimodal actions
Transfer: one route is more common
Find the squared-error minimizer u; compare it with the mode.
$$P(A=-2\mid o)=\tfrac34,\quad P(A=2\mid o)=\tfrac14$$
- $A$
- action
- $u$
- fixed prediction to optimize
Check $u^*=-1$; a mean need not be a mode.
Solution 1 / 1
Choose the conditional mean
A is the random action; u is a deterministic prediction.
- Squared error is minimized by $u^*=\E[A\mid o]$.
- $u^*=\tfrac34(-2)+\tfrac14(2)=-\tfrac32+\tfrac12=-1$.
- The mode is -2, while the minimum-risk mean is -1.
DL §3.8; course exercise · Goodfellow et al. (2016)
Your turn
Multimodal actions
A distribution and its mean answer different questions
Fixed observation; equally likely actions -2 and 2.
Compare: conditional mean vs a random draw.
Check Sampling preserves the two choices.
Solution 1 / 1
Compare the operations
A is an action drawn from the two-point distribution.
- $\E[A\mid o]=0$: averaging returns one fixed value.
- $A\sim p(\cdot\mid o)$: sampling returns -2 or 2, each with probability one half.
- A correct distribution can still have an unusable mean.
Diffusion Policy §4.1; course exercise · Chi et al. (2023/2024)
Motivation
Forward diffusion
Noise creates a supervised learning task
DDPM §2, Algorithms 1–2 · Ho, Jain & Abbeel (2020)
Objects
Forward diffusion
Two clocks and three kinds of vectors
$$x_0,x_k,\epsilon\in\mathbb R^d,\quad k\in\{1,\ldots,K\}$$
- $x_0,x_k$
- clean and noisy vectors
- $k,K$
- noise index and final level
- $\epsilon$
- standard Gaussian noise
DDPM §2; Diffusion Policy §2.3 · Ho, Jain & Abbeel (2020) · Chi et al. (2023/2024)
Definition
Forward diffusion
One step shrinks signal and adds fresh noise
$$x_k=\sqrt{1-\beta_k}\,x_{k-1}+\sqrt{\beta_k}\,z_k$$
- $0<\beta_k<1$
- chosen noise variance
- $z_k\sim\mathcal N(0,I)$
- fresh independent noise
DDPM §2, Eq.2 · Ho, Jain & Abbeel (2020)
Your turn
Forward diffusion
Check the conditional mean and covariance
Find the conditional mean and covariance of x_k.
$$x_k=\sqrt{1-\beta_k}\,x_{k-1}+\sqrt{\beta_k}\,z_k$$
- $x_{k-1}$
- fixed when conditioned on
- $z_k$
- independent N(0,I) vector
Check Mean $\sqrt{1-\beta_k}x_{k-1}$; covariance $\beta_k I$.
Solution 1 / 1
Conditioning fixes the input
z_k has mean zero and covariance I.
- $\E[x_k\mid x_{k-1}]=\sqrt{1-\beta_k}\,x_{k-1}$.
- $x_k-\E[x_k\mid x_{k-1}]=\sqrt{\beta_k}z_k$.
- $\operatorname{Cov}(x_k\mid x_{k-1})=\beta_k I$.
DDPM Eq.2; DL §3.8 · Ho, Jain & Abbeel (2020) · Goodfellow et al. (2016)
Your turn
Forward diffusion
Transfer: variance is not the noise multiplier
Compute the realized x_k; show both coefficients.
$$\beta_k=0.36,\quad x_{k-1}=2,\quad z_k=-1$$
- $\beta_k$
- variance
- $x_{k-1},z_k$
- given scalar values
Check $x_k=0.8(2)+0.6(-1)=1$.
Solution 1 / 1
Compute coefficients before the state
The fresh noise z_k=-1 has been realized.
- $\sqrt{1-\beta_k}=\sqrt{0.64}=0.8$, and $\sqrt{\beta_k}=0.6$.
- $x_k=0.8\times2+0.6\times(-1)=1.6-0.6=1$.
- Using 0.36 as the noise multiplier would give the wrong variance.
DDPM Eq.2; course exercise · Ho, Jain & Abbeel (2020)
Derivation
Forward diffusion
Two steps expose the cumulative signal
$$x_2=\sqrt{a_2a_1}x_0+\sqrt{a_2\beta_1}z_1+\sqrt{\beta_2}z_2$$
- $a_j=1-\beta_j$
- one-step retention
- $z_1,z_2$
- independent N(0,I) noise
Return to the result and check its symbols and assumptions.
Derivation 1 / 1
Substitute the first transition into the second
a_j=1−beta_j. The independent z1 and z2 are standard Gaussian vectors.
- $x_1=\sqrt{a_1}x_0+\sqrt{\beta_1}z_1$.
- $x_2=\sqrt{a_2}x_1+\sqrt{\beta_2}z_2$.
- $x_2=\sqrt{a_2a_1}x_0+\sqrt{a_2\beta_1}z_1+\sqrt{\beta_2}z_2$.
DDPM §2, Eq.4; course expansion · Ho, Jain & Abbeel (2020)
Derivation
Forward diffusion
Independent Gaussian variances combine
$$a_2\beta_1+\beta_2=(1-\beta_2)\beta_1+\beta_2=1-a_1a_2$$
- $a_j=1-\beta_j$
- retained variance fraction
- $z_1,z_2$
- independent standard Gaussians
Return to the result and check its symbols and assumptions.
Derivation 1 / 1
Combine independent centered noise terms
The two noise coefficients are sqrt(a2 beta1) and sqrt(beta2).
- $\operatorname{Cov}(\sqrt{a_2\beta_1}z_1+\sqrt{\beta_2}z_2)=(a_2\beta_1+\beta_2)I$.
- $a_2\beta_1+\beta_2=(1-\beta_2)\beta_1+\beta_2=1-a_1a_2$.
- The sum is Gaussian. Replace it in distribution by a standard Gaussian scaled by sqrt(1−a1 a2).
DDPM Eq.4; course derivation · Ho, Jain & Abbeel (2020)
Result
Forward diffusion
Any noise level can be sampled directly
$$x_k=\alpha_kx_0+\sigma_k\epsilon,\quad\epsilon\sim\mathcal N(0,I)$$
- $\alpha_k=\sqrt{\bar a_k}$
- signal coefficient
- $\sigma_k=\sqrt{1-\bar a_k}$
- noise standard deviation
- $\bar a_k=\prod_{j=1}^k a_j$
- cumulative retention
DDPM Eq.4; notation bridge · Ho, Jain & Abbeel (2020)
Interpretation
Forward diffusion
A schedule controls signal-to-noise ratio
$$\operatorname{SNR}_k=\frac{\alpha_k^2}{\sigma_k^2}=\frac{\bar a_k}{1-\bar a_k}$$
- $\bar a_k$
- cumulative signal retention
- $SNR_k$
- coefficient ratio, for unit-scale signal
DDPM §4; Diffusion Policy §3.3 · Ho, Jain & Abbeel (2020) · Chi et al. (2023/2024)
Worked example
Forward diffusion
Worked example: one noisy training pair
$$x_0=2,\ \alpha_k=0.8,\ \sigma_k=0.6,\ \epsilon=-0.5$$
- $x_0$
- clean scalar
- $\epsilon$
- known training noise
- $\alpha_k,\sigma_k$
- fixed coefficients
DDPM Algorithm 1; course example · Ho, Jain & Abbeel (2020)
Your turn
Forward diffusion
Transfer: a two-component action
Compute x, then recover the sampled noise.
$$x_0=\begin{bmatrix}2\\-1\end{bmatrix},\ \epsilon=\begin{bmatrix}-0.5\\1\end{bmatrix},\ \alpha=0.8,\ \sigma=0.6$$
- $x_0,\epsilon\in\mathbb R^2$
- given vectors
- $x=\alpha x_0+\sigma\epsilon$
- noisy vector to find
Check $x=(1.3,-0.2)^T$.
Solution 1 / 1
Apply the rule componentwise
x, x0 and epsilon are two-component column vectors.
- $x_1=0.8(2)+0.6(-0.5)=1.3$.
- $x_2=0.8(-1)+0.6(1)=-0.2$.
- $(x-0.8x_0)/0.6=(-0.5,1)^T=\epsilon$.
DDPM Eq.4; course exercise · Ho, Jain & Abbeel (2020)
Your turn
Forward diffusion
The marginal covariance also contains data spread
Find the mean and covariance of X_k.
$$X_k=\alpha_kX_0+\sigma_k\epsilon,\quad X_0\perp\epsilon$$
- $\mu_0,\Sigma_0$
- clean-data mean and covariance
- $\epsilon\sim\mathcal N(0,I)$
- independent noise
Check $\mu_k=\alpha_k\mu_0$, $\Sigma_k=\alpha_k^2\Sigma_0+\sigma_k^2I$.
Solution 1 / 1
Average over examples and noise
X0 is now random; epsilon is independent and centered.
- $\E[X_k]=\alpha_k\E[X_0]+\sigma_k\E[\epsilon]=\alpha_k\mu_0$.
- $X_k-\mu_k=\alpha_k(X_0-\mu_0)+\sigma_k\epsilon$.
- $\operatorname{Cov}(X_k)=\alpha_k^2\Sigma_0+\sigma_k^2I$; cross terms vanish by independence.
DDPM Eq.4; DL §3.8 · Ho, Jain & Abbeel (2020) · Goodfellow et al. (2016)
Assumption
Forward diffusion
The terminal Gaussian is a schedule approximation
$$\alpha_K\approx0,\quad\sigma_K\approx1\quad\Longrightarrow\quad X_K\approx\mathcal N(0,I)$$
- $K$
- last diffusion index
- $X_K$
- marginal noisy-data vector
DDPM §4, terminal prior · Ho, Jain & Abbeel (2020)
Your turn
Forward diffusion
Does this terminal schedule match the prior?
Can the terminal law equal N(0,1)? Check its moments.
$$\alpha_K=0.8,\ \sigma_K=0.6,\quad \E[X_0]=5,\ \operatorname{Var}(X_0)=1$$
- $X_0,X_K$
- scalar clean and noisy data
- $N(0,1)$
- proposed generation prior
Check Variance 1 alone does not establish N(0,1).
Solution 1 / 1
Use a necessary moment check
The added standard noise is independent of clean data.
- $\E[X_K]=0.8\times5=4$.
- $\operatorname{Var}(X_K)=0.8^2(1)+0.6^2=1$.
- A standard normal has mean zero. Matching its variance does not repair the mean mismatch.
DDPM §4; course exercise · Ho, Jain & Abbeel (2020)
Definition
The score
A density supplies a local direction
$$s_k(x)=\nabla_x\log p_k(x)$$
- $p_k$
- density at noise level k
- $s_k(x)\in\mathbb R^d$
- gradient with respect to x
Vincent (2011), §2; DDPM §3.2 · Ho, Jain & Abbeel (2020) · Vincent (2011)
Starting relation
The score
Start with a Gaussian log density
$$\log p(x)=C-\frac{(x-\mu)^2}{2v}$$
- $\mu\in\mathbb R,\ v>0$
- fixed mean and variance
- $C=-\tfrac12\log(2\pi v)$
- constant with respect to x
DL §3.9.3; course derivation · Goodfellow et al. (2016)
Derivation
The score
Differentiate the quadratic one step at a time
$$s(x)=-\frac{1}{2v}\,2(x-\mu)=-\frac{x-\mu}{v}$$
- $\mu,v$
- fixed mean and variance
- $s(x)$
- scalar score
Return to the result and check its symbols and assumptions.
Derivation 1 / 1
Differentiate the scalar Gaussian log density
mu and positive variance v are fixed; C is constant in x.
- $\log p(x)=C-(x-\mu)^2/(2v)$.
- $\partial_x C=0$, and $\partial_x(x-\mu)^2=2(x-\mu)$.
- $s(x)=-[2(x-\mu)]/(2v)=-(x-\mu)/v$.
DL §3.9.3; course derivation · Goodfellow et al. (2016)
General rule
The score
Covariance shapes the vector direction
$$s(x)=-\Sigma^{-1}(x-\mu)$$
- $x,\mu\in\mathbb R^d$
- state and mean
- $\Sigma\succ0$
- fixed covariance
Return to the result and check its symbols and assumptions.
Derivation 1 / 1
Differentiate a symmetric quadratic form
r=x−mu is a column vector. Positive-definite covariance Sigma is fixed.
- $\log p(x)=C-\tfrac12r^T\Sigma^{-1}r$.
- $d(r^T\Sigma^{-1}r)=dr^T\Sigma^{-1}r+r^T\Sigma^{-1}dr=2r^T\Sigma^{-1}dx$.
- $d\log p(x)=(-\Sigma^{-1}r)^Tdx$, so $s(x)=-\Sigma^{-1}(x-\mu)$.
DL §3.9.3; Lecture 5 quadratic differential · Goodfellow et al. (2016)
Your turn
The score
Compute an anisotropic score
Compute s(x). Is its direction parallel to −x?
$$\mu=\begin{bmatrix}0\\0\end{bmatrix},\ \Sigma=\begin{bmatrix}4&0\\0&1\end{bmatrix},\ x=\begin{bmatrix}2\\1\end{bmatrix}$$
- $\Sigma$
- covariance, not standard deviations
- $s(x)=-\Sigma^{-1}(x-\mu)$
- score to find
Check $s(x)=(-0.5,-1)^T$.
Solution 1 / 1
Apply the precision matrix
The inverse covariance is the precision matrix.
- $\Sigma^{-1}=\operatorname{diag}(1/4,1)$.
- $s(x)=-\operatorname{diag}(1/4,1)(2,1)^T=(-1/2,-1)^T$.
- The narrower second direction receives stronger correction per unit displacement.
DL §3.9.3; course exercise · Goodfellow et al. (2016)
Derivation
The score
An unknown normalizing constant disappears
$$p(x)=\frac{e^{-E(x)}}{Z}\quad\Longrightarrow\quad\nabla_x\log p(x)=-\nabla_x E(x)$$
- $E(x)$
- differentiable energy
- $Z$
- finite positive constant independent of x
Vincent (2011), §2 · Vincent (2011)
Derivation
The score
A mixture score averages local component scores
$$s(x)=\sum_j r_j(x)s_j(x),\quad r_j(x)=\frac{w_jp_j(x)}{\sum_iw_ip_i(x)}$$
- $w_j,p_j$
- weight and component density
- $r_j(x)$
- responsibility at x
Return to the result and check its symbols and assumptions.
Derivation 1 / 1
Differentiate the sum before taking responsibilities
The weights w_j are fixed and sum to one; component densities are differentiable.
- $p(x)=\sum_jw_jp_j(x)$, so $\nabla p(x)=\sum_jw_j\nabla p_j(x)$.
- $s(x)=\nabla p(x)/p(x)=\sum_j[w_jp_j(x)/p(x)]\,\nabla\log p_j(x)$.
- Set $r_j(x)=w_jp_j(x)/p(x)$ to obtain $s(x)=\sum_jr_j(x)s_j(x)$.
DL §3.9.6; course derivation · Goodfellow et al. (2016)
Your turn
The score
What does a stationary point tell us?
Find s(0). Is x=0 a mode? Explain.
$$p(x)=\tfrac12\mathcal N(x;-2,1)+\tfrac12\mathcal N(x;2,1)$$
- $x$
- scalar state
- $s(x)$
- gradient of log mixture density
Check At x=0, score 0 does not imply a mode.
Solution 1 / 1
Opposing component directions cancel
At x=0, symmetry makes both responsibilities one half.
- $s_1(0)=-(0+2)=-2$, $s_2(0)=-(0-2)=2$.
- $s(0)=\tfrac12(-2)+\tfrac12(2)=0$.
- Here $p^{\prime\prime}(0)=3\mathcal N(0;2,1)>0$: zero is a local density minimum.
DL §3.9.6; course exercise · Goodfellow et al. (2016)
Your turn
The score
Transfer: doubling standard deviation
Compare standard deviations 1 and 2. Compute both scores.
$$\mu=1,\quad x=3,\quad s(x)=-(x-\mu)/v$$
- $v$
- variance
- $\sqrt v$
- standard deviation
Check Doubling standard deviation divides the score by four.
Solution 1 / 1
Convert spread into variance
The displacement x-mu equals 2 in both models.
- First: $v=1^2=1$, so $s(3)=-2$.
- Second: $v=2^2=4$, so $s(3)=-2/4=-0.5$.
- The wider log density changes less sharply at the same displacement.
DL §3.9.3; course exercise · Goodfellow et al. (2016)
Setup
Learning to denoise
Known corruption gives a target for every example
$$(x_0,k,\epsilon)\longmapsto\big((x_k,k),\epsilon\big)$$
- $x_k=\alpha_kx_0+\sigma_k\epsilon$
- network input
- $\epsilon$
- supervised target
- $k$
- sampled noise level
DDPM Algorithm 1 · Ho, Jain & Abbeel (2020)
Definition
Learning to denoise
The simple noise-prediction objective
$$L(\theta)=\E\|\epsilon_\theta(\alpha_kx_0+\sigma_k\epsilon,k)-\epsilon\|^2$$
- $\theta$
- trainable network parameters
- $\epsilon_\theta\in\mathbb R^d$
- predicted noise
- $\E$
- average over data, uniform k, and noise
DDPM §3.4, Eq.14 · Ho, Jain & Abbeel (2020)
Derivation
Learning to denoise
The optimal predictor is a conditional mean
$$\E[\|\epsilon-g\|^2\mid x_k,k]=\E[\|\epsilon-m\|^2\mid x_k,k]+\|g-m\|^2$$
- $m=\E[\epsilon\mid x_k,k]$
- conditional mean
- $g\in\mathbb R^d$
- chosen prediction
Return to the result and check its symbols and assumptions.
Derivation 1 / 1
Separate conditional mean from unexplained noise
Condition on x_k and k. Let m=E[epsilon|x_k,k], with finite conditional second moment.
- $\epsilon-g=(\epsilon-m)+(m-g)$.
- $\E[(\epsilon-m)^T(m-g)\mid x_k,k]=0$.
- $\E[\|\epsilon-g\|^2\mid x_k,k]=\E[\|\epsilon-m\|^2\mid x_k,k]+\|g-m\|^2$.
- Only the last term depends on g, so $g^*=m$.
DDPM Eq.14; course least-squares derivation · Ho, Jain & Abbeel (2020)
Derivation
Learning to denoise
One clean example has an accessible conditional score
$$\nabla_x\log q_k(x\mid x_0)=-\frac{x-\alpha_kx_0}{\sigma_k^2}=-\frac{\epsilon}{\sigma_k}$$
- $x=\alpha_kx_0+\sigma_k\epsilon$
- corrupted realization
- $x_0,k$
- fixed; sigma_k > 0
Vincent (2011), §4; DDPM §3.2 · Ho, Jain & Abbeel (2020) · Vincent (2011)
Derivation
Learning to denoise
Average conditional scores to obtain the score
$$\nabla_x\log p_k(x)=\int p(x_0\mid x)\nabla_x\log q_k(x\mid x_0)\,dx_0$$
- $p_k$
- noisy marginal density; k fixed
- $p(x_0\mid x)$
- posterior over clean data
- $Assumption$
- differentiate under the integral
Return to the result and check its symbols and assumptions.
Derivation 1 / 2
Differentiate the noisy marginal density
q_k(x|x0) is the Gaussian corruption density; p0 is the clean-data density; k is fixed.
- $p_k(x)=\int p_0(x_0)q_k(x\mid x_0)\,dx_0$.
- $\nabla_xp_k(x)=\int p_0(x_0)\nabla_xq_k(x\mid x_0)\,dx_0$.
- The second equality assumes the derivative can pass under the integral.
Derivation 2 / 2
Divide by the marginal and apply Bayes rule
Assume p_k(x)>0. The posterior is p(x0|x)=p0(x0)q_k(x|x0)/p_k(x).
- $\nabla_x\log p_k(x)=\int \frac{p_0(x_0)q_k(x\mid x_0)}{p_k(x)}\frac{\nabla_xq_k(x\mid x_0)}{q_k(x\mid x_0)}\,dx_0$.
- $s_k(x)=\E[\nabla_x\log q_k(x\mid X_0)\mid X_k=x]$.
- For discrete clean support, replace the integrals by sums.
Vincent (2011), §4 · Vincent (2011)
Your turn
Learning to denoise
Noise prediction gives a score estimate
Explain the minus sign and the factor 1/σ_k.
$$s_k(x)=-\frac{\E[\epsilon\mid x_k=x,k]}{\sigma_k}\approx-\frac{\epsilon_\theta(x,k)}{\sigma_k}$$
- $s_k$
- marginal noisy-data score
- $\sigma_k>0$
- noise standard deviation
Check $s_\theta=-\epsilon_\theta/\sigma_k$.
Solution 1 / 2
Join regression to the score identity
At a fixed level, sigma_k is a positive constant.
- $\nabla\log q_k=-\epsilon/\sigma_k$.
- $s_k=\E[\nabla\log q_k\mid x_k]= -\E[\epsilon\mid x_k]/\sigma_k$.
- The MSE optimum is $\epsilon_\theta^*=\E[\epsilon\mid x_k]$.
Solution 2 / 2
Noise regression is a form of denoising score matching
At fixed k, set s_theta=−epsilon_theta/sigma and c=∇log q_k=−epsilon/sigma.
- $\E\|\epsilon_\theta-\epsilon\|^2=\sigma_k^2\E\|s_\theta-c\|^2$.
- $\E\|s_\theta-c\|^2=\E\|s_\theta-s_k\|^2+C_k$.
- Here C_k is the conditional target variance, independent of theta. Positive weights across k preserve the population optimum at each level.
DDPM §3.2; Vincent (2011) §4 · Ho, Jain & Abbeel (2020) · Vincent (2011)
Worked example
Learning to denoise
Worked example: noise prediction becomes a score
$$\sigma_k=0.6,\quad\epsilon_\theta(x,k)=\begin{bmatrix}-0.3\\0.6\end{bmatrix}$$
- $\epsilon_\theta$
- network prediction
- $s_\theta=-\epsilon_\theta/\sigma_k$
- score estimate
DDPM §3.2; course example · Ho, Jain & Abbeel (2020)
Your turn
Learning to denoise
What can a zero noise prediction mean?
Find the noise for each clean hypothesis, then its mean.
$$X_0\in\{-1,1\},\quad\alpha=\sigma=1/\sqrt2,\quad X_k=0$$
- $X_0$
- two equally likely clean values
- $\epsilon$
- noise conditioned on X_k=0
Check Zero conditional mean can average nonzero noises.
Solution 1 / 1
Two explanations of one input
The symmetric likelihoods give equal posterior weights.
- If $X_0=1$, then $0=(1+\epsilon)/\sqrt2$, so $\epsilon=-1$.
- If $X_0=-1$, the required noise is $\epsilon=1$.
- $\E[\epsilon\mid X_k=0]=(-1+1)/2=0$.
DDPM Eq.14; course exercise · Ho, Jain & Abbeel (2020)
Result
Learning to denoise
A denoising identity gives the posterior mean
$$\E[X_0\mid x_k=x]=\frac{x+\sigma_k^2s_k(x)}{\alpha_k}$$
- $\alpha_k>0,\sigma_k>0$
- fixed coefficients
- $s_k$
- true marginal score
Return to the result and check its symbols and assumptions.
Derivation 1 / 2
Invert the known corruption algebraically
X_k=alpha X0+sigma epsilon, with positive alpha and sigma. Condition on X_k=x.
- $X_0=(x-\sigma\epsilon)/\alpha$.
- $\E[X_0\mid X_k=x]=(x-\sigma\E[\epsilon\mid X_k=x])/\alpha$.
- The observed x is fixed inside this conditional expectation.
Derivation 2 / 2
Substitute the noise-score relation
The exact marginal score obeys E[epsilon|X_k=x]=−sigma s_k(x).
- $\E[X_0\mid x]=(x-\sigma[-\sigma s_k(x)])/\alpha$.
- $\E[X_0\mid x]=(x+\sigma^2s_k(x))/\alpha$.
- This is a posterior mean, not a random sample or a guaranteed mode.
Efron (2011), Eq.1.4; scaled Tweedie identity · Efron (2011)
Worked example
Learning to denoise
Worked example: two equivalent denoising routes
$$x=1.3,\quad\alpha=0.8,\quad\sigma=0.6,\quad\epsilon_\theta=-0.5$$
- $\hat x_0$
- network-based clean estimate
- $s_\theta=-\epsilon_\theta/\sigma$
- score estimate
DDPM Eq.11; Efron Eq.1.4; course example · Ho, Jain & Abbeel (2020) · Efron (2011)
Your turn
Learning to denoise
How does predictor error reach the clean estimate?
Find Δx̂₀. Compare α=0.8 and α=0.1, with σ²=1−α².
$$\hat x_0=\frac{x-\sigma\hat\epsilon}{\alpha},\quad\hat\epsilon=\epsilon^*+\delta$$
- $\epsilon^*$
- optimal mean-noise predictor
- $\delta$
- prediction error; alpha > 0
Check $\Delta\hat x_0=-(\sigma/\alpha)\delta$.
Solution 1 / 1
Subtract the two estimates
Both estimates use the same x, alpha and sigma.
- $\Delta\hat x_0=[x-\sigma(\epsilon^*+\delta)]/\alpha-[x-\sigma\epsilon^*]/\alpha$.
- $\Delta\hat x_0=-(\sigma/\alpha)\delta$.
- At $\alpha=0.8$, the factor is $0.75$; at $\alpha=0.1$, it is $\sqrt{0.99}/0.1\approx9.95$.
DDPM Eq.11; course exercise · Ho, Jain & Abbeel (2020)
Algorithm
Learning to denoise
Training updates weights, not the noisy input
Sample x₀, k, ε → form xₖ → predict ε → average squared error → update θ.
DDPM Algorithm 1 · Ho, Jain & Abbeel (2020)
Your turn
Learning to denoise
Checkpoint: trace an input to a score
Data → known corruption → noise regression → score
Which quantity is sampled, observed, and learned?
Check Training learns a conditional mean noise field.
Solution 1 / 1
Connect the four objects
At one training level, alpha and sigma are fixed.
- $x_0\sim p_0$, $\epsilon\sim\mathcal N(0,I)$, then $x=\alpha x_0+\sigma\epsilon$.
- Input $(x,k)$; target $\epsilon$; population optimum $\E[\epsilon\mid x,k]$.
- $s_k(x)=-\E[\epsilon\mid x,k]/\sigma$.
DDPM Algorithms 1–2; Vincent (2011) §4 · Ho, Jain & Abbeel (2020) · Vincent (2011)
Setup
Reverse sampling
The reverse step needs a conditional distribution
$$q(x_{k-1}\mid x_k,x_0)\propto q(x_k\mid x_{k-1})q(x_{k-1}\mid x_0)$$
- $x_0,x_k$
- temporarily known endpoints
- $x_{k-1}$
- unknown intermediate state; k > 1
DDPM §2, Eqs.6–7 · Ho, Jain & Abbeel (2020)
Derivation
Reverse sampling
The Gaussian product adds two quadratic penalties
$$-2\log q(y\mid x_k,x_0)=\frac{\|y-\alpha_{k-1}x_0\|^2}{\sigma_{k-1}^2}+\frac{\|x_k-\sqrt{a_k}y\|^2}{\beta_k}+C$$
- $y=x_{k-1}$
- unknown vector; k > 1
- $a_k=1-\beta_k$
- one-step retention
- $C$
- constant in y
DDPM Appendix A, posterior derivation · Ho, Jain & Abbeel (2020)
Derivation
Reverse sampling
Complete the square to identify mean and variance
$$\Lambda=\frac1{\sigma_{k-1}^2}+\frac{a_k}{\beta_k},\quad h=\frac{\alpha_{k-1}x_0}{\sigma_{k-1}^2}+\frac{\sqrt{a_k}x_k}{\beta_k}$$
- $\Lambda I$
- posterior precision
- $h$
- linear coefficient vector
- $\tilde\beta=1/\Lambda,\ \tilde\mu=h/\Lambda$
- variance and mean
Return to the result and check its symbols and assumptions.
Derivation 1 / 2
Expand and collect terms in the unknown state
y=x_{k−1}; both x0 and x_k are fixed. Previous variance sigma² is positive.
- $\Lambda=1/\sigma_{k-1}^2+a_k/\beta_k$.
- $h=\alpha_{k-1}x_0/\sigma_{k-1}^2+\sqrt{a_k}x_k/\beta_k$.
- $-2\log q(y\mid x_k,x_0)=\Lambda\|y\|^2-2h^Ty+C$.
Derivation 2 / 2
Complete the square and read the Gaussian
Lambda is a positive scalar precision; h is a vector.
- $\Lambda\|y\|^2-2h^Ty+C=\Lambda\|y-h/\Lambda\|^2+C^\prime$.
- $\tilde\mu=h/\Lambda$, $\tilde\beta=1/\Lambda$.
- $q(y\mid x_k,x_0)=\mathcal N(y;\tilde\mu,\tilde\beta I)$.
DDPM Eqs.6–7; Appendix A · Ho, Jain & Abbeel (2020)
Result
Reverse sampling
The posterior coefficients have a closed form
$$\tilde\mu_k=c_0x_0+c_kx_k,\quad\tilde\beta_k=\frac{\beta_k(1-\bar a_{k-1})}{1-\bar a_k}$$
- $c_0=\beta_k\alpha_{k-1}/(1-\bar a_k)$
- clean coefficient
- $c_k=\sqrt{a_k}(1-\bar a_{k-1})/(1-\bar a_k)$
- noisy coefficient
Return to the result and check its symbols and assumptions.
Derivation 1 / 1
Simplify the precision denominator
a_k=1−beta_k; bar-a_k=a_k bar-a_{k−1}.
- $\Lambda=\frac{\beta_k+a_k(1-\bar a_{k-1})}{\beta_k(1-\bar a_{k-1})}$.
- $\beta_k+a_k(1-\bar a_{k-1})=1-\bar a_k$.
- $\tilde\beta_k=1/\Lambda=\beta_k(1-\bar a_{k-1})/(1-\bar a_k)$.
- $\tilde\mu_k=\tilde\beta_kh=c_0x_0+c_kx_k$.
DDPM Eq.7 · Ho, Jain & Abbeel (2020)
Derivation
Reverse sampling
Replace clean data by the learned noise estimate
$$\mu_\theta(x_k,k)=\frac1{\sqrt{a_k}}\left(x_k-\frac{\beta_k}{\sigma_k}\epsilon_\theta(x_k,k)\right)$$
- $a_k=1-\beta_k$
- one-step retention
- $\sigma_k=\sqrt{1-\bar a_k}$
- cumulative noise scale
- $\mu_\theta$
- learned reverse mean
Return to the result and check its symbols and assumptions.
Derivation 1 / 2
Insert the clean estimate into the known-clean mean
alpha_k=sqrt(a_k) alpha_{k−1}; sigma_k²=1−bar-a_k.
- $\hat x_0=(x_k-\sigma_k\hat\epsilon)/\alpha_k$.
- $\mu_\theta=\frac{\beta_k\alpha_{k-1}}{\sigma_k^2}\hat x_0+\frac{\sqrt{a_k}(1-\bar a_{k-1})}{\sigma_k^2}x_k$.
- The noise coefficient becomes $-\beta_k/(\sqrt{a_k}\sigma_k)$.
Derivation 2 / 2
Simplify the remaining state coefficient
beta_k+a_k(1−bar-a_{k−1})=sigma_k².
- Coefficient on $x_k$: $[\beta_k+a_k(1-\bar a_{k-1})]/(\sqrt{a_k}\sigma_k^2)=1/\sqrt{a_k}$.
- $\mu_\theta=(x_k-\beta_k\hat\epsilon/\sigma_k)/\sqrt{a_k}$.
- With optimal mean-noise prediction this gives the reverse conditional mean; a fixed-variance Gaussian still approximates its full law.
DDPM §3.2, Eq.11 · Ho, Jain & Abbeel (2020)
Worked example
Reverse sampling
Worked example: calculate one reverse mean
$$\beta_k=0.36,\quad a_k=0.64,\quad\sigma_k=0.8,\quad x_k=1,\quad\hat\epsilon=0.4$$
- $\hat\epsilon$
- network prediction
- $\mu_\theta$
- reverse mean to compute
DDPM Eq.11; course example · Ho, Jain & Abbeel (2020)
Your turn
Reverse sampling
A reverse draw uses a standard deviation
Compute one draw and the variance across repeated draws.
$$x_{k-1}=\mu_\theta+\sqrt{\tilde\beta_k}\,z,\quad z\sim\mathcal N(0,I)$$
- $\mu_\theta=1.025$
- reverse mean from the previous example
- $\tilde\beta_k=0.24609375,\ z=-1$
- derived posterior variance; fresh draw
Check $x_{k-1}=1.025-\sqrt{0.24609375}\approx0.5289$.
Solution 1 / 1
Continue the same forward schedule
beta=.36, a=.64, sigma_k=.8; therefore bar-a_k=.36.
- $\bar a_{k-1}=.36/.64=.5625$.
- $\tilde\beta_k=.36(1-.5625)/.64=.24609375$.
- $\sqrt{\tilde\beta_k}\approx.4960784$; $x_{k-1}=1.025-.4960784=.5289216$.
- Across fresh draws, $\operatorname{Var}(x_{k-1}\mid x_k)=.24609375$ in this Gaussian model.
DDPM Algorithm 2; course exercise · Ho, Jain & Abbeel (2020)
Algorithm
Reverse sampling
DDPM generation runs from noise to data
Draw x_K ∼ N(0,I). For k=K,…,1: predict noise; compute μθ; draw the next state. At k=1, return the continuous clean endpoint without fresh noise.
DDPM Algorithm 2; continuous-action adaptation · Ho, Jain & Abbeel (2020)
Your turn
Reverse sampling
Does a mean predictor force identical samples?
Same observation and trained weights.
Different initial Gaussian draws.
Must the final samples be identical?
Check A conditional mean field is not one fixed output.
Solution 1 / 1
Follow the whole random process
The network is deterministic at a fixed input and level.
- $X_K$ is random, so $\mu_\theta(X_K,K)$ can vary.
- For stochastic reverse steps, fresh $z_k$ adds variation.
- A conditional mean at each state does not equal the unconditional mean of every final sample.
DDPM Algorithm 2; course exercise · Ho, Jain & Abbeel (2020)
General rule
Reverse sampling
A deterministic DDIM step keeps the predicted direction
$$\hat x_0=\frac{x_k-\sigma_k\hat\epsilon}{\alpha_k},\qquad x_j=\alpha_j\hat x_0+\sigma_j\hat\epsilon$$
- $j<k$
- chosen less noisy level
- $\hat\epsilon=\epsilon_\theta(x_k,k)$
- current prediction
- $\alpha_i^2+\sigma_i^2=1$
- schedule; alpha_k > 0
DDIM §4.1, Eq.12 with eta=0 · Song, Meng & Ermon (2021)
Worked example
Reverse sampling
Worked example: skip to a cleaner level
$$x_k=1.3,\ \hat\epsilon=-0.5,\ (\alpha_k,\sigma_k)=(0.8,0.6),\ (\alpha_j,\sigma_j)=(\sqrt{0.91},0.3)$$
- $j<k$
- selected next level
- $\hat x_0$
- clean estimate
DDIM Eq.12; course example · Song, Meng & Ermon (2021)
Your turn
Reverse sampling
Transfer: check deterministic sampling at the endpoint
Compute the deterministic clean-endpoint output. Is the whole generated distribution deterministic?
$$x_k=0.9,\quad\alpha_k=0.8,\quad\sigma_k=0.6,\quad\hat\epsilon=0.5$$
- $\alpha_0=1,\sigma_0=0$
- clean endpoint
- $x_0^{\mathrm{out}}$
- deterministic output to find
Check $x_0^{\mathrm{out}}=(0.9-0.6(0.5))/0.8=0.75$.
Solution 1 / 1
Set the destination to the clean endpoint
At level zero, signal coefficient is one and noise coefficient is zero.
- $\hat x_0=(0.9-0.3)/0.8=0.75$.
- $x_0^{\mathrm{out}}=1\hat x_0+0\hat\epsilon=0.75$.
- The initial random state can still differ across generation runs; no fresh endpoint noise is added.
DDIM Eq.12; course exercise · Song, Meng & Ermon (2021)
General rule
Reverse sampling
A generalized step allocates fresh randomness
$$x_j=\alpha_j\hat x_0+\sqrt{\sigma_j^2-\rho_{k,j}^2}\,\hat\epsilon+\rho_{k,j}z$$
- $z\sim\mathcal N(0,I)$
- fresh independent draw
- $\rho_{k,j}$
- chosen noise standard deviation
- $\hat x_0,\hat\epsilon$
- current clean/noise estimates
DDIM Eq.12 · Song, Meng & Ermon (2021)
Parameterization
Reverse sampling
The eta parameter selects the stochasticity
$$\rho_{k,j}=\eta\sqrt{\frac{1-\alpha_j^2}{1-\alpha_k^2}\left(1-\frac{\alpha_k^2}{\alpha_j^2}\right)}$$
- $j<k,\ 0\le\eta\le1$
- selected levels and parameter
- $\alpha_j>\alpha_k>0$
- cumulative signal coefficients
DDIM §4.1 and Appendix C.1 · Song, Meng & Ermon (2021)
Your turn
Reverse sampling
A step budget trades computation for approximation
Toy measured cost: 8 ms per network evaluation.
Compare 20 evaluations with 5.
Which claims require an experiment?
Check Model time: 160 ms vs 40 ms; quality must be measured.
Solution 1 / 1
Separate timing arithmetic from quality evidence
The hypothetical cost is 8 ms per sequential network evaluation.
- 20 evaluations: 20 × 8 = 160 ms. Five evaluations: 5 × 8 = 40 ms.
- Fixed overhead and hardware details were omitted, so these are model-only estimates.
- Equal task success does not follow from the timing calculation.
Diffusion Policy §3.4; course exercise · Chi et al. (2023/2024)
Definition
Conditioning
The action distribution depends on observations
$$s_k(x\mid o)=\nabla_x\log p_k(x\mid o)$$
- $o$
- fixed observation context
- $x$
- noisy action vector
- $s_k$
- conditional score
Diffusion Policy §2.3 · Chi et al. (2023/2024)
Architecture
Conditioning
The denoiser has three inputs and one matching output
$$\epsilon_\theta:\ (x_k,k,o)\longmapsto\hat\epsilon\in\mathbb R^d$$
- $x_k\in\mathbb R^d$
- noisy action sequence
- $k,o$
- noise level and encoded observations
Diffusion Policy §§2.3,3.1–3.2 · Chi et al. (2023/2024)
Definition
Conditioning
Classifier-free guidance combines two predictions
$$\hat\epsilon_g=\hat\epsilon_u+w(\hat\epsilon_c-\hat\epsilon_u)$$
- $\hat\epsilon_c,\hat\epsilon_u$
- conditional and null-context predictions
- $w$
- guidance scale; same x and k
Classifier-Free Guidance §3.2 · Ho & Salimans (2022)
Interpretation
Conditioning
Guidance changes the fixed-level density direction
$$s_g=(1-w)s_u+ws_c=\nabla_x\log\!\left[p_k(x)^{1-w}p_k(x\mid o)^w\right]$$
- $s_u,s_c$
- exact scores at the same level
- $w$
- guidance scale; normalizability required
Return to the result and check its symbols and assumptions.
Derivation 1 / 2
Convert the linear prediction rule into scores
Both predictions use the same positive noise scale sigma_k.
- $\hat\epsilon_g=(1-w)\hat\epsilon_u+w\hat\epsilon_c$.
- $s_g=-\hat\epsilon_g/\sigma_k=(1-w)s_u+ws_c$.
- For exact scores, $s_g=\nabla_x[(1-w)\log p_k(x)+w\log p_k(x\mid o)]$.
Derivation 2 / 2
Combine logarithms with the necessary qualification
Assume the power product can be normalized.
- $s_g=\nabla_x\log[p_k(x)^{1-w}p_k(x\mid o)^w]$.
- This is a fixed-noise-level identity. It does not alone identify the final distribution of a finite guided sampler.
- The practical scale trades conditioning strength against diversity and artifacts.
Classifier-Free Guidance §3.2; convention bridge · Ho & Salimans (2022)
Your turn
Conditioning
Transfer: calculate and interpret guidance
Compute guided noise and score for each w.
$$\hat\epsilon_u=0.2,\quad\hat\epsilon_c=-0.1,\quad\sigma_k=0.5$$
- $w=0,1,2$
- scales to compare
- $s_g=-\hat\epsilon_g/\sigma_k$
- guided score
Check w=1 gives the ordinary conditional prediction.
Solution 1 / 1
Compute the difference and apply the scale
Conditional minus unconditional noise equals -0.3.
- $w=0$: $\hat\epsilon_g=0.2$, so $s_g=-0.4$.
- $w=1$: $\hat\epsilon_g=-0.1$, so $s_g=0.2$.
- $w=2$: $\hat\epsilon_g=-0.4$, so $s_g=0.8$; this extrapolates.
Classifier-Free Guidance §3.2; course exercise · Ho & Salimans (2022)
Objects
Diffusion Policy
An action chunk is the vector being generated
$$A_r^{(0)}=\begin{bmatrix}a_r^T\\\vdots\\a_{r+H_p-1}^T\end{bmatrix}\in\mathbb R^{H_p\times d_a}$$
- $r$
- physical time
- $H_p,d_a$
- prediction horizon and action dimension
- $(0)$
- clean diffusion level
Diffusion Policy §2.3 · Chi et al. (2023/2024)
Your turn
Diffusion Policy
Three horizons serve different purposes
Count observations, predicted scalars, and executed steps.
$$H_o=2,\quad H_p=4,\quad H_a=2,\quad d_a=2$$
- $H_o$
- observations supplied
- $H_p$
- actions predicted
- $H_a$
- actions executed before replanning
Check 2 observations; 8 predicted scalars; execute 2 steps.
Solution 1 / 1
Read each horizon in its own clock
Each of four predicted actions has two components.
- Observation input: two recent observations.
- Prediction: 4 × 2 = 8 scalar components.
- Execution: apply the first two actions, then obtain new observations and replan.
Diffusion Policy §2.3; course exercise · Chi et al. (2023/2024)
Training objective
Diffusion Policy
Training pairs observations with demonstrated chunks
$$L(\theta)=\E\|\epsilon_\theta(A_r^{(k)},k,o_r)-\epsilon\|_F^2$$
- $A_r^{(k)}=\alpha_kA_r^{(0)}+\sigma_k\epsilon$
- noisy chunk
- $o_r$
- observation history
- $\epsilon$
- same-shaped Gaussian noise
Diffusion Policy §2.3, Eq.5; DDPM Eq.14 · Ho, Jain & Abbeel (2020) · Chi et al. (2023/2024)
Your turn
Diffusion Policy
A receding horizon closes the feedback loop
Observe → sample chunk → execute prefix → observe again
What happens to the unused suffix?
Check Replan using fresh observations; do not blindly replay the old suffix.
Solution 1 / 1
Close the feedback loop
The learned parameters remain fixed during deployment.
- Collect the current observation context, then denoise an initialized action chunk.
- Execute its first H_a actions using the robot controller.
- Refresh the context and generate a new chunk; the unexecuted suffix is not a commitment.
Diffusion Policy §2.3 · Chi et al. (2023/2024)
Integrated worked example
Diffusion Policy
Integrated example: a normalized two-action chunk
$$x_1=\begin{bmatrix}1.3\\-0.2\end{bmatrix},\quad\hat\epsilon=\begin{bmatrix}-0.5\\1\end{bmatrix},\quad\alpha_1=0.8,\ \sigma_1=0.6$$
- $x_1$
- two noisy normalized scalar actions
- $a=0.4+0.1x$
- conversion to target position in m
Diffusion Policy §§2.3,A.1; course example · Chi et al. (2023/2024)
Integrated worked example
Diffusion Policy
Integrated example: the final denoising step
$$\hat x_0=\frac{x_1-0.6\hat\epsilon}{0.8}=\begin{bmatrix}2\\-1\end{bmatrix}$$
- $x_1=(1.3,-0.2)^T$
- noisy chunk
- $\hat\epsilon=(-0.5,1)^T$
- predicted noise
DDPM Eq.11; DDIM Eq.12; course example · Ho, Jain & Abbeel (2020) · Song, Meng & Ermon (2021)
Integrated worked example
Diffusion Policy
Integrated example: restore units and execute a prefix
$$a=0.4+0.1x,\quad x=\begin{bmatrix}2\\-1\end{bmatrix}\quad\Rightarrow\quad A_r^{(0)}=\begin{bmatrix}0.6\\0.3\end{bmatrix}\mathrm m$$
- $H_p=2,H_a=1$
- predict two, execute one
- $a$
- target position; not displacement
Diffusion Policy §2.3; course example · Chi et al. (2023/2024)
Your turn
Diffusion Policy
Transfer: change execution without changing the sampler
Targets: 0.6 m, then 0.3 m. Compare H_a=1 and H_a=2. An obstacle moves after the first action: which policy can refresh its second target?
Check Shorter execution horizon refreshes policy feedback sooner.
Solution 1 / 1
Separate generation from execution
The clean predicted chunk and sampler are unchanged.
- $H_a=1$: execute 0.6 m target, observe, then regenerate the next target.
- $H_a=2$: execute both planned targets before the policy replans.
- The first policy can incorporate the new observation earlier; neither horizon alone guarantees safety.
Diffusion Policy §2.3; course exercise · Chi et al. (2023/2024)
Your turn
Diffusion Policy
A low denoising loss is not a deployment certificate
Training metric: noise-prediction error.
Deployment question: does the closed-loop task succeed?
Give two missing checks.
Check Validate the entire observation-to-action loop.
Solution 1 / 1
Trace the gap to the physical task
Noise loss is a surrogate measured on a specified data distribution.
- New observations can lie outside that distribution; evaluate held-out environments.
- Wrong units, action alignment, controller tracking or latency can break an otherwise correct denoiser.
- Measure closed-loop success and uncertainty; sampling plausible actions alone does not enforce all constraints.
Diffusion Policy §§5,9; course exercise · Chi et al. (2023/2024)