Learning preferences

Make learning more comfortable. Changes apply immediately.

Enlarges page content, including diagrams and their labels. You can also use your browser’s zoom.

Choose the colours that are easiest for you to distinguish. Applies to lesson diagrams and lab plots. Labels, shapes, hatching and line patterns also distinguish meanings. Source photographs and raw image brightness stay unchanged; mask-only views are available for image overlays.

ExampleComparisonSample link

Saved in this browser on this device. Preferences are separate from progress backups.

Lesson 5 of 8 in this unit

Understand Neural Networks · ORIGINAL LEARN AI LESSON

Generate by learning a flow.

Train a velocity field and compare Euler and Heun generation on the diffusion lesson’s four-mode target.

By the end: Separate training-pair paths, learned velocity and numerical integration; compare coverage at explicit field-call budgets.

Start with the exampleJump to the experimentRead the explanation
Prerequisites and path options

Why learn this? See how a learned movement field transforms a simple distribution into a more useful one.

01 · TRY

Start with something concrete.

Move a Gaussian cloud using an untrained field, then predict how training and smaller integration steps might change the result.

Try the interactive model
02 · PREDICT
Before you experiment

Does the sampler know the target paired with each generated starting point?

Does the sampler know the target paired with each generated starting point?
03 · EXPERIMENT

Change one thing. Watch what follows.

Loading this browser experiment…

04 · UNDERSTAND
READ & CONNECT

Understand what changed.

Back to the experiment

A shorter explanation, with the original worked examples available below. Both explain the same experiment and its limits.

Same learning goal in both modes: Separate training-pair paths, learned velocity and numerical integration; compare coverage at explicit field-call budgets.

The idea in everyday terms

A flow model learns how points should move at different positions and times. Starting with a simple random cloud, repeated small movements can transform it toward a target distribution. The model predicts a movement vector, not a final answer in one step.

What to watch in the experiment

Inspect the learned field and compare different numerical step counts from the same starting noise. Training error and integration error are different: even a useful movement field can be followed inaccurately by steps that are too large.

What this does not establish

These synthetic groups and public development comparisons do not establish a general generator. More sampling steps cost work and cannot necessarily repair an incorrectly learned field.

Open the full worked examples, calculations and limitations

This is the same reference used in Technical mode. Expand it whenever you need the exact numbers, assumptions or further explanation.

Move a cloud of points

Imagine moving a scattered cloud into four groups. Instead of predicting a final destination in one jump, a model tells each point which direction to move at its current position and time. Repeated small moves generate a new cloud. Try an untrained field first, then train and compare the result using the same starting points.

This lab uses the diffusion lesson’s original synthetic dataset: 32 training points and 32 distinct public development points around four centers. Its separate neural network reads two coordinates and time and predicts two velocity coordinates. Two hidden layers of sixteen tanh units give 370 parameters. No image model, external service or GPU is required.

Construct a training path

Draw a two-coordinate source z from a standard Gaussian: each coordinate has mean zero and variance one. Independently choose a training target x. Time t runs from zero to one; it is normalized path time, not seconds on your computer. A straight path connects the pair:

xt=(1−t)z+tx,u=x−zx_t=(1-t)z+tx,\qquad u=x-z

xₜ is the intermediate position; u is the target velocity, in coordinate units per unit of path time. Read this as “start with a fraction of the source and a fraction of the destination.” With z = [−0.6, 0.8], x = [1.2, −1.2] and t = 0.5, the position is [0.3, −0.2]. The velocity is [1.8, −2.0]. Over half a unit of time that velocity moves the source by [0.9, −1.0]. Change the inspector’s time and check both endpoints yourself.

These independent pairs are not an optimal-transport matching. Different pairs can pass through similar positions with different velocities. The model sees only position and time, not the pair’s hidden destination. Squared-error training encourages a conditional average of the possible velocities there. Straight training-pair paths therefore do not imply straight generated trajectories.

Learn the field

Write vθ(xₜ, t) for the network’s predicted velocity; θ denotes its parameters. For N two-dimensional examples the loss is:

L=12N∑i=1N∥vθ(xti,ti)−ui∥2L=\frac{1}{2N}\sum_{i=1}^{N}\left\|v_\theta(x_{t_i},t_i)-u_i\right\|^2

The squared length means “square the error in each coordinate and add.” Dividing by 2N averages across examples and their two coordinates. A prediction [1, −1] against target [2, −3] contributes (1 + 4)/2 = 2.5 to a one-example loss. This is velocity error, not exact likelihood and not the diffusion lesson’s noise error; those loss numbers cannot rank the two generators directly.

Each update creates fresh source points and times for the 32 training targets. Adam uses simultaneous gradients, moment correction and gradient-norm clipping at five. Buttons run at most 25 updates, with a total limit of 1,000. Monitoring reuses fixed pairs at five times, including endpoints, and compares the model against zero velocity on those same pairs. Development monitoring is repeated practice evidence, not an untouched qualification test.

Generate with small numerical steps

Freeze the model and draw 24 Gaussian starting points. The sampler never reads their intended destination: none was assigned. Let h = 1/S be a step size for S steps. Euler’s rule reads the current velocity and moves in that direction:

xt+h=xt+h vθ(xt,t)x_{t+h}=x_t+h\,v_\theta(x_t,t)

For position [1, 2], velocity [−0.4, 0.8] and h = 0.25, Euler produces [0.9, 2.2]. The field may change during this move. Heun’s method first makes this Euler prediction, reads the velocity there at the new time, then uses the average of the two velocities for the actual move. If the second velocity is [−0.2, 0.4], Heun produces [0.925, 2.15]. The lab shows the first generated point’s actual arithmetic for every saved step.

Euler uses one field evaluation per point per step; Heun uses two. With 24 points, Euler with 32 steps and Heun with 16 steps each use 768 individual field evaluations. Equal calls do not prove equal elapsed time: bookkeeping and rendering also take work. Inspecting an already saved frame performs no new field evaluations.

There are two different error sources: the learned field may be inaccurate, and a finite-step integrator approximates motion through that field. Smaller steps can reduce integration error without repairing model error. More steps need not improve our sample-quality scores. No new noise is added after initialization in this sampler; different starting seeds still produce different samples.

Compare evidence and limits

Train one field, then compare Euler with 4 and 32 steps using seed 7. Capture both finished runs. Next compare Euler 32 with Heun 16 for equal field-call budgets. Use another seed before generalizing. Frozen runs retain their original model even if you continue training the live model. Fixed plot axes show out-of-range counts rather than hiding failures by clipping coordinates.

The final summary reports distance to the nearest center and counts within radius 0.45 of each center. Check coverage as well as total proximity. These diagnostics do not establish the target ring shape, correct frequencies or full distribution agreement. A successful toy sample is not evidence of image-generation capability.

For a guided project, export two captures and explain one quality/work tradeoff with numbers. For implementation practice, independently implement Euler and Heun on the field dx/dt = x, whose solution from x = 1 is e at time one; compare error at equal field-call budgets before applying the methods to a neural field. For a decision brief, select a budget, report failure counts across seeds, and state what evidence would change your choice. These are practice tasks; exported notes and captures are not independent assessment or human-reviewed implementation evidence.

Continue with the diffusion experiment to compare mechanisms on the same target. The expanded catalog shows the remaining generation topics. Learner pilots and human artifact review remain pending.

05 · APPLY
Check your understanding

Doubling integration steps barely changes the samples, and one mode remains missing. What should you investigate?

Doubling integration steps barely changes the samples, and one mode remains missing. What should you investigate?
06 · CONTINUE

Take this idea with you.

Flow matching learns velocity from constructed paths. Generation integrates a learned field; assess model error, numerical error, sample quality and computation separately.

My Learning
Explore related topics and the topic map

How this topic connects

Explore this topic on the interactive map

Use these connections to review a foundation or choose where to go next. You can open any topic without completing the others.

What it builds on

  • Generate by removing noise

    Understand how repeated denoising produces samples and what changes when you alter the sampling process.

  • Gaussian latent variables

    Understand the tradeoff between reconstructing examples and learning a space from which new examples can be sampled.

You are hereGenerate by learning a flow

Train a velocity field and compare Euler and Heun generation on the diffusion lesson’s four-mode target.

What it enables