refactor(mixed): log_ggm_ratio_* delegate the det-lemma to log_det_ratio_yy_*#136
Merged
Merged
Conversation
…tio_yy_* The rank-2 (edge) and rank-1 (diag) matrix-determinant-lemma blocks were duplicated: once in log_det_ratio_yy_edge/_diag and again inline in log_ggm_ratio_edge/_diag, so the det-lemma appeared 4x within the mixed model (the cross-model drift smell flagged in the class-design review). Replace the inline cc11/cc12/cc22 + MY_LOG(abs(...)) blocks with a call to the canonical log_det_ratio_yy_* helper. log_ggm_ratio_* still computes Ui/Uj locally because the Woodbury / Sherman- Morrison covariance update below reuses them; only the log-det sub-block is delegated. log_det_ratio_yy_* recomputes the identical Ui/Uj from the same -2*pairwise_effects_continuous_ entries, so the returned ratio is unchanged. Verified bitwise: adaptive-Metropolis mixed-MRF raw draws (edge-sel delta=0, no-edge delta=0, no-edge delta=1) digest-identical pre/post.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #136 +/- ##
==========================================
- Coverage 87.67% 87.64% -0.03%
==========================================
Files 87 87
Lines 12897 12889 -8
==========================================
- Hits 11307 11297 -10
- Misses 1590 1592 +2 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
What
The rank-2 (edge) and rank-1 (diag) matrix-determinant-lemma blocks were duplicated within the mixed model: once in
log_det_ratio_yy_edge/_diag, and again inline inlog_ggm_ratio_edge/_diag. That is the det-lemma appearing 4× — the cross-model drift smell flagged in the class-design review (the GGM/Mixed det-lemma divergence).This replaces the inline
cc11/cc12/cc22 + MY_LOG(abs(...))blocks inlog_ggm_ratio_edge/_diagwith a call to the canonicallog_det_ratio_yy_edge/_diaghelper.log_ggm_ratio_*still computesUi/Ujlocally, because the Woodbury (edge) / Sherman-Morrison (diag) covariance update below reuses them — only the log-det sub-block is delegated.Why this is safe
log_det_ratio_yy_*recomputes the identicalUi/Ujfrom the same-2 * pairwise_effects_continuous_entries (-2*scalar== the(-2*matrix)element), so the returned ratio is bit-for-bit unchanged.Verified bitwise: adaptive-Metropolis mixed-MRF raw draws (main + pairwise + indicator) are digest-identical pre/post across three scenarios:
delta = 0delta = 0delta = 1(exercises thedeterminant_tilt_yy_path)identical(main, refactor) == TRUEfor all three. Harness:dev/bitwise_mixed_logdet_ratio.R.