Repository navigation
fix: MoG.condition for free dims after fixed dims - #2039
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Merge Risk: ⚪ Minimal · up to
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2039 +/- ##
==========================================
- Coverage 89.84% 89.71% -0.14%
==========================================
Files 142 142
Lines 14680 15783 +1103
==========================================
+ Hits 13189 14159 +970
- Misses 1491 1624 +133
Flags with carried forward coverage won't be shown. Click here to find out more.
|
dgedon
left a comment
There was a problem hiding this comment.
Math checks out. Two non-blocking suggestions inline.
…r complement The analytic test only checked sign-invariant quantities, so dropping the sign flip after QR (with abs() in the weights) passed while cond_mog.log_prob returned NaN. Assert a positive factor diagonal and compare log_prob with the analytic mixture. Note in condition() that R_yy^T R_yy is the marginal precision of y (Schur complement), not the yy-block of P.
Summary
MoG.conditiongave wrong conditional means, covariances and mixture weights when a free dimension comes after a fixed one. It took sub-blocks of the upper-triangular precision factor U. That is only exact when all free dims come before all fixed dims. Now it reorders the columns of U to (free, fixed) and makes the factor triangular again with a QR decomposition. Then the sub-blocks are exact again.ConditionedMDNcallsMoG.conditionsince #2026, so this also fixes conditioned MDN posteriors, also when they are passed toconditional_pairplotorconditional_corrcoeff.Evidence
New test
TestMoGCondition::test_condition_matches_analytic_gaussian. It compares the conditional means, covariances (from the precisions and from the factors) and log-weights with the analytic Gaussian conditional. D=4, K=3, batch size 2, float64.[0]passes.[1],[2]and[1, 3]fail. The max errors are up to 18 in the means, 5.8 in the covariances and 19 in the log-weights.Merge Danger
Door: two-way
Blast Radius: results
The fix changes results without a warning when a free dim comes after a fixed dim and the components are correlated. Conditioned MDN samples, densities and plots then differ from before. Before, they were wrong. Other layouts give the same results as before, up to rounding.
Closes #2038
Written with the help of Claude Code, reviewed locally with GPT Sol 6.1.