Concept units

Velocity fields: an arrow at every point

Intermediate

Read these first if they are new to you

The idea in one paragraph

A velocity field puts an arrow at every point of space. The arrow at a point says which way something there moves, and how fast. Drop a leaf on a river: at each moment it moves along the arrow where it is, so it traces a path through the field. A field can also change over time, like the wind during a day. Then the arrow depends on both the place and the time. Some generative models learn a velocity field that carries random noise to real examples.

Every point gets an arrow that gives direction and speed

Think of a weather map of the wind, with a small arrow drawn over each town. Each arrow is a vector. Its direction is the direction of motion, and its length is the speed. That vector is the velocity: how fast the position changes with time, in each coordinate. In other words, each coordinate of the velocity is the derivative of that coordinate of the position with respect to time.

A velocity field is a rule that gives the velocity at every point p. We write it v(p). If the arrows change over time, we write v(p, t).

Worked example: a swirl

The field v(x, y) = (−y, x) turns things around the origin. Read three of its arrows:

  1. At (2, 0) the arrow is (−0, 2) = (0, 2): straight up, at speed 2.
  2. At (0, 1) the arrow is (−1, 0): straight left, at speed 1.
  3. At (3, 4) the arrow is (−4, 3), with speed √(16 + 9) = 5.

Each arrow is at a right angle to the line from the origin, so things circle the origin. Points farther out move faster.

Your turn. The sink field is v(p) = (1, 1) − p. Which arrow sits at (4, 2)? Where does a particle in this field come to rest?

Answer

At (4, 2) the arrow is (1 − 4, 1 − 2) = (−3, −1). A particle comes to rest at (1, 1), the only point where the arrow has length zero. Everywhere else the arrow points toward (1, 1).

A particle traces a path by following the arrows

A particle in a field moves, at every moment, with the velocity given by the arrow where it is. As it moves, it reaches new arrows, so its direction and speed change. The curve it traces is its path. Two particles that start at different points usually follow different paths and may end in different places.

Release particles and watch them follow the arrows

Move the pointer over the field to read the arrow there. Click or tap to release a particle.

Try this. Choose Two sinks and release particles on both sides of the middle. Find the line that separates particles that end at the left sink from those that end at the right one. What happens to a particle released exactly on that line? Arrow lengths are scaled to fit the picture. The page moves each particle in many tiny steps, with a refinement of Euler's method called the midpoint method.
What you should find

In Two sinks, the dividing line is the vertical line through the middle. A particle released exactly on it slides along the line to the center point and stops there, because the two pulls cancel. Any small nudge sends it to one sink or the other.

Generative models use fields like this one: where a noise point starts decides which kind of example it becomes.

In a smooth field, two particles never meet

Suppose two particles were ever at the same place at the same time. From then on they would read the same arrows and move together. Run time backward from that moment, and they would also read the same arrows, so they must have been together all along. So in a field whose arrows change smoothly from point to point, two particles that start at different points are never at the same place at the same time.

If the field does not change with time, the paths never cross at all. If it does change, two particles can pass through the same spot at different times, but never at the same time.

This fact matters for flow matching. Its straight training paths often bring two points to the same place at the same time, heading different ways. Particles that follow its learned field never meet, so their paths bend instead.

What "smooth" means here

The precise condition is called Lipschitz continuity: the arrow cannot change faster than some fixed rate as you move. Fields with jumps, or with arrows that change infinitely fast at some point, can make paths merge. The usual layers of a neural network meet the condition, at least within any bounded region.

read_arrows.py

import numpy as np

def swirl(p):
    # Turn around the origin: the arrow at (x, y) is (-y, x).
    x, y = p
    return np.array([-y, x]) + 0.0     # + 0.0 turns -0.0 into 0.0

def sink(p, target=np.array([1.0, 1.0])):
    # Head for a target: the arrow points from p to the target.
    return target - p

for p in [(2.0, 0.0), (0.0, 1.0), (3.0, 4.0)]:
    v = swirl(np.array(p))
    speed = np.linalg.norm(v)   # np.linalg.norm gives the length of the arrow v
    print("swirl at", p, "->", v, " speed", round(speed, 2))
print("sink at (4, 2) ->", sink(np.array([4.0, 2.0])))
swirl at (2.0, 0.0) -> [0. 2.]  speed 2.0
swirl at (0.0, 1.0) -> [-1.  0.]  speed 1.0
swirl at (3.0, 4.0) -> [-4.  3.]  speed 5.0
sink at (4, 2) -> [-3. -1.]

Check yourself

  1. In the swirl field v(x, y) = (−y, x), what is the arrow at (0, −2), and which way does a particle there move?

    Answer

    (2, 0). The particle moves to the right at speed 2, which is counterclockwise around the origin.

  2. An arrow is (6, 8). What is the speed?

    Answer

    √(36 + 64) = 10.

  3. In a smooth field that does not change with time, can two paths cross in an X shape?

    Answer

    No. At the crossing point the arrow would have to point along both paths at once, but each point has only one arrow. Two particles can still travel the same path, one after the other.

Go further

Optional background, for readers with more time.

Where this shows up

Units that build on this one