← Back to Index

Lecture 16 — Generative Models

Flow Matching, ODEs, and Euler's Method

1. Target Data Distribution (Smiley Face)

STATIC

The target distribution is a 2D smiley face built from sampled points along a circle (face outline), two dots (eyes), and an arc (mouth), each perturbed with small Gaussian noise.

2. Flow Matching — Trajectories

ANIMATED

Particles follow straight-line (linear interpolation) paths from noise (t=0) to data (t=1):  xt = (1−t) x0 + t x1

Noise (source) Data (target) Current particles

3. Velocity Vector Field

INTERACTIVE

The learned velocity field v(xt, t) = x1 − x0 shown as arrows on a grid. Arrows point from the current interpolated position toward the target. Drag the slider to see how the field changes with time.

4. Sample Generation (ODE Integration)

ANIMATED

Starting from noise, we integrate dx/dt = v(x, t) via Euler's method to generate new samples that match the target distribution.

5. Simple ODE: dx/dt = −x

INTERACTIVE

Analytical solution: x(t) = x(0) · e−t. Drag the slider to change the initial condition.

6. Euler's Method Visualization

INTERACTIVE

Compare the true solution x(t) = x(0) e−t with Euler steps x(t+Δt) = x(t) + Δt · f(x, t). Larger step sizes yield less accurate (and eventually unstable) approximations.

True solution Euler approximation

7. Multiple Euler Step Sizes

VISUALIZATION

Euler approximations with step sizes Δt ∈ {0.1, 0.5, 1.0, 1.5, 2.0, 2.5}. For Δt > 2 the method becomes unstable and oscillates.

Made with ❤️ by Mark Žnidar