AI Hero Club

Diffusion Models and Flow Matching · Lesson 4

Marked Complete by You0 / 8

Saved in this browser only. Marking a lesson complete does not mean the project has passed verification.

Lesson Outline 9 subsections
Course Contents 8 lessons
Full course plan.
Diffusion Models and Flow Matching / Learning Plan ↗

LESSON 04 / 8Suggested study 180 minutes

Scores, Denoising Identities and Probability-flow ODEs

Why does the same density evolution use a score coefficient of one-half in the probability-flow ODE and one in the reverse SDE?

3 Questions for This Lesson
  • The following is the average of score's after-effects versus average noise.
  • Density Evolution From Test Function Expanding
  • Check the direction and coefficient of the reverse SDE versus the probabilities streamODE
Course Project ZIP ↓

Task: Distinguish the Density Gradient, Mean Denoising, and Stochastic Reverse Drift

This chapter has a continuous time rr A positive process from data to noise, and a flow from noise to data from the next chapter tt Different. For a strict and moderate density pr(x)p_r(x), define score as sr(x)=∇xlog⁡pr(x)s_r(x)=\nabla_x\log p_r(x), that is, a logarithmic density gradient for space coordinates. It gives the fastest-growing direction for local densities, not for sample mass ratings, nor for probability itself. Different densities vary at different times, so score in the same position also depends on time.

Let's just think about the noise. Xr=arZ+σrϵX_r=a_r Z+\sigma_r\epsilon of which ZZ For clean data, ϵ\epsilon For stand-alone standard normal, bar ara_r and σr\sigma_r Known and Current σr>0\sigma_r>0. The fixed clean value zz After which the conditions density is mean arza_rz The co-op. σr2I\sigma_r^2I Gaussian. For the second item of its logarithm, the condition is negative score divided by the variance, i.e. −(x−arz)/σr2-(x-a_rz)/\sigma_r^2 and equals −ϵ/σr-\epsilon/\sigma_r 。

1. Why Conditional Supervision Can Learn the Marginal Score

The margin density is a fraction of the distribution of the conditions density to the clean data. Assuming that the fractions and the fractions are exchanged, then the gradient is drawn on the fraction and divided by the marginal density. By multiplying each by the same condition density, clean data is observed. xx The later weights. The edge score is then equal to the after-check average of the condition score, rather than the non-entitlement of all clean sample conditions score. This reasoning explains both denomination and indicates that estimation at low density points may be influenced by the lack of a sample.

sr(x)=E[−ϵσr | Xr=x],E[Z∣Xr=x]=x+σr2sr(x)ars_r(x)=\mathbb E\left[-\frac{\epsilon}{\sigma_r}\,\middle|\,X_r=x\right],\qquad \mathbb E[Z\mid X_r=x]=\frac{x+\sigma_r^2s_r(x)}{a_r}
The noise on the right also requires a_r 0; it returns the mean value and does not guarantee that it is a real center.

The second option simply takes the original noise-relations to the current point and replaces the noise mean with the first. If a function is trained by square error to approach the score label, the desired orthographic projection nature ensures the ideal optimal score. The actual network may have capacity and optimization errors, and the average training error is small and does not guarantee the accuracy of all space locations; in particular, sampling tracks are accumulated when they enter an area where training coverage is insufficient.

Divide when using noise network arguments score σr\sigma_r It'll make score MSE equal to press 1/σr21/\sigma_r^2 Weighted noise MSE. This weight may be large near the zero noise level, even if it is undefined at the end. The weighting of different times is not an insignificant detail of realization. We use these constant equations only at internal moments of the sound; if endpoint values exist, they should be negotiated by proven limits or individual models and cannot be directed to the optimizer.

Example 1: Mean Denoising Does Not Identify the Hidden Answer

Set a moment ar=0.6a_r=0.6 The difference in noise is 0:64 and the observation value is 0:06; a known accurate score here equals negative 05. Then the mean of noise conditions is negative times negative + zero + eight times negative + zero five, which is zero + four times negative + zero five. Clean conditions are equal to zero + six and zero six equal to about zero + four, six, six, six and six.

This check only proves that the average after-check meets the mean ratio, and does not prove that the clean point actually extracted is zero point four, six, six, six. At the centre of the data for two peaks, the later average may also be located in a low density area between two modes. Direct output of this mean usually causes excessive contraction in distribution; multi-step generation requires updating the total random distribution, rather than crushing each moment into one of the most likely answers.

2. Deriving Density Evolution from a Stochastic Differential Equation

Satisfied to random process dXr=fr(Xr)dr+grdWrdX_r=f_r(X_r)dr+g_r dW_r Of which... frf_r It's a drift vector. grg_r It's a time-only metric diffusion factor. WrW_r The typical measure of a random item is the square root of the time interval, not the time spacing itself. This does not involve a state-related diffusion matrix, which requires additional dispersion items and cannot directly follow the formula in this chapter.

From Random Displacement to the Density Equation, Term by Term

The space coordinates are x, the current time is r, and short intervals are recorded as r. The diffusion factor g_r is based on time; drifting is only possible. f_r(x) You can rely on position. Assuming that the coefficient is smooth enough, that there are limited local rectangulations in the process, and that the rest of Taylor is expected to be zero after r. Brown increment meets E. [ΔW] = 0 、 E [(ΔW)²] = r; this is not to replace random items with zero because the square items will be retained. X=f_r(x) Δ r+g_r The X-W plus the high rank.

E[ΔX∣x]=fr(x)Δr+o(Δr),E[(ΔX)2∣x]=gr2Δr+o(Δr)\mathbb E[\Delta X\mid x]=f_r(x)\Delta r+o(\Delta r),\qquad \mathbb E[(\Delta X)^2\mid x]=g_r^2\Delta r+o(\Delta r)
The drift square is O(Δr²); the cross-reference between the drift and the Brown item is zero to one order, so the first step second rule leaves only g2.

Select a secondary micrometric function that is not density, but is used to observe any smoothness of random locations, such as location or position square. Expanding (x+X): a constant item (x), a regular item (x) and a second item of two parts (x) (x)2. A first expectation of the current x condition distribution, then a reduction (x), divided by r, and the limit. This limit definition is working on the function platitude of generating calculator L_r; it transforms an observation into a transient rate of change in the condition of the observation.

Lrϕ=frϕ′+gr22ϕ′′,ddrE[ϕ(Xr)]=∫pr(x)Lrϕ(x) dxL_r\phi=f_r\phi^{\prime}+\frac{g_r^2}{2}\phi^{\prime\prime},\qquad \frac{d}{dr}\mathbb E[\phi(X_r)]=\int p_r(x)L_r\phi(x)\,dx
One in two comes from Taylor's second order and does not come from optional de-noise weights.

Now move the guide from the twig to the density. [f p φ] The boundary item is zero, which can be supported by a tight or require functions to decline long enough. One segment results in f(fp); the diffuse item makes two consecutive (p), two negative numbers offset. The definition is accompanied by a density of (f_r p)(g_r2/ 2 The asterisk is right here in relation to the accumulation, not the compound.

∫pLrϕ dx=∫ϕLr∗p dx,∂rp=Lr∗p=−(frp)′+gr22p′′\int pL_r\phi\,dx=\int\phi L_r^*p\,dx,\qquad \partial_r p=L_r^*p=-(f_rp)^{\prime}+\frac{g_r^2}{2}p^{\prime\prime}
The equation is created for a sufficiently rich test function to give a weak form density equation; it can be read to the point-by-point equation when smooth.

Finally, s=p'/p, or p'=ps, writes the diffuse item as (g2/2) (ps). So the density equation becomes r p=− [p(f−g²s/2)]', which is a continuous equation for the determinative speed of removal v=f−g 2 s/2. The original random process is not the same path as ODE; they have the same one-time margin under the same conditions of initial density, de-existence and density evolution as required. The conditions of existence and singularity are explicitly imported here, rather than proving all random process theorem at a time by Taylor.

Glossy Test Functions ϕ(x)\phi(x), second-tier Taylor starts with a condition expectation. A drift gives. f⋅∇ϕf\cdot\nabla\phi The second order of the Brown Increment is given in half. g2Δϕg^2\Delta\phi; the higher order disappears after the interval of time has become zero. For the current densities, and for the fractions when the boundary item has disappeared, the guide is moved from the test function to the density, and the Fokker-Planck equation is obtained. ∇⋅\nabla\cdot is the dispersion of the vector field. Δ\Delta is the sum of the second steps of the coordinates.

∂rpr=−∇ ⁣⋅(frpr)+12gr2Δpr=−∇ ⁣⋅[(fr−12gr2sr)pr]\partial_r p_r=-\nabla\!\cdot(f_rp_r)+\tfrac12g_r^2\Delta p_r=-\nabla\!\cdot\left[\left(f_r-\tfrac12g_r^2s_r\right)p_r\right]
Use pylog p = p to write the diffuse item as the dispersion of the probability stream.

So the certainty ODE speed. vr=fr−12gr2srv_r=f_r-\tfrac12g_r^2s_r The same density continuity equation is met, with the same single moment edge in the same starting distribution and sufficient regular conditions. This is called the probabilities stream ODE. It does not mean that a single ODE track is equal to the original random trajectory or that the combined time distribution of the two processes is identical. It is possible to construct different random paths to match the edges; this course evaluates the sample distribution with concern for the margin, but it is not possible to interpret the path without any difference.

3. Reverse Time and the One-Half Factor

Expanding the Reverse Generator: Where the Full Score Comes From

The reverse time u=R−r is increased, and short-step reordered under short-step Bayesian conditions is assigned to the current position. In a positive density and sufficient regularity, the local generation of this inverse process can be written as a companion set below. This combination formula is the result of the back-of-the-time analysis imported in this section; we then complete the implementation of the fractional algebra in it, instead of treating the normal inversion of time as proven by the basic guides.

Lˉuϕ=Lr∗(prϕ)−ϕLr∗prpr,r=R−u\bar L_u\phi=\frac{L_r^*(p_r\phi)-\phi L_r^*p_r}{p_r},\qquad r=R-u
The denominator is the density of the current position; p_r>0 allows a point-by-point division.

The drifting part begins. -(fp)'=-(fp)-fp fp-fp}'. Then the spreading part: (p)=2; after subtracting, the constant density second leg disappears, leaving 2 pp' and p. Multiplies the original g2/2 factor of two is offset by half with Taylor, so that the g2p.

Lr∗(pϕ)−ϕLr∗p=(−fp+gr2p′)ϕ′+gr22pϕ′′L_r^*(p\phi)-\phi L_r^*p=(-fp+g_r^2p^{\prime})\phi^{\prime}+\frac{g_r^2}{2}p\phi^{\prime\prime}
Each missing item and the remaining cross-items are derived from arithmetic guidance; g2 cannot be mistranslated into g2/ 2 here.
Lˉuϕ=(−fr+gr2sr)ϕ′+gr22ϕ′′\bar L_u\phi=(-f_r+g_r^2s_r)\phi^{\prime}+\frac{g_r^2}{2}\phi^{\prime\prime}
In contrast to the generation of the algorithm "Floating Diffusion Square/ 2 " read reverse SDE drifting and spreading.

The reverse migration of SDE is — f+g 2s and retains proliferation g; the reverse probabilities stream ODE directly reverses to the original ODE time, drifting to — f+g 2 s/2 without the Brown item. Both can give back density, but the compensation for proliferation is different. If g relies on space, the first steps to move g2 out of range are ineffective, it adds a number of references, and the set cannot be applied.

To write the process from noise echo data, make new time u=R−ru=R-r It increases with the creation. Reverse proliferation retains its proliferation intensity and drifts to −fr+gr2sr-f_r+g_r^2s_r. The calculator can be moved short by the Bayesian: the reverse test function produces a meta-metric equal to the associated generation of a meta-metric effect prϕp_r\phi Less ϕ\phi Take it. prp_r I'm not going to be able to do that. prp_r. The drifting item gives a negative effect when the multiplier lead is expanded frf_r, La Plass cross-direction gives a whole piece gr2∇log⁡prg_r^2\nabla\log p_r The remaining proliferation generation is the same. That explains why it's not half score.

dYu=[−fR−u(Yu)+gR−u2sR−u(Yu)]du+gR−udWˉudY_u=\left[-f_{R-u}(Y_u)+g_{R-u}^2s_{R-u}(Y_u)\right]du+g_{R-u}d\bar W_u
Reverse SDE time u increases; reverse probability stream ODE takes a positive v directly and only half of score corrects.

This reasoning requires a positive density, a shift in available conditions, sufficient smoothness and no-problem boundaries. If you multiply the positive to random incremental numbers by negative numbers, you cannot get the correct conditions for the reverse Brown path; the new random noise is not the reverse of the original noise at the time of training.

Example 2: One Incorrect Coefficient Changes the Probability Flow

The current parameter for the extraction variance to maintain a positive path is f(x)=−xf(x)=-x 、 g2=2g^2=2; setting the current edge is a one-dimensional Gossic with an average value of zero, a difference of two and five points, so in x=1x=1 The negative four is the negative four. The positive-probability flow is a negative one minus one times a negative four and a negative three; the inverse ODE speed is a negative three. The reverse drift is a negative seven to one plus two times a negative four, plus a new noise from root two of the diffusion coefficient. Negative three is not inconsistent with negative seven. They describe different processes.

The independent examination of the deviation guide: The difference rate is two times two times two plus five plus two to one five to one five for SDE. The probability flow is three times its own in this instant, with a variation of six times two plus five, which is also one point five. Half of the score compensates for the removal of the random diffusion item in ODE. If the whole score were used on the positive path to ODE, the variance would not be matched, and this check would be more perceptive than just observing a trajectory direction.

Another very positive comparison is the standard normal smoothing process: drifting to a negative current position, spreading square two, and currently score to a negative current. The positive-probability flow is therefore zero, and density is still constant; reverse drifting to a negative current position, which is based on proliferation and contraction balances, maintains the same normal state. If half of score is misdirected to a reverse SD, drift to zero and spread still exists, with the result that it has been degraded to the Brown movement. This counter-case does not require complex data to detect a mix of ODE and SDE coefficients.

If the new coordinates are equal to a positive sign, the density is replaced by an aberration constant because of the variable, and the logarithmic gradient is divided by the score size. It is not an arbitrary vector that can be moved directly from the data unit. The original coordinates ' score gets 10 times the magnified coordinates directly used, which makes noise correction inconsistent with the variable probabilities model; standardized parameters must be saved together with networks and samplers.

The theoretical relationship and procedure check should still be divided. The project checked the score formula for this task by automatically requesting a space gradient by parsing mixed logarithm density and comparing it with the responsibility line that was independently written. It did not train the score network, did not randomly reverse the spread of images, and did not prove that any neural vector field is a gradient of a density. By writing these more powerful features, one test would go beyond the evidence provided by the actual call chain.

Standalone ProgramChecks the score lead, drift factor and variance rate.
from math import log,pi
def log_density(x):return -0.5*log(2*pi*0.25)-x*x/(2*0.25)
h=1e-5
score=(log_density(1+h)-log_density(1-h))/(2*h)
assert abs(score+4)<1e-8
f=-1;g2=2
forward_ode=f-0.5*g2*score
reverse_sde=-f+g2*score
assert abs(forward_ode-3)<1e-8
assert abs(reverse_sde+7)<1e-8
assert abs((-2*0.25+2)-6*0.25)<1e-12
print(score,forward_ode,reverse_sde)
Standalone ProgramSeparately distinguish between versions of reverse ODE, reverse SDE and intentional error coefficients using variance rates.
# 确定性计算一阶短步矩;不靠有限Monte Carlo噪声掩盖系数错误。
variance=0.25;g2=2.0;h=1e-6
# 此刻f=-x、score=-x/variance=-4x。
forward_ode=-1+g2/(2*variance)  # 3
reverse_ode=-forward_ode       # -3
reverse_sde=1-g2/variance      # -7
rate_forward=((1+h*forward_ode)**2*variance-variance)/h
rate_ode=((1+h*reverse_ode)**2*variance-variance)/h
rate_sde=((1+h*reverse_sde)**2*variance+g2*h-variance)/h
wrong_reverse_sde=1-g2/(2*variance)  # 错把一整份score减成一半
rate_wrong=((1+h*wrong_reverse_sde)**2*variance+g2*h-variance)/h
assert abs(rate_forward-1.5)<2e-5
assert abs(rate_ode+1.5)<2e-5 and abs(rate_sde+1.5)<2e-5
assert abs(rate_wrong+1.5)>1.9
print(dict(forward=rate_forward,reverse_ode=rate_ode,reverse_sde=rate_sde,wrong=rate_wrong))

Exercises and Complete Solutions

TRY IT YOURSELF

Practice a scaled Gausscore.

The density is three-dimensional, four-dimensional. In. x=1x=1 How many scores are there? Why does the unknown static constant not affect the outcome?

Hint 1
The second item relying on x in Gausslog density is written first, and constants are left aside.
Hint 2
Checks whether the symbol points to average for x-guiding re-integration; only the constant unicoded factor is zero.
Compare with the Solution
The location-related items in the density are negative “Position minus three.” squarely divided by eight. Negative guidance “Position minus three.” divided by four; replaced by one, received a positive 0.5, pointing to average three. Normalization constants remain constant and their guides are zero, so score does not need to know the constant values. This does not mean that any vector field is derived from a normalised density or that time dependency can be ignored; it is only guided by the already legal high density.

TRY IT YOURSELF

Practice two-poly mixed responsibility.

A position falls under two categories of post-test weights: 0.9 and 0. 1, while the two types of conditions are 2 and −6, respectively, for edges.

Hint 1
After observing the current x, are the two categories still possible? Do you use a priori or a later test weight?
Hint 2
The weighting of scores by degree of responsibility, compared to parity and hard selection, examines the possible direction.
Compare with the Solution
Weighted by a later examination of responsibility, the margin score is zero nine times two plus one times six, and gets a point two. Direct parity is on average negative two, even in the opposite direction. Because it is not equally possible to look at this position; density search is reduced to natural weights of position depending on the density of the margin. This solution can also be reviewed using the definition of “graduation of the gradients of the conditions of density, with total density removed”.

TRY IT YOURSELF

Practice three-polle to find randomly dispersed scale error

The program uses the step length h=0.01 to write the Brown Increment into the standard normal. What is the correct randomity factor? How many times less is the error realized?

Hint 1
The variance of the Brown increment should be equal to h, and the coefficient times the difference behind Z is the square of the coefficient.
Hint 2
Separate square correctness and error coefficients, comparing the variance ratio; line scale with h can be verified separately and separately.
Compare with the Solution
The standard Brown incremental variance is equal to the time interval, so the correct coefficient is Root Zero-One, i.e. zero One; the error factor zero-one leads to the difference zero-zero-one, and the correct difference is zero-one, a hundred times the difference. If drifting is constant and random diffusion is reduced, it is another process that simulates an equation that cannot be expected of the same Fokker-Planck. “Smoother” The judgment is correct.

CHECK YOUR UNDERSTANDING

Check Your Understanding

Answer first, then open the explanation to check your reasoning. These questions help reveal gaps in understanding; independent implementation and transfer require separate evaluation.

1. score guides to which variable?

Show ExplanationDefines a spatial logarithmic density gradient.
2. What's the probability stream of ODE like the original SDE?

Show ExplanationPaths and combined time distributions are generally different.
3. Reverse SDDE score factor in the increased generation time?

Show ExplanationDrifting is — f+g 2score and cannot be confused with the reverse ODE.
4. Think zero can directly score?

Show ExplanationThe exception to zero is not a matter of numerical accuracy, but of formulae defining domains.

Manual completion records your progress; it does not certify your project.