feat(mdn): implement transform_to_unconstrained z-scoring for MDN#1888
Conversation
|
@janfb please review at your convenience thanks! |
|
Thanks for picking this up, @BHARATH0153! I suggest to split this into two PRs, because the two halves are at very different stages: 1. MDN: The structure is clean, 2. Vector field (deferred). Please drop the vector-field changes from this PR for now. I checked it locally and it currently crashes at sampling, and more importantly it overlaps with #1884 (composed standardization for scale-equivariant FMPE/NPSE), which changes the same standardization path. I'm assigned to #1885 and will take the VF part myself once #1884 is settled and the ODE-space design is worked out. So overall, please trim this PR to MDN-only with the fix + a test below, and we can get it in. Thanks again, this is a useful contribution! |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #1888 +/- ##
==========================================
- Coverage 87.90% 87.86% -0.04%
==========================================
Files 143 143
Lines 13366 13387 +21
==========================================
+ Hits 11749 11763 +14
- Misses 1617 1624 +7
Flags with carried forward coverage won't be shown. Click here to find out more.
|
janfb
left a comment
There was a problem hiding this comment.
Thanks again for the PR @BHARATH0153 . Here the inline review.
Please revert all changes to the vector field related methods. And please revert the removed docstrings. The remaining todos are variable naming and testing issues, and the jac summing bug.
Looking forward to your fixes!
|
@janfb thanks for the review by today 12 I will make all changes as per review thanks for the review again |
- Add prior_transform parameter to MixtureDensityEstimator - Implement log_prob Jacobian correction and sample inverse transform - Wire transform_to_unconstrained in build_mdn via mcmc_transform - Fix double-sum bug in _log_det_jacobian_forward - Rename parameter to prior_transform (distinct from transform_input) - Add test for MDN transform_to_unconstrained correctness - Add x_dist as explicit parameter to build_mdn
|
@janfb as requested all changes are done please review thanks! |
|
@janfb please rerun the checks all are resolved thanks! |
|
Thanks for the quick quixes, @BHARATH0153! The MDN estimator itself now looks right: the Jacobian fix is correct (I verified When reviewing this again I found two two more blocking bugs, both from the same root cause: the PR changes two things that the MDN shares with the NPE-A / NPE-C machinery, without updating the other side. They don't show up in the diff because the broken code is in files the PR doesn't touch. Details inline, summary here:
The reason bug 2 hides is that the analytic NPE-A / NPE-C correction is mathematically only valid for an affine z-score, it can't represent a nonlinear So, I'd suggest:
More generally, this is now reaching into the NPE-A/NPE-C correction internals, which is a bit beyond where I wanted this PR to go. Do let me know if you prefer that I implement those fixes, I can commit to your branch. |
|
@janfb done I implemented once re check please at your convenience and please commit if anything going wrong and thanks for the great review |
janfb
left a comment
There was a problem hiding this comment.
Thanks again @BHARATH0153 , I made specific suggestions to fix the new bugs. let me know how it goes.
@BHARATH0153 you were too fast, I posted my inline comments just know and I suggest to not use a new property, but just raise an error in the caller sites. |
|
@janfb sorry I had terrible network and trying to do fast by the data finish and two comments are adressed dint used a new property sorry for using before |
|
@janfb now all tests are passing tested locally |
janfb
left a comment
There was a problem hiding this comment.
Converging! one last fix and we are good to merge @BHARATH0153 🚀
|
@janfb done please check thanks! |
janfb
left a comment
There was a problem hiding this comment.
All good, well done @BHARATH0153! First PR merged 🎉
Summary
Remove all vector field estimator changes from this PR. Keep only the
transform_to_unconstrainedz-scoring for MDN.Changes
MixtureDensityEstimator: Addedprior_transformparameter for change-of-variables viamcmc_transform.log_probincludes the Jacobian correction (log_prob(z) + log|det J⁻¹|).sampleapplies the inverse transform to map back to constrained space. The mutual-exclusion guardtransform_input↔prior_transformensures only one is active.build_mdn: Wiresprior_transform = mcmc_transform(x_dist)whenz_score_x="transform_to_unconstrained". Addedx_distas explicit parameter._log_det_jacobian— theIndependentTransform(reinterpreted_batch_ndims=1)already sums over the event dimension, so the explicit.sum(dim=-1)was duplicating the sum.input_transform→prior_transformto avoid confusion with the existingtransform_inputparameter.has_input_transform,_transform_input,_inverse_transform_input,_log_det_jacobian_forward.TorchTransformfromsbi.sbi_types.test_mdn_transform_to_unconstrainedthat tests the change-of-variables formula directly against the underlying MoG.Closes #1885
The VF estimator changes will be pursued in a separate PR by @janfb