Repository navigation
Add approximate (MCMC) sampling with the tie/no-tie sampler - #33
Merged
Merged
Conversation
Model::sample_approx() draws arrays with Metropolis-Hastings using the tie/no-tie (TNT) proposal, so it does not need the support or store_psets(). The chain state (array, running sufficient statistics, free cells, current ties) persists across calls in SampleApproxState, statistics are updated only through change statistics, and an optional stats_out pointer streams model-scale statistics every `thin` proposals. This is the basis for MCMC-MLE and stochastic approximation. - TNT acceptance includes the proposal ratio (as in ergm's MH_TNT). - Supports nonlinear model transformations and dynamic rules. - DEFM::simulate_approx() wraps it; simulate() now shares its loop. - Tests compare chain means with exact expectations (sparse and dense regimes, sparse and dense arrays, transformed model), check persistence and incremental stats, dynamic rules, and DEFM. - Docs: doc/sample-approx.md (published under Implementation). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Version bump check ✅
Checked 1 group(s) against |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #33 +/- ##
==========================================
+ Coverage 89.54% 90.39% +0.85%
==========================================
Files 46 46
Lines 3262 3395 +133
==========================================
+ Hits 2921 3069 +148
+ Misses 341 326 -15 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
gvegayon
commented
Oct 28, 2026
Cells locked by the static rules keep their values from the starting array, as in the exact support used by sample(). Rejecting non-zero locked cells would break DEFM, whose locked Markov rows are generally non-zero. Adds a test showing that the exact and approximate samplers both keep a locked diagonal tie, and documents the behavior. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
7 tasks
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.
Summary
Adds
Model::sample_approx(), which draws arrays with Metropolis–Hastings and the tie/no-tie (TNT) proposal. It never computes the support and does not needstore_psets(). It is designed as the basis for simulation-based estimation (MCMC-MLE and stochastic approximation) in a later release.SampleApproxStateholds the current array, its running raw statistics, the free cells and the current ties. Each call resumes the chain, and θ can change between calls.stats_outis not null, they are appended everythinproposals, on the scale ofget_stats_target()(after any transform).MH_TNT. With probability ½ a random tie is proposed for removal; otherwise a random free cell is toggled. Acceptance includes the proposal ratio q(y′→y)/q(y→y′). Without it, the chain converges to the wrong distribution.SampleApproxMethod(onlytntfor now).DEFM::simulate_approx().simulate()now shares the same loop and behaves as before.doc/sample-approx.md, published under Implementation.barry.hppanddefm.hppare regenerated.Tests
NetworkandNetworkDense, and a model with a nonlinear transform. Removing the proposal correction makes these checks fail (errors of 36–96%).paramslength throws.simulate_approxreproduces the deterministic torus walk (test 20) and matches the analytic marginal rate.make test-portablepasses (194 assertions in 26 test cases). Valgrind and the MkDocs build were not run locally, because valgrind and Doxygen are not installed.Out of scope
conditional_probhandle nonlinear transforms🤖 Generated with Claude Code