Repository navigation
Goodness-of-fit evaluation: kernel Stein discrepancy + classifier two-sample test - #38
Merged
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.pyshows 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