Skip to content

Goodness-of-fit evaluation: kernel Stein discrepancy + classifier two-sample test - #38

Merged
davidkhjo merged 4 commits into
mainfrom
goodness-of-fit
Aug 15, 2026
Merged

davidkhjo merged 4 commits into
mainfrom
goodness-of-fit

Conversation

@davidkhjo

Copy link
Copy Markdown
Owner

Goodness-of-fit evaluation

Two GoF metrics that answer questions FID/MMD can't — "does this sample set come from this EBM?" and "can anything tell model from data?" — complementing the sample-vs-sample distances. Both torch-only.

  • kernel_stein_discrepancy (Liu et al. 2016) — a Stein discrepancy that needs only the model score ∇log p = −∇E (no partition function, no samples from the model), using the closed-form RBF Stein kernel. Test: on N(0,I) data, KSD²≈0 for the correct energy and grows with mismatch (a=2 → 0.23); validated in 2D and 5D.
  • classifier_two_sample_test (Lopez-Paz & Oquab 2017) — trains a small MLP to separate two sets, returns held-out accuracy (0.5 = indistinguishable). Test: identical draws → ≈0.5, disjoint → ≈1.0.

Example goodness_of_fit.py shows each where it's sharp: KSD² bottoms out exactly at the true variance (model selection with no samples), and C2ST separates a trained EBM (0.56) from a wrong Gaussian (0.72) on two-moons.

Note: KSD is score-magnitude sensitive — great as a selector between candidate energies, but on a trained neural energy over multimodal data the score errors make it noisy, so the example uses it for the clean model-selection case rather than overselling it.

No version bump — lands under the unreleased 0.13.0 CHANGELOG section.

Verification

ruff + format + mypy clean; 137 tests pass; example runs on CPU.

🤖 Generated with Claude Code

Goodness-of-fit tests that complement the sample-vs-sample distances. KSD (Liu
et al. 2016) asks 'do these samples come from THIS energy?' using only the score
(no partition function), with the closed-form RBF Stein kernel. C2ST (Lopez-Paz
& Oquab 2017) trains a small MLP to tell two sets apart and returns held-out
accuracy (0.5 = indistinguishable). Both torch-only.
@davidkhjo
davidkhjo merged commit 14550f6 into main Aug 15, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant