Introduction
In this part we’ll discuss a bit of operator theory, but in general this part is to connect what we’ve seen in the last part to the overall family of generative (diffusion) models.
Recap from Lecture 6
As always, recall our definition of the SDE,
d x ( t ) = f ( x ( t ) , t ) d t ⏟ drift + L ( x ( t ) , t ) d β ( t ) ⏟ diffusion . dx(t) = \underbrace{f(x(t), t) \ dt}_{\text{drift}} + \underbrace{L(x(t), t) \ d\beta(t)}_{\text{diffusion}}. d x ( t ) = drift f ( x ( t ) , t ) d t + diffusion L ( x ( t ) , t ) d β ( t ) .
We defined the h h h -transform as,
h ( x ( s ) , s ) p ( x ( T ) ∣ x ( s ) ) ∣ x ( T ) = v ∈ R x ( s ) ∈ R . h(x(s), s) p(x(T) | x(s)) \biggr\vert_{\substack{x(T) = v \in \mathbb{R} \newline x(s) \in \mathbb{R}}}. h ( x ( s ) , s ) p ( x ( T ) ∣ x ( s )) x ( T ) = v ∈ R x ( s ) ∈ R .
Which has an important property, namely,
∫ p ( x ( T ) ∣ x ( s ) ) h ( x ( t ) , t ) d x ( t ) = h ( x ( s ) , s ) , \int p(x(T) | x(s)) h(x(t), t) dx(t) = h(x(s), s), ∫ p ( x ( T ) ∣ x ( s )) h ( x ( t ) , t ) d x ( t ) = h ( x ( s ) , s ) ,
a martingale property.
We also defined the transition density ,
p ⋆ ( x ( t ) ∣ x ( s ) ) = p ( x ( t ) ∣ x ( s ) ) h ( x ( t ) , t ) h ( x ( s ) , s ) , p^{\star}(x(t) | x(s)) = \frac{p(x(t) | x(s)) h(x(t), t)}{h(x(s), s)}, p ⋆ ( x ( t ) ∣ x ( s )) = h ( x ( s ) , s ) p ( x ( t ) ∣ x ( s )) h ( x ( t ) , t ) ,
which in fact uses the h h h -transform.
Further, we saw how the conditional process took use of the h h h -transform (bridge to v v v at time T T T ),
Brownian motion forced to a point at time
Then we defined the A A A operator,
g ( x ) ↦ ( A g ) ( x ) = f ( x ) g ′ ( x ) + 1 2 L 2 ( x ) g ′ ′ ( x ) , g(x) \mapsto (Ag)(x) = f(x) g^{\prime}(x) + \frac{1}{2} L^2(x) g^{\prime\prime}(x), g ( x ) ↦ ( A g ) ( x ) = f ( x ) g ′ ( x ) + 2 1 L 2 ( x ) g ′′ ( x ) ,
If g ( s , x ) g(s, x) g ( s , x ) depends on time and state/space,
∂ ∂ s g ( s , x ) + ( A g ) ( s , x ) = 0. \frac{\partial}{\partial s} g(s, x) + (Ag)(s, x) = 0. ∂ s ∂ g ( s , x ) + ( A g ) ( s , x ) = 0.
An Important Definition and Observation
Now, take h T ( x ) h_T(x) h T ( x ) and define,
h ( s , x ) = ∫ p ( x ( T ) ∣ x ( s ) ) h T ( x ( T ) ) d x ( T ) , h(s, x) = \int p(x(T) | x(s)) h_T(x(T)) \ dx(T), h ( s , x ) = ∫ p ( x ( T ) ∣ x ( s )) h T ( x ( T )) d x ( T ) ,
Here, we can make an important observation, namely,
∫ p ( x ( t ) ∣ x ( s ) ) h ( x ( t ) , t ) d x ( t ) = ∫ p ( x ( t ) ∣ x ( s ) ) ( ∫ p ( x ( T ) ∣ x ( s ) ) h T ( x ( T ) ) d x ( T ) ) d x ( t ) = C.K ∫ p ( x ( T ) ∣ x ( s ) ) h T ( x ( T ) ) d x ( T ) . \begin{align*}
\int p(x(t) | x(s)) h(x(t), t) \ dx(t) & = \int p(x(t) | x(s)) \left( \int p(x(T) | x(s)) h_T(x(T)) d x(T) \right) d x(t) \newline
& \overset{\text{C.K}}{=} \int p(x(T) | x(s)) h_T(x(T)) d x(T).
\end{align*} ∫ p ( x ( t ) ∣ x ( s )) h ( x ( t ) , t ) d x ( t ) = ∫ p ( x ( t ) ∣ x ( s )) ( ∫ p ( x ( T ) ∣ x ( s )) h T ( x ( T )) d x ( T ) ) d x ( t ) = C.K ∫ p ( x ( T ) ∣ x ( s )) h T ( x ( T )) d x ( T ) .
For each h T ( x ) h_T(x) h T ( x ) we get a process like in Equation (1) , with transition density p ⋆ ( x ( t ) ∣ x ( s ) ) p^{\star}(x(t) | x(s)) p ⋆ ( x ( t ) ∣ x ( s )) .
If x ( 0 ) = x 0 ∈ R x(0) = x_0 \in \mathbb{R} x ( 0 ) = x 0 ∈ R (deterministically), then x ⋆ ( T ) x^{\star}(T) x ⋆ ( T ) has density,
p ⋆ ( x ( T ) ∣ x ( 0 ) ) = p ( x ( T ) ∣ x ( 0 ) ) h T ( x ( T ) ) h ( x ( 0 ) , 0 ) p^{\star}(x(T) | x(0)) = \frac{p(x(T) | x(0)) h_T(x(T))}{h(x(0), 0)} p ⋆ ( x ( T ) ∣ x ( 0 )) = h ( x ( 0 ) , 0 ) p ( x ( T ) ∣ x ( 0 )) h T ( x ( T ))
Thus, if we want to sample from a density π ( x ( T ) ) \pi(x(T)) π ( x ( T )) ,
p ( x ( T ) ∣ x ( 0 ) ) h T ( x ( T ) ) h ( x ( 0 ) , 0 ) = π ( x ( T ) ) h T ( x ( T ) ) = C ⋅ π ( x ( T ) ) p ( x ( T ) ∣ x ( 0 ) ) \begin{align*}
\frac{p(x(T) | x(0)) h_T(x(T))}{h(x(0), 0)} & = \pi(x(T)) \newline
h_T(x(T)) & = C \cdot \frac{\pi(x(T))}{p(x(T) | x(0))}
\end{align*} h ( x ( 0 ) , 0 ) p ( x ( T ) ∣ x ( 0 )) h T ( x ( T )) h T ( x ( T )) = π ( x ( T )) = C ⋅ p ( x ( T ) ∣ x ( 0 )) π ( x ( T ))
so, if you give me the data density π ( x ( T ) ) \pi(x(T)) π ( x ( T )) , we can obtain h ( s , x ) h(s, x) h ( s , x ) (or the smarter choice is ∇ log h ( s , x ) \nabla \log h(s, x) ∇ log h ( s , x ) , but we’ll come to this.)
Remark 1 Note that our generative model runs forward in time here, one can also reverse the time.
Example 1 x ( t ) x(t) x ( t ) is a Brownian motion,
d x ( t ) = 0 d t ⏟ f + 1 d β ( t ) ⏟ L , x ( 0 ) = 0. dx(t) = \underbrace{0 \ dt}_{f} + \underbrace{1 \ d\beta(t)}_{L}, \quad x(0) = 0. d x ( t ) = f 0 d t + L 1 d β ( t ) , x ( 0 ) = 0. Assume that π \pi π is given, and our end time is T = 1 T = 1 T = 1 .
Thus,
h ( x ( 1 ) ) = C ⋅ π ( x ( 1 ) ) p ( x ( 1 ) ∣ x ( 0 ) ) = C ~ ⋅ π ( x ( 1 ) ) e − x ( 1 ) ) 2 2 \begin{align*}
h(x(1)) & = C \cdot \frac{\pi(x(1))}{p(x(1) | x(0))} \newline
& = \tilde{C} \cdot \frac{\pi(x(1))}{e^{-\frac{x(1))^2}{2}}}
\end{align*} h ( x ( 1 )) = C ⋅ p ( x ( 1 ) ∣ x ( 0 )) π ( x ( 1 )) = C ~ ⋅ e − 2 x ( 1 ) ) 2 π ( x ( 1 )) Which means the h h h -transform is,
h ( s , x ) = C ~ ∫ p ( x ( 1 ) ∣ x ( s ) ) π ( x ( 1 ) ) e − x ( 1 ) 2 2 d x ( 1 ) = C ~ ~ ∫ e − 1 2 ( x ( 1 ) − x ( s ) ) 2 1 − s + x ( 1 ) 2 2 π ( x ( 1 ) ) d x ( 1 ) \begin{align*}
h(s, x) & = \tilde{C} \int p(x(1) | x(s)) \frac{\pi(x(1))}{e^{-\frac{x(1)^2}{2}}} \ dx(1) \newline
& = \tilde{\tilde{C}} \int e^{-\frac{1}{2} \frac{(x(1) - x(s))^2}{1 - s} + \frac{x(1)^2}{2}} \pi(x(1)) \ dx(1) \newline
\end{align*} h ( s , x ) = C ~ ∫ p ( x ( 1 ) ∣ x ( s )) e − 2 x ( 1 ) 2 π ( x ( 1 )) d x ( 1 ) = C ~ ~ ∫ e − 2 1 1 − s ( x ( 1 ) − x ( s ) ) 2 + 2 x ( 1 ) 2 π ( x ( 1 )) d x ( 1 ) Which we can write as an expectation,
= C ~ ~ ⋅ E [ e − 1 2 ( x ( 1 ) − x ( s ) ) 2 1 − s + x ( 1 ) 2 2 ] . = \tilde{\tilde{C}} \cdot \mathbb{E} \left[ e^{-\frac{1}{2} \frac{(x(1) - x(s))^2}{1 - s} + \frac{x(1)^2}{2}} \right]. = C ~ ~ ⋅ E [ e − 2 1 1 − s ( x ( 1 ) − x ( s ) ) 2 + 2 x ( 1 ) 2 ] . This is useful if we don’t have π \pi π , but have samples, x 1 ∼ D x_1 \sim \mathcal{D} x 1 ∼ D .
Note If x ( t ) x(t) x ( t ) is a Brownian motion and π ( x ( T ) ) \pi(x(T)) π ( x ( T )) is given, then,
∇ log h ( x ( s ) , s ) = … = E x ( T ) ∼ p x ( T ) ∣ x ( s ) [ x ( T ) − x ( s ) T − s ] , \nabla \log h(x(s), s) = \ldots = \mathbb{E}_{x(T) \sim p^{x(T) | x(s)}} \left[ \frac{x(T) - x(s)}{T - s} \right], ∇ log h ( x ( s ) , s ) = … = E x ( T ) ∼ p x ( T ) ∣ x ( s ) [ T − s x ( T ) − x ( s ) ] , seems familiar? ;)
Score Matching
Recall that the “score” is defined as,
s ( x ( t ) , t ) = ∇ x log h ( x ( t ) , t ) . s(x(t), t) = \nabla_x \log h(x(t), t). s ( x ( t ) , t ) = ∇ x log h ( x ( t ) , t ) .
Note If we take the integral over the h h h -transformed process,
∫ h ( x ( t ) , t ) d x ( t ) ≠ 1 , \int h(x(t), t) \ dx(t) \neq 1, ∫ h ( x ( t ) , t ) d x ( t ) = 1 , but instead,
∫ h ( x ( t ) , t ) d x ( t ) = C ∈ R . \int h(x(t), t) \ dx(t) = C \in \mathbb{R}. ∫ h ( x ( t ) , t ) d x ( t ) = C ∈ R . Thus, the h h h -transform is not a probability, but likelihood [^1].
Which means, that if we normalize the h h h -transform, we get a probability density function,
h ( x ( t ) , t ) ∫ h ( u , t ) d u . \frac{h(x(t), t)}{\int h(u, t) d u}. ∫ h ( u , t ) d u h ( x ( t ) , t ) .
Score matching learns the score from (weighted) samples of,
q ( x ) = h ( x ( t ) , t ) ∫ h ( u , t ) d u q(x) = \frac{h(x(t), t)}{\int h(u, t) d u} q ( x ) = ∫ h ( u , t ) d u h ( x ( t ) , t )
Vanilla score matching (Hyvärinen, 2005) 1 ,
Take nueral netowrk approximation, s ^ θ ( x ( t ) , t ) ≈ s ( x ( t ) , t ) \hat{s}_{\theta}(x(t), t) \approx s(x(t), t) s ^ θ ( x ( t ) , t ) ≈ s ( x ( t ) , t ) .
Train with,
min θ ∫ 0 T ∫ q ( x ( t ) , t ) ∑ i = 0 d S i d x ( t ) d t , x ∈ R d , \underset{\theta}{\min} \int_0^T \int q(x(t), t) \sum_{i = 0}^d S_i \ dx(t) dt, \quad x \in \mathbb{R}^d, θ min ∫ 0 T ∫ q ( x ( t ) , t ) i = 0 ∑ d S i d x ( t ) d t , x ∈ R d ,
where S i = ∂ ∂ x i s θ ( x ( t ) , t ) ( i ) + 1 2 s θ ( x ( t ) , t ) 2 S_i = \frac{\partial}{\partial x_i} s_{\theta}(x(t), t)^{(i)} + \frac{1}{2} s_{\theta}(x(t), t)^2 S i = ∂ x i ∂ s θ ( x ( t ) , t ) ( i ) + 2 1 s θ ( x ( t ) , t ) 2 .
Or in the scalar case,
min θ ∫ 0 T ∫ q ( x ( t ) , t ) ( s θ ′ ( x ( t ) , t ) + 1 2 s θ ( x ( t ) , t ) 2 ) d x ( t ) d t , \underset{\theta}{\min} \int_0^T \int q(x(t), t) \left(s_{\theta}^{\prime}(x(t), t) + \frac{1}{2} s_{\theta}(x(t), t)^2 \right) \ dx(t) dt, θ min ∫ 0 T ∫ q ( x ( t ) , t ) ( s θ ′ ( x ( t ) , t ) + 2 1 s θ ( x ( t ) , t ) 2 ) d x ( t ) d t ,
and again, if we only have samples,
min θ C ⋅ ∑ K ∑ L s θ ′ ( x K , L , t K ) + s θ ( x K , L , t K ) 2 , \underset{\theta}{\min} \ C \cdot \sum_K \sum_L s_{\theta}^{\prime}(x_{K, L}, t_K) + s_{\theta}(x_{K, L}, t_K)^2, θ min C ⋅ K ∑ L ∑ s θ ′ ( x K , L , t K ) + s θ ( x K , L , t K ) 2 ,
where x K , L x_{K, L} x K , L are samples from q ( t K , ⋅ ) q(t_K, \cdot) q ( t K , ⋅ ) and C = 1 , … , N C = 1, \ldots, N C = 1 , … , N .
So, we need samples from,
q ( x ( t ) , t ) = h ( x ( t ) , t ) ∫ h ( u , t ) d u . q(x(t), t) = \frac{h(x(t), t)}{\int h(u, t) d u}. q ( x ( t ) , t ) = ∫ h ( u , t ) d u h ( x ( t ) , t ) .
Luckily, Schoenmakers et al. (2013) 2 propose,
{ d y ( t ) = α ( y ( t ) , t ) d t + L ( y ( t ) ) d β ( t ) – position d y ( t ) = C ( y ( t ) , t ) y ( t ) d t – weights \begin{cases}
\begin{align*}
dy(t) & = \alpha(y(t), t) \ dt + L(y(t)) \ d \beta(t) & \text{-- position} \newline
d \mathfrak{y}(t) & = C(y(t), t) \mathfrak{y}(t) \ dt & \text{-- weights}
\end{align*}
\end{cases} { d y ( t ) d y ( t ) = α ( y ( t ) , t ) d t + L ( y ( t )) d β ( t ) = C ( y ( t ) , t ) y ( t ) d t – position – weights
We have two choices for setting up stuff,
y ( 0 ) = 1 y ( 0 ) ∼ h 0 ( x ( T ) ) ∫ h 0 ( v ) d v \begin{align*}
\mathfrak{y}(0) & = 1 \newline
y(0) & \sim \frac{h_0(x(T))}{\int h_0(v) d v}
\end{align*} y ( 0 ) y ( 0 ) = 1 ∼ ∫ h 0 ( v ) d v h 0 ( x ( T ))
y ( 0 ) ∼ π 1 y ( 0 ) = 1 p ( x ( T ) ∣ x ( 0 ) ) ∣ x ( T ) = y ( 0 ) \begin{align*}
y(0) & \sim \pi_1 \newline
\mathfrak{y}(0) & = \frac{1}{p(x(T) | x(0))} \biggr\vert_{x(T) = y(0)}
\end{align*} y ( 0 ) y ( 0 ) ∼ π 1 = p ( x ( T ) ∣ x ( 0 )) 1 x ( T ) = y ( 0 )
But the important part is that,
α ( T − t , x ) = − f ( x ( t ) , t ) + ( L 2 ) ′ ( x ( t ) , t ) C ( T − t , x ) = 1 2 ( L 2 ) ′ ′ ( x ( t ) , t ) − f ′ ′ ( x ( t ) , t ) \begin{align*}
\alpha(T - t, x) & = -f(x(t), t) + (L^2)^{\prime}(x(t), t) \newline
C(T - t, x) & = \frac{1}{2} (L^2)^{\prime\prime}(x(t), t) - f^{\prime\prime}(x(t), t)
\end{align*} α ( T − t , x ) C ( T − t , x ) = − f ( x ( t ) , t ) + ( L 2 ) ′ ( x ( t ) , t ) = 2 1 ( L 2 ) ′′ ( x ( t ) , t ) − f ′′ ( x ( t ) , t )
Example 2 For each test function g g g ,
E [ g ( y ( t ) ⋅ y ( t ) ) = ∫ g ( x ) q ( t , x ) d x . \mathbb{E}[g(y(t) \cdot \mathfrak{y}(t)) = \int g(x) q(t, x) \ dx. E [ g ( y ( t ) ⋅ y ( t )) = ∫ g ( x ) q ( t , x ) d x . Take x ( 0 ) = 0 , x ( t ) = β ( t ) x(0) = 0, x(t) = \beta(t) x ( 0 ) = 0 , x ( t ) = β ( t ) ,
{ f = 0 L = 1 ⟹ { d y ( t ) = d β ( t ) , y ( t ) = 1 L ′ = L ′ ′ = 0 \begin{cases}
\begin{align*}
f & = 0 \newline
L & = 1
\end{align*}
\end{cases} \implies
\begin{cases}
\begin{align*}
dy(t) & = d \beta(t), \quad \mathfrak{y}(t) = 1 \newline
L^{\prime} & = L^{\prime\prime} = 0
\end{align*}
\end{cases} { f L = 0 = 1 ⟹ { d y ( t ) L ′ = d β ( t ) , y ( t ) = 1 = L ′′ = 0
Score matching diffusion!
Schoenmakers score matching