AI Hero Club

Diffusion Models and Flow Matching · Lesson 5

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 05 / 8Suggested study 180 minutes

Conditional Flow Matching and Marginal Velocity Fields

Each conditional straight path has its own velocity. Why can regression on those targets recover the marginal velocity field?

3 Questions for This Lesson
  • Prove the link between return conditions and the projection of a return to marginal speed
  • Consistency equation by test function
  • Independent calculations of Gaussian mixed teachers and maintenance of sampling information boundaries
Course Project ZIP ↓

Task: Learn a Sampleable Marginal Velocity from Conditional Targets

Returning to project agreement: t=0t=0 It's a standard normal noise. t=1t=1 It's a four-dimensional target. From a separate endpoint. X0,X1X_0,X_1 Construct Xt=(1−t)X0+tX1X_t=(1-t)X_0+tX_1, the condition path of each known endpoint is U=X1−X0U=X_1-X_0. The training can draw to two endpoints, generating only access to the current state. The key to Slow Matching is not to sneak real data into the sampler, but to use these condition labels to combine a single accepted (x,t)(x,t) QuickNet vθ(x,t)v_\theta(x,t) 。

When all possible paths are mixed at the same time, multiple endpoints can pass through the same location and lead to different speeds in different directions. A function cannot produce all conditions at the same time, so a sample-by-samp training error is not considered an immediate failure to achieve it. We begin by extrapolating what average it should be able to export and then explaining why that average can handle the correct margin density. The square error returns here is not an empirical slogan, but a constant projection equation that can be verified.

1. Conditional Expectation Minimizes Squared Error

Remember margin speed v∗(x,t)=E[U∣Xt=x,t]v_*(x,t)=\mathbb E[U\mid X_t=x,t]. Any candidate function vv The error can be written as (v−v∗)+(v∗−U)(v-v_*)+(v_*-U). Two squares and a cross-section are squared; given Xt,tX_t,t After that, the first factor is the determination of quantities, while the second factor is on average zero, so the cross-sectional expectation disappears. The remaining two do not rely on the candidate network, and the condition label returns to the same ideal optimal function as the speed of direct return to unknown edges.

E∥v(Xt,t)−U∥2=E∥v(Xt,t)−v∗(Xt,t)∥2+E∥U−v∗(Xt,t)∥2\mathbb E\|v(X_t,t)-U\|^2=\mathbb E\|v(X_t,t)-v_*(X_t,t)\|^2+\mathbb E\|U-v_*(X_t,t)\|^2
The second is the speed of the condition unmatched by the coupon; the limited sample actuals need not accurately satisfy the overall decomposition on a sequential basis.

The equation does not say that the two training losses are equal, nor does it guarantee that a limited network is optimal. It also relies on time sampling and endpoint coupling: changing the weight of sampling rights or changing independent endpoints to some matching endpoint will change the return problem. The project has a flat time sampling, endpoint independence, averaged by sample and two coordinates. Trainers use margin labels directly, without calling the interpreters to update parameters; teachers provide reference only in independent validation and numerical tests, avoiding mixing learning results with artificial answers.

Example 1: Meeting Paths Need Not Be Copied Individually

At half a dimension, two probabilities are considered: first pair from negative two to positive two, condition four; second pair from positive two to negative two, condition four. Both are located in zero. If you look at this example of a discrete condition, a function that accepts only the current position and time should be exported zero at zero. Output four will leave an error of zero in the first case, 64 in the second case and an error of an average 32; output zero from a error of 16 in each case and an average loss of 16. This is precisely the smaller amount of square loss in the average speed.

This discrete example explains only the return conflict and does not cross the two atom paths to prove the global singularity of smooth ODE. The actual projects are non-zero Gaussian and internal density is smooth. The precise centre of symmetric distribution may still have zero margin velocity, but the initial noise is equal to zero probability for a point. It is asserted that the entire distribution is static without a central static, nor can it be forced to send a single stream to exactly the same initial point simultaneously to two modes.

2. From Conditional Paths to the Marginal Continuity Equation

Take any smooth and tightly supported test function ϕ(x)\phi(x). Right on the known endpoint path ϕ(Xt)\phi(X_t) Guides, chain rules give a gradient and a speed of conditions. Retrace the endpoint expectations and change the speed to an average of the conditions at the current position, and get the desired guide is equal to the right pt(x)∇ϕ(x)⋅v∗(x,t)p_t(x)\nabla\phi(x)\cdot v_*(x,t) . A continuous equation is given when a segmental component is made and the boundary item disappears. It describes the probability quality as constant, not the density values at each point.

ddtE[ϕ(Xt)]=E[∇ϕ(Xt)⋅U]=∫pt∇ϕ⋅v∗ dx⟹∂tpt=−∇⋅(ptv∗)\frac{d}{dt}\mathbb E[\phi(X_t)]=\mathbb E[\nabla\phi(X_t)\cdot U]=\int p_t\nabla\phi\cdot v_*\,dx\quad\Longrightarrow\quad\partial_t p_t=-\nabla\cdot(p_tv_*)
Under the regular conditions and the same initial density, the ODE at the margin speed of the integral recreates the edge of this probabilities path.

This step combines training with sampling: the sampler from p0p_0 Draws initial noise and uses a network of near edge speeds to one. It does not require any end-point data input, nor does it guarantee that the line that randomly pairs with the training will be restored. The margin ODE tracks will continue to bend when certain straight-line paths are mixed, as the back-check point weights of the current point change constantly. “Line” in the training is a different level of condition than “Line” in the generation.

3. Computing the Project's Analytic Velocity Teacher

Target category given K=kK=k The clean end is the center. μk\mu_k Add standard deviations σ\sigma The linear bridge is still Gaussian under this category, with an average of tμkt\mu_k, each coordinates' variance is recorded st2=(1−t)2+t2σ2s_t^2=(1-t)^2+t^2\sigma^2. The speed of the condition is recorded as the difference between the current position and the speed of the condition ct=tσ2−(1−t)c_t=t\sigma^2-(1-t). The gap is from two separate endpoints: the data noise is positive tσ2t\sigma^2, initial noise due to a negative sign contribution 1−t1-t 。

vk(x,t)=μk+ctst2(x−tμk),v∗(x,t)=∑krk(x,t)vk(x,t)v_k(x,t)=\mu_k+\frac{c_t}{s_t^2}(x-t\mu_k),\qquad v_*(x,t)=\sum_k r_k(x,t)v_k(x,t)
r_k is the degree of responsibility for the Gaussian mix at that time, multiplied by a prior weighting by the density of each fraction.

The first is the combined Gossip Girl condition average, which can be obtained by a combination of two variables with a secondary density; it takes the form of a speed mean plus a co-ordinated variance, other than the position variance multiplied by the location deviation. The second is an average for the unknown category. st2s_t^2 The formula is not used to add a small constant when it is strictly correct throughout the closed zone; when it is replaced with a zero-broad mass, the regularity of the endpoint will change and cannot be claimed that the same numerical process still has the same assurance.

Example 2: A Gaussian Bridge's Velocity Is Not Endpoint Minus Current Position

For ease of calculation, the initial distribution of one dimension is provisionally given as a standard normal state, with the goal being a two-point average, a square one, and an independent end point. At one quarter of the time, the position conditions are equal to zero five, a seven-five-square difference to zero two-two-two-five and a negative zero-five difference to all positions. The observation position is equal to one-five, and then the margin is minus two-point-five, divided by six-two-two. It is neither zero-five nor two in all locations.

At the midpoint of the same example, the difference is zero, so the speed is right at two; this is a special case where the difference is minimal and instantaneous, not the constant pace of the entire path. The endpoint can be independently checked: zero-time edge speed is targeted to reduce the current position, that is, by reducing the current position; one moment is the current position, because the initial noise is independent and equal to the known endpoint. The two endpoint limits capture the problem of the icon writing back.

Cross-Checking Scores and Velocities on the Same Linear Bridge

Chapter IV and this chapter use different time directions to explain the two generation methods. Xt=(1−t)X0+tX1 Contact them: X0 is independent standard normal and X1 is data. At fixed X1, the average Xt condition value is tX1, and the noise standard difference is tX1. 1−t So the conditions of the internal moment are-- [x−tX1] /( 1−t) 2; due to disability equal to () 1−t)X0 Average after-the-test s_t(x) =− E [X0|Xt=x] /( 1−t). The score here is the density gradient of the bridge at the moment. It is not directly replaced by the network of chapter IV arbitrary r calendars.

(1−t)E[X0∣x]+tE[X1∣x]=x,E[X0∣x]=−(1−t)st(x)(1-t)\mathbb E[X_0\mid x]+t\mathbb E[X_1\mid x]=x,\quad \mathbb E[X_0\mid x]=-(1-t)s_t(x)
The first is derived from the constant equivalent of conditionality expectations after the given Xt; the second is from the Goscore.

Use first-style E. [X1|x] And a little less E. [X0|x] Get the edge speed. Write E first. [X1|x] = [x−(1−t)E[X0|x] ]]/t; minus two, E [X0|x] The overall coefficient is - [(1−t)/t+1] =− 1/t. The score is the bottom. Each coefficient is derived from the actual path; it is changed to another. a(t) 、 b(t) or when the endpoint is coupled, the guidance is re-orientated to the average condition and cannot be re-labeled only to the time label of the sub.

v∗(x,t)=E[X1−X0∣Xt=x]=x+(1−t)st(x)t,0<t<1v_*(x,t)=\mathbb E[X_1-X_0\mid X_t=x]=\frac{x+(1-t)s_t(x)}{t},\qquad 0<t<1
This is not a description of FM training as a score network, but rather as a constant relationship between the two resolution amounts on the same path.

I'm sorry. I'm sorry. X1 ~ N(2,1) 。 t=.25 Mean time. 5 The difference. 625;observation x=1.5 , score=−(1.5−.5)/.625 =− 1.6, so speed is... [1.5+.75×(−1.6)] /. 25=1.2 The same speed as the previous joint Gossian conditions. t=.5 Organisation score=−(1.5−1)/.5 =− 1, Speed [1.5+.5×(−1)] /. 5=2. Two moments cannot share the same scoret.

Do not divide t=0 directly by zero. The molecules in the exact model are synchronized to zero, but the floating point score error is likely to be more unstable (1−t)/t magnified; this little t reconstruction is probably more volatile than the direct speed teacher. t should not jump over limits when approaching 1.

Standalone ProgramThe same path score and FM speeds are calculated independently and the error time coefficient is detected without project oracle.
import numpy as np
# 单高斯桥,独立由条件协方差计算速度,再由score重建。
for t,x in [(.25,1.5),(.5,1.5),(.8,-.7)]:
    variance=(1-t)**2+t*t
    score=-(x-2*t)/variance
    conditional_velocity=2+(2*t-1)/variance*(x-2*t)
    reconstructed=(x+(1-t)*score)/t
    assert abs(reconstructed-conditional_velocity)<1e-12
    wrong=(x+t*score)/(1-t)  # 故意把两个时间系数调换
    if t==.25:assert abs(wrong-conditional_velocity)>.1
    print(t,score,conditional_velocity,reconstructed)

4. Can the Endpoint Become the Training Target?

If you take the label from X1−X0X_1-X_0 Change it to X1−XtX_1-X_t, for the linear bridge of this class, the new label equals (1−t)(X1−X0)(1-t)(X_1-X_0). This network output is used directly as a speed component, which wrongly reduces the scale when it approaches the end point; even if it returns well, it is also deciphering another differential equation. Another parameter for predicting the end point can be designed, but must be divided by corresponding coefficients and handle end limits and restate the weight of the loss. Changing the label is not a replacement for an interface that does not need to be pushed.

Time input is not decorative. For the same space location, early noise may need to shrink and models may need to spread internally at an advanced stage; networks without time conditions can only equalize multiple tasks. The project uses time itself as well as sines and cosine as three numbers, without using a complex structure. This is a runable teaching option that does not claim best. Independent tests check that gradients enter all parameters and use real training to reduce the network to prove that it is actually updated, rather than wrapping the dissecting teacher into “Post-training model”.

The continuity equation itself does not necessarily determine the speed field. For example, standard two-dimensional normality is symmetrical and the zero-speed field can remain constant; the rotation rate “Negative Vertical Coordinates、Horizontal Coordinates” can also maintain the same density. Since the rotation speed intersects with the density gradient and its own dispersion is zero, the probability flux is still zero.

This explains why the field error requires a clear teacher. The project's relative interpretation of the teacher's square error is defined under the same lined bridge; if we switch to another coupling or probabilities path, this teacher cannot be used as the only correct answer. One field may generate a reasonable endpoint under its own path, but there is a deviation in the teacher's index.

Standalone ProgramTest conditions projection and single-goose conditions speed; no torch is required.
def risk(value):return ((value-4)**2+(value+4)**2)/2
assert risk(0)==16 and risk(4)==32
t=0.25;mu=2.0;sigma2=1.0;x=1.5
variance=(1-t)**2+t*t*sigma2
covariance=t*sigma2-(1-t)
velocity=mu+covariance/variance*(x-t*mu)
assert abs(velocity-1.2)<1e-12
assert abs((mu-x)-velocity)>0.1
print(risk(0),risk(4),velocity)

Exercises with Step-by-Step Solutions

TRY IT YOURSELF

Practice a full project error

The condition labels are negative two for six to three quarters of the probability.

Hint 1
The best constants of the square loss are to be found from the mean value of the condition, rather than from whether the loss is zero.
Hint 2
The weighted square error is calculated for each of the two labels and the difference between the candidate and the best projection is reconciled with the loss increment.
Compare with the Solution
The average condition is six-by-four plus two-by-three, which is zero, so the optimal constant is zero. The minimum square loss is thirty-six times one-quarter and four times three-quarters. The lowest square loss is twelve. The forecast is 25 and nine, with a weight of thirteen. The difference is equal to the distance between the candidate ' s projection one and the best projection zero, confirming the project persistence equation.

TRY IT YOURSELF

Practice two-bit blend speed from responsibility.

Two types of responsibility for a two-dimensional position are 0.8 and 0. 2, with a different type of speed ( 1,− 1 and - 3, 2 What's the edge speed? What happens if you choose the nearest class?

Hint 1
Marginal velocity is the average of conditions after a given current position, not the most recent type label.
Hint 2
Compromise by coordinates of responsibility; whether there is a jump in the hard selection of the category boundary and whether the real category can be read at the time of generation.
Compare with the Solution
Weighted by coordinates, the first coordinates are 0:08 minus 0:06 and the second coordinates are negative: 08 plus 0.4. The edge speed is zero-two and negative:04. The hard selection of the first category is one and negative one, neglecting the quality of the secondary category, especially if it causes non-continuous jumps near the boundary of the category. Responsibility is calculated by the density of the current time and the true class number of the training sample cannot be used directly because there is no hidden label at the time of generation.

TRY IT YOURSELF

Practice three-pod design of a positive label.

The project speed label is misspelled to reduce the current plugin point. Writes how it relates to the correct speed and indicates at which point an error will be detected by the end-point test.

Hint 1
Write the current plug-in point to 1−t)x0+t x1, and sort the x1−xt.
Hint 2
Check t=0, internal and t=1 separately by comparing it to the number of t-to-path guides, avoiding a mere starting test for leaks.
Compare with the Solution
The correct velocity is to reduce the initial point of the end. The current point is to multiply the initial point by one time plus the end point by one time, so the end point minus the current point by one time. The same at zero, only the check starting point cannot be detected; there are errors in the internal moment, the error labels are always zero at one point, and the correct conditions are usually not zero. At the same time, it should be verified that the path has a limited differential number, internal timing, and end-point properties. The drop in training cannot replace this tab check because the wrong target can also be matched by the network.

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. What's the optimal regression for the FM condition label?

Show ExplanationThe square loss condition projection gives margin speed.
2. Conditional path line means a trajectory line?

Show ExplanationConditional paths are not the same as marginal streams.
3. What labels do you use for project training?

Show ExplanationThe teacher is to be analysed for reference purposes only, and the sampled conditions margin is to be used for training.
4. What about the peer coupling?

Show ExplanationThe same edge does not fix the joint end distribution.

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