ID-5-02 (TO) · Mathematical Foundations of Diffusion Models · Transport demo

The Transport Plan Lab

Two histograms over the same four bins. Moving one onto the other is a min-cost flow on a bipartite graph — and the answer you get depends entirely on what you decided moving costs.

Act I · The planMass has to go somewhere

The top bar is the source histogram p, split into bins A–D; the bottom bar is the target q. A transport plan γ says how much mass moves from each bin to each other bin. The ribbons are that plan. Their widths are forced to add up: everything leaving bin i totals p i, everything arriving at bin j totals q j — which is exactly the statement that γ is a coupling of p and q.

Among all such plans the lab shows the cheapest one for the cost you pick. Watch the ribbons cross, or refuse to.

optimal plan γ — ribbon width is mass moved
p weights q weights

cost matrix Cij

optimal plan γij

Rows of γ sum to p, columns to q — that is the whole constraint. A vertex of this polytope has at most 4 + 4 − 1 = 7 non-zero entries, so an optimal plan is always sparse: most pairs of bins never trade at all. Ribbons that cross mean mass has to overtake other mass. For costs growing convexly with distance that is never necessary, and the readout says so; for the all-or-nothing and concave costs it often is. (When several plans tie for optimal — which happens routinely for |i − j| — the lab draws a non-crossing one, since one exists.)

Act II · The cost functionChange the price, change the answer

The bins, the histograms and the constraints are all fixed. The only thing that varies below is the price of moving one unit of mass from bin i to bin j. Each row re-solves the same problem under a different price list.

total cost of the optimal plan, by cost function
The magnitudes are not comparable across rows — different cost functions are in different units, and scaling C scales the answer. What is comparable is the plan each one induces, and what each total means. Two rows have closed forms worth recognising: the all-or-nothing cost returns exactly the total variation distance, and the distance-on-a-line cost returns exactly the area between the two CDFs. Both are computed independently below and checked against the solver.

Transport is not one number. "How far apart are these two histograms?" has no answer until you say what it costs to move mass, and that choice is modelling, not mathematics. Pick the ground distance and you have picked the geometry: the same pair of histograms can be close under one price list and far under another, and can be matched monotonically under one and scrambled under the next.