Skip to content
QFT.org

Search QFT.org

Enter a word or phrase.

    You can also browse the main navigation and chapter contents.

    Continuous and Stochastic Normalizing Flows

    A transported field configuration is not enough to evaluate a probability ratio. For a deterministic invertible map, its Jacobian supplies the missing density. For a stochastic procedure, the recorded transitions determine a path density; obtaining the endpoint density normally requires integrating over unobserved paths.

    This distinction matters when a learned proposal enters importance sampling or Metropolis acceptance. We will compute a continuous transport density, test what a numerical solver actually approximates, and build an explicit Gaussian path example. The interacting comparison uses the same frozen score as diffusion and score-based field models, so the density and cost discussion refers to an actual fitted model rather than a hypothetical exact score.

    Preparation: Change of variables, Gaussian conditioning, and ordinary differential equations. The sampling time is artificial. The field has two real coordinates with the positive Euclidean measure defined on the preceding page.

    The density of a continuous map

    Let

    dyτdτ=b(yτ,τ),y0=z∼qb.(1)\frac{\mathrm dy_\tau}{\mathrm d\tau} =b(y_\tau,\tau),\qquad y_0=z\sim q_{\mathrm b}. \tag{1}

    Assume that bb is continuously differentiable in its spatial argument, globally Lipschitz there uniformly on 0≤τ≤T0\leq\tau\leq T, and that bb and its spatial derivative are jointly continuous. The solution exists globally over this interval and defines an invertible differentiable map Fτ:z↦yτF_\tau:z\mapsto y_\tau. These hypotheses matter: a learned polynomial vector field can generate finite-time escape, in which case a global change-of-variables claim is unjustified.

    Differentiate the solution with respect to zz. Its Jacobian matrix Jτ\mathcal J_\tau obeys

    J˙τ=Dyb(yτ,τ)Jτ,J0=I.(2)\dot{\mathcal J}_\tau= D_yb(y_\tau,\tau)\mathcal J_\tau, \qquad \mathcal J_0=I. \tag{2}

    Jacobi's determinant identity then gives

    ddτlog⁡det⁡Jτ=tr⁡Dyb(yτ,τ).(3)\frac{\mathrm d}{\mathrm d\tau}\log\det\mathcal J_\tau =\operatorname{tr}D_yb(y_\tau,\tau). \tag{3}

    The determinant is positive, since it starts at one and is the exponential of a finite integral. Hence the transported model density satisfies

    log⁡qτ(yτ)=log⁡qb(z)−log⁡det⁡Jτ,ddτlog⁡qτ(yτ)=−∇ ⁣⋅b(yτ,τ).(4)\begin{aligned} \log q_\tau(y_\tau) &=\log q_{\mathrm b}(z)-\log\det\mathcal J_\tau,\\ \frac{\mathrm d}{\mathrm d\tau}\log q_\tau(y_\tau) &=-\nabla\!\cdot b(y_\tau,\tau). \end{aligned} \tag{4}

    The same equation follows from probability conservation: ∂τq+∇ ⁣⋅(bq)=0\partial_\tau q+\nabla\!\cdot(bq)=0. This is an exact statement about the density of the specified continuous flow. It does not assert that this density equals a desired physical target. See Song et al., Appendix D.1–D.2, Eqs. (35)–(40).

    A density that can be checked exactly

    The free two-site field has covariance C0=diag⁡(1/2,1/6)C_0=\operatorname{diag}(1/2,1/6). Under dXt=−Xt dt+2 dWt\mathrm dX_t=-X_t\,\mathrm dt+\sqrt2\,\mathrm dW_t,

    Ct=I+e−2t(C0−I).(5)C_t=I+e^{-2t}(C_0-I). \tag{5}

    The exact reverse probability-flow velocity is b(y,τ)=(I−CT−τ−1)yb(y,\tau)=(I-C_{T-\tau}^{-1})y. Its map and determinant are

    Fτ(z)=CT−τ1/2CT−1/2z,log⁡det⁡Jτ=12log⁡det⁡CT−τdet⁡CT.(6)F_\tau(z)=C_{T-\tau}^{1/2}C_T^{-1/2}z, \qquad \log\det\mathcal J_\tau= \frac12\log\frac{\det C_{T-\tau}}{\det C_T}. \tag{6}

    Starting with qb=N(0,CT)q_{\mathrm b}=\mathcal N(0,C_T) gives covariance CT−τC_{T-\tau}. Substituting the map into the normalized Gaussian density reproduces (4), including its sign and endpoint term. The companion independently integrates the divergence at quadrature orders 6464 and 128128 for T=1,2,4T=1,2,4, and compares it with (6).

    Starting instead with a standard Gaussian gives a different but still normalized final model:

    Law⁡(YT)=N(0,C0CT−1).(7)\operatorname{Law}(Y_T)=\mathcal N(0,C_0C_T^{-1}). \tag{7}

    Computing its density exactly does not make it the intended N(0,C0)\mathcal N(0,C_0). Density correctness and target approximation are separate questions.

    For the interacting field, the fitted score on the preceding page has the form sc(x,t)=−x+bounded smooth corrections_c(x,t)=-x+\text{bounded smooth correction}. Its reverse ODE velocity is b=y+sc(y,T−τ)b=y+s_c(y,T-\tau), so the linear terms cancel. Bounded feature gradients and Hessians ensure the global assumptions used above. The density in (4) therefore exists for this learned continuous map even though its field moments are biased.

    Continuous divergence is not a discrete Jacobian

    Suppose a numerical integrator returns a map F^h\widehat F_h and also integrates the scalar equation L′=∇ ⁣⋅bL'=\nabla\!\cdot b. There are now two quantities:

    log⁡∣det⁡DF^h(z)∣,L^h(z)≈∫0T∇ ⁣⋅b(yτ,τ) dτ.(8)\log\left|\det D\widehat F_h(z)\right|, \qquad \widehat L_h(z)\approx \int_0^T\nabla\!\cdot b(y_\tau,\tau)\,\mathrm d\tau. \tag{8}

    They coincide for the exact flow but need not coincide at finite step size. The first is the derivative of the numerical update itself. The second approximates the log determinant of the continuous flow. Treating the latter as an exact density for the numerical proposal can invalidate a probability ratio.

    For RK4 we differentiate every stage and compose the resulting matrices. Equivalently, apply RK4 to the coupled state and variational equations, using the same intermediate states. This produces the actual derivative of the finite RK4 map. We separately integrate its divergence and compare the two.

    The fixed experiment uses 6464 base Gaussian probes and the same 6060-coefficient interacting score. Over the sampled points:

    RK4 stepsMaximum log-determinant discrepancyMaximum reverse-map defect
    32321.14×10−41.14\times10^{-4}5.75×10−55.75\times10^{-5}
    64647.67×10−67.67\times10^{-6}1.83×10−61.83\times10^{-6}
    1281284.96×10−74.96\times10^{-7}5.72×10−85.72\times10^{-8}

    The reverse-map defect integrates the ODE back from each computed endpoint. All tested numerical determinants are positive, but checking finitely many points is not a global invertibility proof for F^h\widehat F_h. The global proof above concerns the continuous flow.

    On the first eight probes, centered differences of the complete numerical map agree with its stage-derived Jacobian to about 5×10−115\times10^{-11} at difference step 10−510^{-5}; reducing that step to 10−610^{-6} exposes roundoff. On a predetermined subset of 1616 probes, DOP853 with two fixed tolerance pairs changes the augmented solution by 9.42×10−129.42\times10^{-12}. At 128128 RK4 steps, the largest endpoint difference from the tighter reference is 1.13×10−71.13\times10^{-7} and the divergence-integral difference is 1.05×10−71.05\times10^{-7}.

    These checks resolve numerical transport and density error on the declared probes. They do not bound every tail configuration or remove score-model bias. The small continuous-solver error coexists with the substantial interacting moment bias measured on the previous page.

    Refinement of the discrepancy between integrated divergence and the actual RK4 map determinant, alongside cached-input stochastic and deterministic transport timings at equal score-call budgets.

    Left: two distinct density diagnostics converge with step refinement on the fixed probes. Right: sampling-only transport times use identical batch sizes and score-call budgets; density derivatives, training and input generation are accounted for separately. The timings describe this implementation, not an accuracy or scaling theorem.

    Stochastic transitions define an extended probability space

    Let a reverse sampler start from y0∼qby_0\sim q_{\mathrm b} and apply normalized stochastic kernels Rk(yk+1∣yk)R_k(y_{k+1}\mid y_k). Its joint path density is

    Q(y0,…,yK)=qb(y0)∏k=0K−1Rk(yk+1∣yk).(9)Q(y_0,\ldots,y_K) =q_{\mathrm b}(y_0)\prod_{k=0}^{K-1}R_k(y_{k+1}\mid y_k). \tag{9}

    For reverse Euler with step hh, the kernels are known Gaussians with mean yk+h[yk+2sc(yk,T−kh)]y_k+h[y_k+2s_c(y_k,T-kh)] and covariance 2hI2hI. This makes (9) tractable. Its endpoint density is instead

    qend(yK)=∫Q(y0,…,yK) d2y0⋯d2yK−1.(10)q_{\mathrm{end}}(y_K)= \int Q(y_0,\ldots,y_K) \,\mathrm d^2y_0\cdots\mathrm d^2y_{K-1}. \tag{10}

    One realized noise history does not perform that integral. In particular, paths sharing an endpoint can have different values of (9).

    There is nevertheless a useful exact construction on path space. Choose normalized kernels Fk(yk∣yk+1)F_k(y_k\mid y_{k+1}) toward the noisier fields and define

    P(y0,…,yK)=π(yK)∏k=0K−1Fk(yk∣yk+1).(11)P(y_0,\ldots,y_K) =\pi(y_K)\prod_{k=0}^{K-1}F_k(y_k\mid y_{k+1}). \tag{11}

    Successively integrating out y0,y1,…,yK−1y_0,y_1,\ldots,y_{K-1} gives the desired endpoint marginal π\pi. In this example the FkF_k can be exact OU noising kernels, with mean e−hyk+1e^{-h}y_{k+1} and covariance (1−e−2h)I(1-e^{-2h})I.

    The extended importance ratio is

    w(y0,…,yK)=π(yK)qb(y0)∏k=0K−1Fk(yk∣yk+1)Rk(yk+1∣yk).(12)w(y_0,\ldots,y_K) =\frac{\pi(y_K)}{q_{\mathrm b}(y_0)} \prod_{k=0}^{K-1} \frac{F_k(y_k\mid y_{k+1})} {R_k(y_{k+1}\mid y_k)}. \tag{12}

    If QQ covers PP and the required moments are integrable, independent proposal paths can be weighted by (12). If π\pi is known only up to normalization, the corresponding self-normalized estimator is consistent under the usual law-of-large-numbers conditions, but has finite-sample ratio bias. An independent Metropolis algorithm could instead operate on the entire path. Neither procedure substitutes a path probability for the endpoint proposal density in an ordinary endpoint-only ratio. This construction and its marginal distinction are explicit in Wu, Köhler and Noé, §2, Eqs. (8)–(12) and Theorem 1.

    A fully calculable path check

    Take the free Gaussian field at chronological times 0,12,10,\frac12,1. Assemble its full six-dimensional covariance directly:

    Cov⁡(Xs,Xt)=e−∣t−s∣Cmin⁡(s,t).(13)\operatorname{Cov}(X_s,X_t) =e^{-|t-s|}C_{\min(s,t)}. \tag{13}

    Its joint normalized Gaussian density agrees with the product of the two forward transition densities and with the product of the two exact conditional reverse densities. The latter use

    At=e−hCtCt+h−1,Vt=Ct−e−2hCtCt+h−1Ct.(14)\begin{aligned} A_t&=e^{-h}C_tC_{t+h}^{-1},\\ V_t&=C_t-e^{-2h}C_tC_{t+h}^{-1}C_t. \end{aligned} \tag{14}

    The ratio (12) is then one for every path, since both factorizations describe the same joint law. The companion checks the origin and all twelve signed coordinate-unit vectors against the independently assembled joint covariance.

    Replace the reverse kernels by Euler kernels. Their product still agrees with the corresponding six-dimensional Gaussian joint density, but it differs from the two-dimensional endpoint density obtained by marginalization. In the retained example, two paths ending at the origin have joint log densities −5.41877-5.41877 and −5.76290-5.76290, while both have endpoint log density −1.88204-1.88204. The stochastic model's density is not ill-defined; the path and endpoint are simply different random variables.

    This is a Gaussian density calculation, not an executed interacting path-space Metropolis or importance-sampling study. The interacting outputs on the preceding page remain explicitly uncorrected.

    Density estimation and cost

    In many dimensions, a trace such as tr⁡Dyb\operatorname{tr}D_yb can be estimated with a random vector ξ\xi satisfying E[ξξT]=I\mathbb E[\xi\xi^T]=I:

    E[ξTDyb ξ]=tr⁡Dyb.(15)\mathbb E[\xi^T D_yb\,\xi]=\operatorname{tr}D_yb. \tag{15}

    This is the trace estimator used in Song et al., Appendix D.2, Eq. (40). Here the dimension is only two, so the calculation evaluates the trace directly. In a stochastic trace calculation, unbiasedness of the trace estimate does not make an exponentiated log-density estimate unbiased. For example,

    ℓ^=ℓ+σZ,Z∼N(0,1)⟹E[eℓ^]=eℓeσ2/2.(16)\widehat\ell=\ell+\sigma Z,\quad Z\sim\mathcal N(0,1) \quad\Longrightarrow\quad \mathbb E[e^{\widehat\ell}] =e^\ell e^{\sigma^2/2}. \tag{16}

    An ordinary Metropolis ratio requires the appropriate proposal probabilities; arbitrary noisy log-density substitutes do not inherit its invariance proof. Specialized extended-space methods need their own positive-weight and distributional construction.

    For the actual interacting score model, the matched sampling budgets are 128,256,512128,256,512 score evaluations per trajectory: that many Euler steps versus one quarter as many RK4 steps. A fixed batch of 512512 uses cached base vectors and Brownian increments, one warmup and three timed replays:

    Score calls per trajectoryEuler SDE median timeRK4 ODE median time
    1281280.0253 s0.0253\ \mathrm s0.0245 s0.0245\ \mathrm s
    2562560.0532 s0.0532\ \mathrm s0.0498 s0.0498\ \mathrm s
    5125120.1033 s0.1033\ \mathrm s0.1013 s0.1013\ \mathrm s

    These are comparable transport-kernel timings on one implementation. They exclude cached-input generation, training and I/O. A fresh Euler trajectory also needs 2K2K Gaussian variates beyond its two base variates; the deterministic trajectory needs only the two base variates. Integrating the ODE Jacobian or density adds derivative evaluations and state components, which are absent from the sampling-only timing table. The fitted model's one-time SVD and design diagnostics took about 0.197 s0.197\ \mathrm s in this run.

    Equal score calls therefore do not imply equal end-to-end cost or equal accuracy. Both outputs have model bias, and their stochastic uncertainties differ. No break-even or high-dimensional advantage is inferred. The companion retains all raw timing repeats and input-generation costs, so exclusion of cached work is explicit.

    The pure maps and checks are in continuous_transport.py, transport_checks.py and transport-results.json under examples/computational-qft/generative-models/. Reproduction consumes the delivered score coefficients; plotting does not train or resample. For corrections with an explicitly normalized finite proposal, continue to corrected learned proposals.

    Summary

    A globally defined continuous flow has a tractable density through its divergence or variational determinant. A numerical approximation introduces a separate density error, and a learned flow can still miss the physical target. Stochastic transitions supply an extended path law; a valid correction must use that law or compute the endpoint marginal. Keeping these objects distinct makes both probability ratios and cost comparisons meaningful.

    Exercises

    1. A continuous map and its Euler approximation

    For y˙=γy\dot y=\gamma y in dd dimensions, derive the exact density transformation over a time step hh. Compare the log determinant of a single Euler map with the integrated divergence. State the conditions for invertibility and explain what density would be correct for each map.

    Solution

    The exact map is y=eγhzy=e^{\gamma h}z, with Jacobian eγhIe^{\gamma h}I. Thus

    qexact(y)=qb(e−γhy)e−dγh.q_{\mathrm{exact}}(y) =q_{\mathrm b}(e^{-\gamma h}y)e^{-d\gamma h}.

    The variational equation is J˙=γJ\dot{\mathcal J}=\gamma\mathcal J, and its log determinant is dγhd\gamma h, equal to the integrated divergence.

    Euler gives y=(1+hγ)zy=(1+h\gamma)z, which is invertible precisely when 1+hγ≠01+h\gamma\ne0. Its correct density is

    qEuler(y)=qb ⁣(y1+hγ)∣1+hγ∣−d.q_{\mathrm{Euler}}(y)= q_{\mathrm b}\!\left(\frac{y}{1+h\gamma}\right) |1+h\gamma|^{-d}.

    For ∣hγ∣<1|h\gamma|<1, its log determinant expands as

    dlog⁡(1+hγ)=dhγ−d2h2γ2+O(h3).d\log(1+h\gamma) =d h\gamma-\frac d2h^2\gamma^2+O(h^3).

    Replacing this determinant by dhγd h\gamma while keeping the Euler endpoint mixes two different maps. At 1+hγ=01+h\gamma=0, the Euler map collapses all inputs to a point and has no ordinary density obtained by an invertible change of variables. The exact continuous map remains invertible for every finite real γh\gamma h.

    2. Integrating out a stochastic history

    Let Y0∼N(0,v0)Y_0\sim\mathcal N(0,v_0), Y1=a0Y0+η0Y_1=a_0Y_0+\eta_0 and Y2=a1Y1+η1Y_2=a_1Y_1+\eta_1, with independent centered Gaussian noises of positive variances r0,r1r_0,r_1. Compute the endpoint law. Explain why a product of transition densities is insufficient as an endpoint proposal probability, and derive the extended-path ratio for a chosen target density π(Y2)\pi(Y_2) and normalized backward kernels.

    Solution

    Substitution gives Y2=a1a0Y0+a1η0+η1Y_2=a_1a_0Y_0+a_1\eta_0+\eta_1. Hence

    Y2∼N(0,v2),v2=a12(a02v0+r0)+r1.Y_2\sim\mathcal N(0,v_2),\qquad v_2=a_1^2(a_0^2v_0+r_0)+r_1.

    Its density is the joint density

    Q(y0,y1,y2)=N(y0;0,v0)N(y1;a0y0,r0)N(y2;a1y1,r1)Q(y_0,y_1,y_2)= \mathcal N(y_0;0,v_0) \mathcal N(y_1;a_0y_0,r_0) \mathcal N(y_2;a_1y_1,r_1)

    integrated over y0,y1y_0,y_1. At the same fixed y2y_2, changing y0y_0 or y1y_1 changes the product, while the endpoint density remains N(y2;0,v2)\mathcal N(y_2;0,v_2).

    Choose normalized F1(y1∣y2)F_1(y_1\mid y_2) and F0(y0∣y1)F_0(y_0\mid y_1). The joint target P=π(y2)F1(y1∣y2)F0(y0∣y1)P=\pi(y_2)F_1(y_1\mid y_2)F_0(y_0\mid y_1) has marginal π\pi. Therefore P/QP/Q is the valid extended weight. With known normalized densities, EQ[(P/Q)O(Y2)]=EπO\mathbb E_Q[(P/Q)O(Y_2)]=\mathbb E_\pi O whenever the integral exists. Replacing an unknown normalization by a ratio of empirical weighted sums introduces finite-sample ratio bias, even though the large-sample limit is correct under integrability.

    Finally, if an unbiased log-density approximation adds σZ\sigma Z, Gaussian integration gives EeσZ=eσ2/2\mathbb E e^{\sigma Z}=e^{\sigma^2/2}. Exponentiation therefore changes its expectation. A noisy log estimate cannot be treated as an exact endpoint or path density merely because its noise has zero mean.

    References

    • Song, Yang, Jascha Sohl-Dickstein, Diederik P. Kingma, Abhishek Kumar, Stefano Ermon and Ben Poole. “Score-Based Generative Modeling through Stochastic Differential Equations.” arXiv:2011.13456v2, HTML (2021), §4.3 and Appendix D.1–D.2, Eqs. (35)–(40).
    • Wu, Hao, Jonas Köhler and Frank Noé. “Stochastic Normalizing Flows.” arXiv:2002.06707v3, HTML (2020), §2, Eqs. (8)–(16), especially the endpoint marginal, path ratio and Theorem 1; §3 for stochastic transition implementations.

    Scrollable formula. Use Left and Right arrow keys to reveal hidden content.

    Scrollable table. Use Left and Right arrow keys to reveal hidden columns.

    Scrollable figure. Use Left and Right arrow keys to reveal hidden content.