Skip to content

Commit 882e741

Browse files
committed
update
1 parent 3214901 commit 882e741

1 file changed

Lines changed: 87 additions & 34 deletions

File tree

‎index.html‎

Lines changed: 87 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -125,42 +125,75 @@
125125
<header>
126126
<h1>Generator Matching without Generators</h1>
127127
<div style="text-align: center; color: #666; margin-bottom: 2rem;">
128-
or "Generator Matching for Computer Scientists" - Ben Murrell
128+
or "Generator Matching for Computer Scientists"
129+
</div>
130+
<div style="text-align: center; color: #666;">
131+
by Ben Murrell
129132
</div>
130133
</header>
131134

132135
<div class="abstract">
133-
<strong>Abstract.</strong> We give an intuitive description of generator matching in terms of a simple “resample–and–step” construction. Starting from conditional Markov processes indexed by a data variable $Z$, we define a hypothetical marginal process that, at each time $t$ and state $x$, resamples a fresh $Z$ from the posterior $Z \mid (X_t = x)$ and then moves one tiny step according to the corresponding conditional Markov process. We explain why this process preserves the desired marginal distributions, and why in the small–step limit it is equivalent to running a single Markov process with an <em>averaged generator</em>.
136+
<strong>Motivation.</strong> Generator Matching (GM) is an incredible framework that subsumes nearly all flow matching and diffusion models.
137+
Understanding it unlocks the ability to easily construct <a href="https://arxiv.org/pdf/2511.09465">entirely novel methods</a>, and let's you understand existing approaches with greater clarity.
138+
Depending on your math background, however, it can be somewhat unapproachable, since it uses the formalism of <a href="https://en.wikipedia.org/wiki/Infinitesimal_generator_(stochastic_processes)">generators</a> to handle the generality needed to cover all kinds of stochastic processes and state spaces.
139+
Here we use a simple reframing to attempt to explain Generator Matching without Generators, using only concepts from basic probability. Working through this should make it clear why GM works, and give you the ability to construct your own GM methods without learning measure theory and advanced stochastic processes.
140+
<p>
141+
Note: If you are in the target audience for this simplified presentation of GM, this will not be easy reading, and will require some work on your side. But it will be worth it. So set aside a few quiet hours, grab some coffee, and get ready to dive in.
142+
</p>
134143
</div>
135144

136145
<section>
137-
<h2>1. High–level picture</h2>
138-
<p>Generator Matching (GM) starts from two ingredients:</p>
146+
<h2>1. Preliminaries</h2>
147+
<p>
148+
In generative modeling, you typically have a training dataset of samples from some "target" distribution, and you wish to train a model that can generate new samples from this distribution. These could be images, sequences of text, songs, proteins, etc, each with their own state space (continuous, discrete, manifold, or mixtures of these).
149+
<p> This is what Generator Matching (GM) lets you do. Like <a href="https://mlg.eng.cam.ac.uk/blog/2024/01/20/flow-matching.html">flow matching</a> (which GM generalizes), this is done by starting from an easy-to-sample-from "prior" distribution, and learning how to transform this into the target distribution. It does this through many small steps in what we call "time" (which we denote with $t$), starting at $t=0$ (the simple prior) and ending at $t=1$ (the target distribution).
150+
</p>
151+
<p>
152+
[Insert image and protein examples.]
153+
</p>
154+
<p>
155+
We denote the state of the model at time $t$ as $x_t$. For example, if you are modeling images, then $x_1$ would be an image from the training dataset, and $x_0$ would be an image with random pixel values.
156+
</p>
157+
<p>We need to introduce the notion of a "conditional processs". GM requires that you can:</p>
139158
<ul>
140-
<li>a simple “prior” distribution $p_{\text{simple}}$ (usually Gaussian);</li>
141-
<li>a conditional path of distributions $p_t(\cdot \mid z)$,
142-
interpolating between the prior and a specific data point $z$.</li>
159+
<li>sample a $z$ from some distribution $p(z)$, which controls where the process ends when $t=1$.</li>
160+
<li>conditioned on $z$, sample $x_{t+\Delta t}$ from $p(x_{t+\Delta t} \mid x_t, z, t)$ for some small time step $\Delta t$;</li>
143161
</ul>
144162

145-
<p>The marginal generator turns out to be the appropriate <em>average</em> of the generators of the conditional processes. The goal of this note is to give an intuitive route to why this marginal generator is an average.</p>
163+
<p>What is $z$? Often $z$ is just a single training data sample $x_1$, but $z$ is an extremely flexible "latent variable", and can include other information that controls the path of the process. More about that later.</p>
164+
165+
<p>You can think of $p(x_{t+\Delta t} \mid x_t, z, t)$ as a function that takes the current state $x_t$, the latent $z$, and the time $t$, and returns the next state $x_{t+\Delta t}$, which may or may not involve some randomness. The only constraint is that when you repeatedly step through time by calling this function over and over, when $t$ reaches $1$, the state $x_1$ will be the sample from the training distribution that is associated with the latent $z$.</p>
166+
167+
<p>With a simple prior distribution $p(x_0)$ that governs where the process starts, $p(x_{t+\Delta t} \mid x_t, z, t)$ specifies the distribution of each subsequent step, and pins down what we call the "conditional path" (because it is conditioned on $z$ to terminate at a given $x_1$).</p>
168+
146169
</section>
147170

148171
<section>
149-
<h2>2. The Posterior Calculation</h2>
172+
<h2>2. The marginals of the process $p(x_t \mid t)$, and the conditional posterior distribution $p(z \mid x_t, t)$.</h2>
173+
174+
<p>Importantly, we can sample from $p(x_t \mid z, t)$, the conditional process at any $t$, by first sampling $z$, sampling $x_0$ from the prior, and then stepping through $p(x_{t+\Delta t} \mid x_t, z, t)$ for each step until $t$ is reached. A central distribution of interest is the <strong>marginal distribution</strong> of $x_t$ at each time $t$. If we have $n$ training data samples, and each $z$ has equal probability, then:
175+
$$p(x_t \mid t) = \frac{1}{n} \sum_{i=1}^n p(x_t \mid z_i, t)$$
176+
</p>
177+
<p>Conceptually, you can think about this as the distribution you get when you repeatedly sample $z$ from $p(z)$ and then sample $x_t$ from $p(x_t \mid z, t)$ and accumulate the $x_t$ samples. This is the marginal distribution of $x_t$ at each time $t$. <strong>Note:</strong> by construction, since each $z$ terminates at a sample from the training distribution, this marginal distribution at $t=1$ is the same as the training data distribution $p(z)$.</p>
150178

151-
<p>Define a joint model for $(Z, X_t)$: Sample $Z \sim p_{\text{data}}$, then run a conditional process $(X^z_t)$. In simple flow matching, the conditional path is a straight line:
152-
$$ X_t = (1-t)X_0 + t Z $$
153-
where $X_0 \sim \mathcal{N}(0, I)$.</p>
179+
<p>Using Bayes theorem, we can then write the posterior distribution of $z$ given $x_t$ and $t$ as $p(z \mid x_t, t) \propto p(x_t \mid z, t)$ (since $p(z)$ is a constant). In practice we will not need to calculate it, but we do need to understand what it means to explain GM.</p>
180+
</section>
181+
182+
<section>
183+
<h2>3. A concrete example</h2>
184+
185+
<p>As a working concrete example, we'll consider the case of standard <a href="https://arxiv.org/abs/2210.02747"> flow matching</a>, where the state space is continuous, $p(x_0)$ is a Gaussian distribution, and the conditional path is simply a straight line that points towards $x_1$. In this case, $p(x_{t+\Delta t} \mid x_t, z, t)$ is just a point mass at $x_t + \frac{(x_1 - x_t)\Delta t}{1-t}$.</p>
154186

155-
<p>To calculate the posterior $p(z \mid x, t)$, we invert this relationship. If we observe $x$ at time $t$, and we hypothesize it came from $z$, then the starting point must have been:
156-
$$ x_0 = \frac{x - t z}{1-t} $$
157-
The likelihood of $z$ is proportional to the density of the prior at this projected $x_0$.
187+
<p>With this example, $p(z \mid x_t, t)$ is simple to compute. There is no noise in the conditional process, so the only source of uncertainty is in the prior $p(x_0)$. Given $x_t$ and $t$, we can thus compute $p(z \mid x_t, t)$ for each $z$ proportional to the probability of $x_0$ under the Gaussian prior $p(x_0)$, and we can get $x_0$ by extrapolating backwards from $x_1$ through $x_t$:
188+
$$ x_0 = -t \cdot \frac{x_1 - x_t}{1-t} $$
158189
</p>
190+
191+
<p>The following interactive figure shows an example with a one-dimensional state, where you control $t$ and $x_t$, and $p(z \mid x_t, t)$ is shown as the opacity of the blue lines. Move around a little and understand how the training data points at $t=1$ get reweighted as $t$ and $x_t$ change.</p>
159192
</section>
160193

161194
<!-- Interactive Figure 1: The Posterior -->
162195
<div class="interactive-figure">
163-
<h4 style="margin-top:0;">Viz 1: The Time-Dependent Posterior</h4>
196+
<h4 style="margin-top:0;">$p(z \mid x_t, t)$</h4>
164197
<canvas id="posteriorCanvas" width="600" height="450"></canvas>
165198

166199
<div class="controls">
@@ -172,31 +205,43 @@ <h4 style="margin-top:0;">Viz 1: The Time-Dependent Posterior</h4>
172205

173206
<div class="caption">
174207
<strong>Instructions:</strong> Move the <span style="color:green">Green Dot</span> ($x$).
175-
The opacity of the <span style="color:blue">Blue Lines</span> represents the posterior probability $p(z|x,t)$.
176-
<br>
177-
The posterior averaged velocity $\bar{u}_t(x)$ can be shown as a red arrow (hidden in this viz).
178-
<br>
179-
Notice that at $t=0$, weights are based on the Prior (center). As $t \to 1$, weights depend on distance to the nearest $Z$.
208+
The opacity of the <span style="color:blue">Blue Lines</span> represents the posterior probability $p(z|x_t,t)$.
180209
</div>
181210
</div>
182211

183212
<section>
184-
<h2>3. The “resample–$Z$” marginal process</h2>
213+
214+
185215

186-
<p>We define a hypothetical process using a simple algorithm:</p>
216+
217+
<h2>4. A “resample–$z$” process</h2>
218+
219+
<p>Stepping away from our concrete example, back to the general case, we can define a hypothetical process using a simple algorithm:</p>
187220
<blockquote>
188-
Given $X^{(\Delta t)}_t = x$:
221+
Given $x_t$ at time $t$:
189222
<ol>
190-
<li>Sample a fresh latent $Z$ from the posterior $p(z \mid x, t)$;</li>
191-
<li>Evolve one tiny step towards that $Z$:
192-
$$ x_{new} = x + \frac{Z - x}{1-t} \Delta t $$
223+
<li>Sample a fresh latent $z$ from the posterior $p(z \mid x_t, t)$;</li>
224+
<li>Evolve one tiny step towards that $z$:
225+
$$ x_{t+\Delta t} = x_t + \frac{z - x_t}{1-t} \Delta t $$
193226
</li>
194227
</ol>
195228
</blockquote>
196229

197-
<p>If the step size is larger, we "hold" a specific $Z$ for longer, leading to a more "jagged" path, but as $\Delta t \to 0$,
198-
the random fluctuations cancel out, and the path follows the expected velocity (the smooth average).
199-
</p>
230+
231+
232+
<!-- Why resampling preserves marginals -->
233+
<div style="margin: 1.2rem 0;">
234+
<h3>Why this preserves the marginal path \(p_t\)</h3>
235+
<p>The resample–and–step chain exactly matches the one–time marginals of the original conditional construction. The reason is simple:</p>
236+
<ul>
237+
<li><strong>Same joint at time \(t\):</strong> In the original model, sampling \(Z \sim p_{\text{data}}\) and then \(X_t \sim p_t(\cdot \mid Z)\) induces some joint law for \((Z, X_t)\). In the resampling chain, we first have \(X_t \sim p_t\), then draw \(Z \sim p(z \mid X_t, t)\). By Bayes’ rule these two procedures produce the <em>same</em> joint distribution for \((Z, X_t)\) at time \(t\).</li>
238+
<li><strong>Same tiny step given \(Z\):</strong> From that shared \((Z, X_t)\), both constructions apply the <em>same</em> conditional transition kernel \(K^{(Z)}_{t+\Delta t \mid t}(\cdot \mid X_t)\) to obtain the next state.</li>
239+
<li><strong>Therefore same next marginal:</strong> Because both start from the same \((Z, X_t)\) law and use the same kernel, the distribution of \(X_{t+\Delta t}\) is identical in both. Hence, if \(X_t \sim p_t\), then \(X_{t+\Delta t} \sim p_{t+\Delta t}\).</li>
240+
</ul>
241+
<p>Iterating over steps keeps the whole grid of marginals \(\{p_t\}\) intact, and letting \(\Delta t \to 0\) preserves the continuous path. A short Bayes–rule proof appears in the appendix of the note.</p>
242+
</div>
243+
244+
<p>This interactive figure shows...</p>
200245
</section>
201246

202247
<!-- Interactive Figure 2: Resample vs Average -->
@@ -227,6 +272,14 @@ <h4 style="margin-top:0;">Resampling faster and faster until things are smooth</
227272
</div>
228273
</div>
229274

275+
<h3>The infinite switching limit</h3>
276+
277+
<p>If the step size is larger, we "hold" a specific $Z$ for longer, leading to a more "jagged" path, but as $\Delta t \to 0$,
278+
the random fluctuations cancel out, and the path follows the expected velocity (the smooth average).
279+
</p>
280+
281+
282+
230283
<!-- LOGIC -->
231284
<script>
232285
// =========================================
@@ -943,7 +996,7 @@ <h4 style="margin-top:0;">Resampling faster and faster until things are smooth</
943996
</script>
944997

945998
<section>
946-
<h2>4. Posterior–averaged tiny step (and the red arrow)</h2>
999+
<h2>5. Posterior–averaged tiny step (and the red arrow)</h2>
9471000
<p>In the “resample–and–step” view, we repeatedly (i) look at the current $x$, (ii) resample a fresh $Z \sim p(z \mid x,t)$, and (iii) take one tiny step using the conditional rule for that $Z$. As the step size $\Delta t \to 0$, the randomness from resampling washes out and what remains is the <em>average tiny step</em> at $(t,x)$.</p>
9481001
<p>For simple flow matching, the conditional velocity is $u_t(x\mid z) = \dfrac{z - x}{1-t}$. The <em>posterior–averaged velocity</em> is</p>
9491002
<p style="text-align:center;">$$ \bar{u}_t(x) \;=\; \E\!\left[\,u_t(x\mid Z)\,\middle|\, X_t = x \right] \;=\; \E\!\left[\,\frac{Z - x}{1-t}\,\middle|\, x,t \right]. $$</p>
@@ -1027,8 +1080,8 @@ <h4 style="margin-top:0;">Viz 3: The Time-Dependent Posterior (with Averaged Vel
10271080
const priorSigmaY = PRIOR_SIGMA_1;
10281081
drawVerticalGaussianHump(ctx3, cvs3.height, priorMeanY, priorSigmaY, 60, '#888');
10291082
ctx3.fillStyle = "#777";
1030-
ctx3.fillText("Prior (t=0)", 8, Math.max(14, priorMeanY - priorSigmaY - 10));
1031-
ctx3.fillText("Data (t=1)", cvs3.width - 70, 14);
1083+
ctx3.fillText("Prior (t=0)", 2, 20);
1084+
ctx3.fillText("Data (t=1)", cvs3.width - 50, 20);
10321085

10331086
const tPosX = v3.t * cvs3.width;
10341087

@@ -1087,7 +1140,7 @@ <h4 style="margin-top:0;">Viz 3: The Time-Dependent Posterior (with Averaged Vel
10871140
</script>
10881141

10891142
<section>
1090-
<h2>5. Tiny–step averaging: four concrete cases</h2>
1143+
<h2>6. Tiny–step averaging: four concrete cases</h2>
10911144
<p>“Average the generator” means “average the <em>infinitesimal</em> step rule.” Below are four common cases and exactly what gets averaged.</p>
10921145

10931146
<h3>Case I: pure drift (deterministic flow)</h3>

0 commit comments

Comments
 (0)