Skip to content

refactor(mixed): log_ggm_ratio_* delegate the det-lemma to log_det_ratio_yy_*#136

Merged
MaartenMarsman merged 1 commit into
mainfrom
refactor/mixed-logdet-ratio-dedup
Jun 4, 2026
Merged

refactor(mixed): log_ggm_ratio_* delegate the det-lemma to log_det_ratio_yy_*#136
MaartenMarsman merged 1 commit into
mainfrom
refactor/mixed-logdet-ratio-dedup

Conversation

@MaartenMarsman

Copy link
Copy Markdown
Collaborator

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 in log_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 in log_ggm_ratio_edge/_diag with a call to the canonical log_det_ratio_yy_edge/_diag helper.

log_ggm_ratio_* still computes Ui/Uj locally, 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 identical Ui/Uj from 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:

  • edge selection, delta = 0
  • no edge selection, delta = 0
  • no edge selection, delta = 1 (exercises the determinant_tilt_yy_ path)

identical(main, refactor) == TRUE for all three. Harness: dev/bitwise_mixed_logdet_ratio.R.

…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

codecov Bot commented Jun 4, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 50.00000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 87.64%. Comparing base (7b32aa0) to head (b993f45).

Files with missing lines Patch % Lines
src/models/mixed/mixed_mrf_metropolis.cpp 50.00% 1 Missing ⚠️
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@MaartenMarsman MaartenMarsman merged commit 44efd57 into main Jun 4, 2026
8 of 10 checks passed
@MaartenMarsman MaartenMarsman deleted the refactor/mixed-logdet-ratio-dedup branch June 4, 2026 13:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant