Manuscript Offprint

arXiv:2608.22807

Change Detection in Probability Flow ODE: Online Testing in Diffusion Latent Spaces

Artem Kraevskiy, Artem Prokhorov

Abstract

A rapidly growing range of sequential data tasks, such as identifying trend reversals in financial markets, auto-segmenting video and audio recordings, detecting changes in movement direction from motion sensors cannot be fully addressed without detection of distributional shifts in time-ordered data. We consider a sequential change-point detection problem where the conditional density switches at an unknown time, yet neither the pre- nor post-change distribution admits a closed-form. Classical likelihood-ratio statistics are inapplicable in this settings.

A conditional diffusion model, trained on pre-change-point data with a frozen context encoder, defines a deterministic bijection via the probability flow ODE. Pre-change observations are mapped onto standard Gaussian latent variables. Post-change observations, processed through the same frozen map, deviate from this reference. We employ the Maximum Mean Discrepancy as the test statistic, derive closed-form expressions for its components under the Gaussian null, and establish its asymptotic distribution as a degenerate U-statistic. Afterwards we apply an online detection procedure of Shiryaev–Roberts to the resulting statistic with exact threshold calibration.

The method detects arbitrary distributional shifts, including covariance rotations and higher-order structural breaks, without parametric assumptions on either regime.

Keywords: Change-point, diffusion models, PF-ODE, U-statistic, Shiryaev–Roberts statistic, optimal stopping rules, concept drift.

Preprint.

1 Problem Formulation

Let (Xt)t≥1(X_t)_{t \geq 1}, Xt∈RdX_t \in \mathbb{R}^d, be an observed sequence and let Ft=σ(X1,…,Xt)\mathcal{F}_t = \sigma(X_1, \ldots, X_t) denote its natural filtration. Fix a look-back window l≥1l \geq 1 and let ht−1∈Rm\mathbf{h}_{t-1} \in \mathbb{R}^m be a summary of the history Xt−l,…,Xt−1X_{t-l}, \ldots, X_{t-1} produced by a causal encoder (e.g. GRU, Transformer encoder, MLP, etc.), with h0=0\mathbf{h}_0 = 0.

Let θ∈N\theta \in \mathbb{N} be an unobservable change-point, independent of F∞\mathcal{F}_\infty and distributed geometrically, P(θ=k)=(1−ρ)k−1ρ,ρ∈(0,1)\mathbb{P}(\theta = k) = (1 - \rho)^{k-1} \rho, \rho \in (0,1). The conditional distribution of XtX_t given Ft−1\mathcal{F}_{t-1} is

Xt∣Ft−1∼{p0(⋅∣ht−1)t<θ,p1(⋅∣ht−1)t≥θ,(1)X_{t}\mid\mathcal{F}_{t-1}\sim\begin{cases}p_{0}(\cdot\mid\mathbf{h}_{t-1})&t<\theta,\\p_{1}(\cdot\mid\mathbf{h}_{t-1})&t\geq\theta,\end{cases} \tag{1}

where p0(⋅∣h)p_0(\cdot \mid \mathbf{h}) and p1(⋅∣h)p_1(\cdot \mid \mathbf{h}) are families of absolutely continuous conditional densities with p0≠p1p_0 \neq p_1. Neither density is assumed to have a known analytic form.

Shiryaev (1963) and Roberts (1966) showed that, for the Bayes risk

R(τ)=cE[(τ−θ)+]+P(τ<θ),c>0,\mathcal{R}(\tau)=c\mathbb{E}[(\tau-\theta)^{+}]+\mathbb{P}(\tau<\theta),\qquad c>0,

trading off detection delay against the false-alarm probability, the rule minimising R(τ)\mathcal{R}(\tau) over stopping times τ\tau has the form: τ∗=inf⁡{t:πt≥π∗}\tau^* = \inf\{t : \pi_t \geq \pi^*\}, where πt=P(θ≤t∣Ft)\pi_t = \mathbb{P}(\theta \leq t \mid \mathcal{F}_t) is the posterior change-point probability and π∗\pi^* is determined by a free-boundary problem (Peskir and Shiryaev (2006)). Computing πt\pi_t requires the conditional log-likelihood ratio log⁡[p1(Xt∣ht−1)p0(Xt∣ht−1)]\log \left[\frac{p_1(X_t \mid \mathbf{h}_{t-1})}{p_0(X_t \mid \mathbf{h}_{t-1})}\right], which is intractable whenever the densities p0p_0 and p1p_1 are unknown.

Another crucial factor that makes the direct application of the Shiryaev-Roberts approach impractical is the curse of dimensionality. Classical approaches to multivariate PDF estimation (kNN, tree-based algorithms, KDE, etc.) suffer even when the dimensionality is moderately large. Furthermore, it may be difficult to consider various domain-specific aspects for empirical distributions such as heavy-tails and tail-dependence in financial time series or sparsity of images in video frame sequences.

We address this problem by applying a trained Probability Flow ODE (PF-ODE) generative model (Song et al., 2021b) – trained by denoising score matching against the conditional Stein score (Appendix I) – as a conditional encoder that, provided the model is well trained, deterministically maps 1^{1} a complex, unknown multivariate PDF in the original data domain to a latent space following N(0,I)\mathcal{N}(0, I), and back again. If the current data XtX_t comes from the same distribution as its previous values (aggregated into the embedding ht−1\mathbf{h}_{t-1}) then the corresponding latent variable ztz_t will follow this standard normal distribution. If the distribution has changed, the projection into latent space will no longer follow N(0,I)\mathcal{N}(0, I).

In this sense, we want to test the hypothesis that the distribution of latent variables is N(0,I)\mathcal{N}(0, I). The moment when we reject this hypothesis would be considered a change-point.

The paper proceeds as follows. First, we derive a formula for maximum mean discrepancy (MMD) against a Gaussian alternative and find its asymptotic distribution. Second, we apply the Shiryaev-Roberts approach and describe an algorithm for finding the optimal threshold π∗\pi^{*}. Finally, we apply the proposed approach to synthetic and real-world data.

References (77)

  • Reverse-time diffusion equation models
  • Theory of reproducing kernels
  • Layer Normalization
  • Learning phrase representations using RNN encoder–decoder for statistical machine translation
  • Density estimation using Real NVP. In International Conference on Learning Representations (ICLR)
  • Sigmoid-weighted linear units for neural network function approximation in reinforcement learning
  • A kernel two-sample test
  • Central limit theorem for integrated square error of multivariate nonparametric density estimators
  • Denoising diffusion probabilistic models
  • Classifier-Free Diffusion Guidance
  • A class of statistics with asymptotically normal distribution
  • The generalization of student's ratio
  • Estimation of non-normalized statistical models by score matching
  • Adam: A method for stochastic optimization
  • Glow: Generative flow with invertible 1x1 convolutions
  • Gradient-based learning applied to document recognition
  • A kernelized Stein discrepancy for goodness-of-fit tests
  • Continuous inspection schemes
  • FiLM: Visual reasoning with a general conditioning layer
  • Minimax and pointwise sequential changepoint detection and identification for general stochastic models
  • Optimal Stopping and Free-Boundary Problems
  • Optimal detection of a change in distribution
  • Gaussian Processes for Machine Learning
  • A comparison of some control chart procedures
  • Progressive distillation for fast sampling of diffusion models
  • On optimum methods in quickest detection problems
  • A Hilbert space embedding for distributions
  • Denoising diffusion implicit models
  • Generative modeling by estimating gradients of the data distribution
  • Score-based generative modeling through stochastic differential equations
  • Hilbert space embeddings and metrics on probability measures
  • Estimation of the mean of a multivariate normal distribution
  • Sequential Analysis: Hypothesis Testing and Changepoint Detection
  • General asymptotic bayesian theory of quickest change detection
  • A connection between score matching and denoising autoencoders
  • EDICT: Exact diffusion inversion via coupled transformations
  • Gaussian regression and optimal finite dimensional linear models
  • Hence $P = P'$
  • the same $X_t$ can be encoded into different latent codes across runs, and no measurable inverse exists
  • The kernel factorises over dimensions:
  • Expanding in the exponent:
  • On the diagonal, $k(Z_i, Z_i) = k_0 := k(z, z)$, a constant for any stationary kernel (for the RBF kernel, $k_0 = 1$ regardless of $z$); the $w$ diagonal terms contribute $k_0/w$
  • V-statistic
  • The unbiased estimator is then a degree-2 U-statistic with kernel $\tilde{k}$:
  • by the tower property, for each pair $i \neq j$
  • For a first-order degenerate U-statistic the leading Gaussian term vanishes identically, and the fluctuation is of order 1/w
  • Define the integral operator $T_{\tilde{k}} : L^2(P_0) \to L^2(P_0)$:
  • The degeneracy condition forces all eigenfunctions $\phi_l$ to satisfy $\mathbb{E}_{P_0}[\phi_l(Z)] = 0$ (zero mean), with $\text{Var}[\phi_l(Z)] = 1$ by normalisation
  • The orthogonality $\mathbb{E}[\phi_l(Z)\phi_m(Z)] = \delta_{lm}$ implies $S_l \perp S_m$ asymptotically for $l \neq m$
  • The limit belongs to the class of generalised $\chi^{2}$ distributions (infinite weighted sums of centred $\chi^{2}(1)$ variables), for which no closed-form CDF exists
  • The ladder structure of the Hermite/harmonic-oscillator basis propagates this ratio to every mode: writing the (unnormalised) eigenfunctions as weighted Hermite functions
  • sample $Z_{1},\ldots,Z_{w}$ drawn from a common law $-P_{0}$ under $H_{0}$, $P_{1}$ under $H_{1}$ – the U-statistic $U_{w}=\frac{1}{w(w-1)}\sum_{i \neq j} h(Z_{i},Z_{j})$ admits the orthogonal Hoeffding (1948) decomposition:
  • Substituting into the centered statistic:
  • Under the null $P_0=Q$, the first-order projection evaluates to:
  • from $P_{1}\neq Q$, with signal strength $\delta^2=\mathrm{MMD}^2(P_1,Q)>0$ taking the role of $\mu$
  • Let $\sigma_1^2 = \mathrm{Var}_{Z \sim P_1}[h_1(Z)] > 0$
  • This contributes at rate $O_p(w^{-1/2})$
  • By Slutsky's theorem the degenerate term is asymptotically negligible, giving:
  • Averaging this Gaussian density over the exponential prior $\pi(\delta^2) = \alpha e^{-\alpha\delta^2}$, $\delta^2 > 0$, gives the marginal (mixture) density
  • Section 1 shows that $\delta^2$ itself never needs to be estimated – the mixture already averages over it – but $(\alpha, v_1)$ still have to be fixed somehow before the mixture can be evaluated at all
  • a mean shift, a covariance rotation, an inflated tail, etc.) when no real post-change instance has yet been observed
  • The threshold-crossing rule $\tau_A = \inf\{t : R_t \geq A\}$ becomes the equivalent, equally exact rule
  • smooth-fit
  • their (22.1.2) and (24.1.16)):
  • Repeating this for a range of c traces out the achievable delay/false-alarm frontier
  • By the same one-step decomposition as above (now with running cost $\equiv 1$ per window rather than $c\Pi_{k}$, and no minimisation – the rule is already fixed as a threshold crossing, so this is a linear first-passage problem, not a variational one)
  • The threshold is then the value of $b$ (equivalently $A=b/(1-b)$) solving
  • Encoding each $X_i$ requires solving the PF-ODE and is the dominant cost; everything downstream $-\widehat{\text{MMD}}_n^2$, $\Lambda_n^\pi$, $R_n$ – is closed-form arithmetic on $w$ numbers
  • Anderson (1982) shows this process can be run backward in time with the same marginals $p_{\tau}(\cdot \mid \mathbf{h})$ at every $\tau$, via the reverse-time SDE
  • 1) show a deterministic ODE sharing the very same marginals exists, obtained by discarding the stochastic term while halving the score coefficient:
  • \mathbb{R}^d \to \mathbb{R}^d$ vanishing at infinity, integration by parts gives Stein (1981)'s identity
  • This implicit score-matching objective is, however, not what Algorithm 1 trains with: $\text{tr}(\nabla_x s_\theta)$ requires the full Jacobian of the network, one backward pass per output coordinate, which is infeasible at the dimension used in Section 5 ($d = 256$)
  • $\eta$ is simulated directly, and $\hat{\varepsilon}_{\theta}$ is trained by ordinary backpropagation of a mean-squared error
  • This appendix fixes the two instantiations actually used, in Section 4 and Section 5 respectively – both trained once, with no architecture search
  • $h \leftarrow h + \left[\text{SiLU}(\text{Linear}(\text{LayerNorm}(h))\right) \odot (1 + \text{scale}) + \text{shift}$
  • itself would have access to at that point. The one exception, applied identically to
  • †: the MNIST column shows the corrected recipe used to produce Table 1 and the convergence study of Section 6 – hidden width 512, 8 denoiser blocks, learning rate $10^{-4}$ with gradient-norm clipping at 1, no CFG dropout, 120,000 steps, full 999-step DDIM budget