Skip to content

Graph-level prior samplers and a progress bar for the correction-table build#161

Merged
MaartenMarsman merged 2 commits into
developfrom
feat/prior-samplers-stage1
Jul 6, 2026
Merged

Graph-level prior samplers and a progress bar for the correction-table build#161
MaartenMarsman merged 2 commits into
developfrom
feat/prior-samplers-stage1

Conversation

@MaartenMarsman

Copy link
Copy Markdown
Collaborator

What this adds

Two new functions for drawing from the graph level of the edge-selection prior, and a cleaner experience when a fit has to build the correction table.

New functions

  • sample_graph_prior() — draws edge-inclusion indicators, and any edge-prior hyperparameters, directly from the prior. Exact draws under the hierarchical specification; a zero-data prior chain under the joint specification.
  • sample_sbm_prior() — draws block memberships and pair-inclusion probabilities from the stochastic-block edge prior.

Correction-table build experience

  • Shows a progress bar while the table is built, matching the sampler's own bar. It follows display_progress, so it shows up whenever the sampling bar would.
  • Only announces the build when it actually runs; a cached table is silent. The message notes the build is one-time and cached.
  • The build can use several cores. bgm()'s cores argument now documents this: sampling uses min(cores, chains), while the correction-table build uses all cores.

Fix

  • A test helper set bgms.verbose = FALSE at load time, which silenced messages and progress bars in sessions loaded with devtools::load_all(). Moved to the test setup only, so it no longer leaks into interactive use.

Testing

  • New tests for both prior samplers and for the parallel correction-table build.
  • R CMD check --as-cran clean apart from the usual environmental notes.

sample_graph_prior() draws edge indicators and edge-prior
hyperparameters from the graph level of the spike-and-slab prior. The
hierarchical specification samples ancestrally (hyperparameters from
their prior, then independent pair flips), which is exact. The joint
specification runs the zero-data prior chain and discards the precision
draws, so the returned graphs carry the per-graph normalizer tilt and
the hyperparameter updates apply the normalizing-constant correction.
Hyperparameters can be fixed instead of sampled: theta for Bernoulli
and Beta-Bernoulli priors, allocations plus block_probs for the
Stochastic-Block prior.

sample_sbm_prior() draws block allocations and pair-inclusion
probabilities ancestrally from the MFM-SBM hyperprior, wrapping the
internal helpers that until now only initialized the joint chain.

The correction-table build message printed before the cache check, so
every fit read 'building or loading' even when the table loaded
instantly. The message now prints only on an actual build, states that
the build is one-time and cached, and the sweep reports progress: a
progress bar on one core, a cell-and-core count when parallel.

Stage 1 of the prior-sampler redesign
(dev/plans/active/2026-07-06_prior-sampler-redesign_DESIGN.md).
Gate the build progress bar on display_progress (the sampler's own
control) instead of bgms.verbose, and draw it for both serial and
parallel builds; a parallel build advances the bar as each batch of
forked chains completes. The build announcement stays on bgms.verbose.

Remove the top-level options(bgms.verbose = FALSE) from
helper-fixtures.R so devtools::load_all no longer silences fit-time
output in development sessions; setup.R still quiets the test run.

Document the cores contract in bgm(): sampling uses min(cores, chains),
while computations outside sampling (the correction-table build) use
all cores.
@codecov

codecov Bot commented Jul 6, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 86.88525% with 32 lines in your changes missing coverage. Please review.
✅ Project coverage is 91.05%. Comparing base (cef30b8) to head (8791690).

Files with missing lines Patch % Lines
R/correction_tables.R 78.57% 18 Missing ⚠️
R/sample_graph_prior.R 91.13% 14 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop     #161      +/-   ##
===========================================
- Coverage    91.13%   91.05%   -0.08%     
===========================================
  Files          103      104       +1     
  Lines        14515    14748     +233     
===========================================
+ Hits         13228    13429     +201     
- Misses        1287     1319      +32     

☔ 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 f39927f into develop Jul 6, 2026
7 of 9 checks passed
@MaartenMarsman MaartenMarsman deleted the feat/prior-samplers-stage1 branch July 6, 2026 13:10
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