G2 Correlation Function Theory¶
This page explains the theoretical background of the G2 autocorrelation function, the primary observable in XPCS experiments, and how XPCS Viewer models and fits it.
Physical Background¶
In an XPCS experiment, coherent X-rays scattered from a sample produce a speckle pattern on the detector. As the sample evolves (particles diffusing, domains relaxing, etc.), the speckle pattern fluctuates. The intensity autocorrelation function quantifies these temporal fluctuations:
where:
\(I(q, t)\) is the scattered intensity at wavevector \(q\) and time \(t\)
\(\tau\) is the delay time (lag)
\(\langle \cdot \rangle_t\) denotes a time average over frames
The \(g_2\) function is computed per Q-bin from the detector pixel data and the Q-map partition.
Siegert Relation¶
The intensity autocorrelation \(g_2\) is related to the field autocorrelation \(g_1\) via the Siegert relation:
where \(\beta\) is the speckle contrast (or coherence factor), which depends on the optical setup (beam coherence, pixel-to-speckle size ratio, etc.). In practice, \(\beta \in [0, 1]\) and is treated as a fit parameter.
Fitting Models¶
XPCS Viewer provides several functional forms for fitting \(g_2(\tau)\).
All models share the parameterization convention where baseline
corresponds to the long-time limit (typically 1.0) and contrast
corresponds to the Siegert \(\beta\) factor.
Single Exponential¶
The simplest and most common model, appropriate for simple diffusive dynamics:
where \(\tau_c\) is the characteristic relaxation time. The factor of 2 comes from the Siegert relation (\(|g_1|^2\) squares the field correlation, doubling the decay rate).
Note
The implementation uses jnp.clip(tau, 1e-30) to prevent numerical
instability when the optimizer samples near \(\tau_c = 0\).
Physical interpretation: \(\tau_c \propto 1 / (D q^2)\) for Brownian diffusion, where \(D\) is the diffusion coefficient. Plotting \(\tau_c\) vs. \(q\) (tau-Q analysis) extracts the scaling exponent.
Double Exponential¶
For systems with two distinct relaxation processes:
This model captures bimodal dynamics (e.g., fast cage rattling and slow structural relaxation in glassy systems).
Stretched Exponential (KWW)¶
The Kohlrausch-Williams-Watts (KWW) function models heterogeneous dynamics:
where \(\beta \in (0, 1]\) is the stretching exponent:
\(\beta = 1\): simple exponential (monodisperse dynamics)
\(\beta < 1\): stretched decay (broad distribution of relaxation times)
\(\beta > 1\): compressed exponential (ballistic or stress-driven dynamics)
Two-Stage Fitting Pipeline¶
XPCS Viewer uses a two-stage approach for fitting \(g_2\) data:
Stage 1: Point Estimates (NLSQ)
NLSQ 0.6.0 performs nonlinear least squares optimization to obtain fast
point estimates (\(\hat{\tau}_c\), \(\hat{\beta}\), etc.) along
with a covariance matrix. The native CurveFitResult provides R-squared,
AIC, BIC, prediction intervals, and model health diagnostics.
Stage 2: Bayesian Inference (NumPyro NUTS)
The NLSQ point estimates serve as a warm start for the No-U-Turn Sampler (NUTS), a Hamiltonian Monte Carlo algorithm implemented in NumPyro. NUTS explores the full posterior distribution over parameters, providing:
Credible intervals (not just confidence intervals)
Model comparison via Bayesian information criteria
Diagnostics for convergence (R-hat, ESS, BFMI)
The Bayesian models use weakly informative priors:
Parameter |
Prior |
Rationale |
|---|---|---|
\(\tau_c\) |
LogNormal(0, 2) |
Positive, broad, spans many decades |
baseline |
Normal(1.0, 0.1) |
Close to 1 for normalized \(g_2\) |
contrast |
HalfNormal(1.0) |
Positive, typically 0–0.5 |
\(\sigma\) |
HalfNormal(0.1) |
Observation noise (when errors not provided) |
Convergence Diagnostics¶
After NUTS sampling, XPCS Viewer checks five convergence diagnostics via ArviZ:
Diagnostic |
Threshold |
Meaning |
|---|---|---|
R-hat |
< 1.01 |
All chains converge to the same distribution |
ESS bulk |
> 400 |
Sufficient effective samples for mean/variance |
ESS tail |
> 400 |
Sufficient effective samples for quantiles |
Divergences |
= 0 |
No divergent transitions (pathological geometry) |
BFMI |
>= 0.2 |
Adequate energy exploration in Hamiltonian dynamics |
A fit is considered converged only when all five criteria are satisfied.
Failed diagnostics are reported in the FitDiagnostics object attached
to each FitResult.
Model Selection¶
When multiple models (single exponential, double exponential, KWW) are fit to the same data, XPCS Viewer supports model comparison via:
AIC (Akaike Information Criterion): Balances goodness of fit against model complexity. Lower is better.
BIC (Bayesian Information Criterion): Similar to AIC but with a stronger penalty for extra parameters. Preferred for large datasets.
R-squared: Coefficient of determination. Useful for quick assessment but does not penalize complexity.
These metrics are available directly from the NLSQResult object, which
delegates to NLSQ 0.6.0’s native CurveFitResult properties.