feat(vfpe): opt-in composed standardization for scale-equivariant FMPE/NPSE (#1680)#1884
feat(vfpe): opt-in composed standardization for scale-equivariant FMPE/NPSE (#1680)#1884test1card wants to merge 3 commits into
Conversation
|
Thanks a lot for this, really nice first contribution @test1card! One pointer before a deeper review: please take a look at #1752 which is more recent than #1681 and changed how A few other things I'll want to look at more closely, at a high level:
I won't be able to do the detailed line-by-line review until July, sorry for that. In the meantime, looking at #1752 and thinking about how the new standardization could reuse the existing |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1884 +/- ##
==========================================
- Coverage 87.89% 87.67% -0.22%
==========================================
Files 143 143
Lines 13353 14488 +1135
==========================================
+ Hits 11736 12703 +967
- Misses 1617 1785 +168
Flags with carried forward coverage won't be shown. Click here to find out more.
|
…E/NPSE FMPE and NPSE posteriors are not equivariant under theta -> c*theta when the parameters are far from O(1): with the default z_score_theta the flow/SDE integrate against a base fixed by the noise process, not the data, while the parameters live at scale s, so calibration collapses as s -> 0. NPE/NLE are unaffected. Add an opt-in, per-dim composed standardization (default off). The estimator trains and samples in z = (theta - mean) / std, with an invertible affine composed at the boundaries; log_prob is corrected by the affine Jacobian. Per-dim statistics have a single source; under composition the internal input normalization is forced to unit, asserted as an invariant. gaussian_baseline and composed standardization are mutually exclusive. Single-observation only: iid / guided / MAP raise NotImplementedError, with a runtime backstop on the iid log_prob path if _x_is_iid is forced directly. Legacy checkpoints load as composition-off; partial-compose checkpoints raise. Tests cover equivariance recovery, default collapse, heterogeneous scales, exact log_prob Jacobian scaling, the compose scope guards, and the direct-force backstop. Flag defaults off; the full non-slow suite passes unchanged.
dabf0e5 to
2f717aa
Compare
|
Thanks! I pushed an updated version of the branch, so the PR now shows the hardened commit rather than the earlier one. The #1752 pointer really helped, it turns out to be the same question as whether the two standardizations are redundant. As far as i understood it correctly, #1752's z-scoring works on the network internally as it z-scores the input and rescales the velocity output. But The update also adds the missing coverage tests and a runtime backstop on the iid log_prob path, plus the edge-case guards on the sampling/loading paths. The bigger scope, opening up the affine iid/guidance/MAP paths by pushing the prior into z-space, is on a separate follow-up branch, not yet finished. I am new to this as you've noticed, so should that follow-up go as its own PR after this one lands, or fold it in here? And i wanted to say sorry because I leaned on LLM assistance a fair amount here, which the contributing guide asks contributors to flag. I went through and tested all of it myself, so if something's wrong it's on me. No rush on the line by line! |
|
Pushed a small follow-up, the Apache license headers on the four new test files. I also noticed that the standardization path that with Could you please recommend what to do with it? I know it has to be fixed, but the scope creep worries me. |
What does this PR do?
FMPE and NPSE amortized posteriors are not equivariant under the exact
reparameterization theta -> c*theta when parameters are far from O(1) scale.
The flow / SDE integrate against a unit base, so calibration degrades for
small-scale parameters despite the default z_score_theta. #1681 addressed only
the z_score_x off-branch, which is a no-op on the default path.
This adds an opt-in per-dimension composed standardization
(
compose_standardization=True). The estimator is trained and sampled in astandardized z-space, with an invertible affine map theta = shift + scale * z
composed at the boundaries:
Per-dimension scaling handles heterogeneous parameter scales (mixed O(1) and
O(1e-6) dimensions). The flag defaults to off; with it off, behavior is
byte-identical to current sbi, and legacy checkpoints load via identity buffers.
MAP raises NotImplementedError in compose mode: the score potential is computed
in z-space, so gradient ascent in theta-space would require a chain-rule
rescaling of the gradient. This is left as a documented follow-up; single-
observation sampling and log_prob are fully supported.
Changes
neural_nets/estimators/base.py: standardization buffers and helpers, legacy-checkpoint shimneural_nets/estimators/flowmatching_estimator.py,score_estimator.py: standardize loss inputinference/posteriors/vector_field_posterior.py: unstandardize samples; guard MAP/iid/guided under composeinference/potentials/vector_field_potential.py: affine Jacobian in log_probneural_nets/net_builders/vector_field_nets.py: opt-in builder kwargtests/test_scale_equivariance.py: homogeneous + heterogeneous equivariance, opt-in-off regressionValidation
Run on an editable install:
covered by tests/test_scale_equivariance.py (homogeneous, heterogeneous).
Does this close any issues?
Relates to #1680. That issue was closed by #1681, but #1681 only touched the
z_score_x off-branch and did not address the default-path scale-equivariance of
FMPE/NPSE; this PR completes that case.
Checklist