Repository navigation
feat(ABCShadow): infer the model parameters with the ABC shadow algorithm - #69
Open
francoisbonneau wants to merge 9 commits into
Open
francoisbonneau wants to merge 9 commits into
francoisbonneau wants to merge 9 commits into
Conversation
shadow_step runs nb_proposals Metropolis proposals on theta, whether accepted or not, with the log ratio < theta' - theta, t_obs - t_y > and a uniform prior on a box, on one coordinate or on all of them. The engine is the only source of randomness. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ovariance With t_y frozen during the shadow chain, the outer chain behaves like an unadjusted Langevin chain with h = m delta^2 / 12: stable only if h.P < 4, close to the posterior for h.P ~ 0.2. calibrate_deltas gives delta_i = sqrt( 12 s_eff / ( m_i Cov_ii ) ), with s_eff the step scale divided by a Gershgorin bound on the correlations. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Model::theta_bounds gives, per term, the interval of the valid theta: -inf for a hard-core, at most 0 if the attraction is not integrable, no upper bound otherwise. set_thetas checks the attraction with the same bounds: a single source for the model and the prior box of an inference. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
run_abc_shadow checks the configuration once (known, distinct, non hard-core terms; prior box inside the integrability domain, by default this domain; a finite lower bound when nothing is observed; no fixed objects until the observation rate is constant), calibrates the steps from the covariance of the statistics unless they are given, then runs the outer chain on the context and returns the trace in memory. The model keeps the last theta: a second call continues the chain. Tested on a Poisson process, whose posterior is known. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A Strauss pattern simulated with known parameters gives the observed statistics; the ABC shadow, started elsewhere, finds the parameters within three posterior standard deviations, with a spread consistent with the Fisher information, in both proposal modes. At the posterior mean, the model gives the observed statistics on average: the comparison of the statistics in the domain with a model simulated on the extended domain (option A) is validated. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
docs/statistics.md gives, for each statistic, what it counts, its parameter and its rule at the boundary of the domain, the limits of the measurement on an outcrop, and how to run and tune the ABC shadow. The reference of the algorithm goes to the README. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… documentation A statistic with a tiny variance gave an infinite or zero calibrated step: it is refused, and the correlations are computed without underflow (the correlation of a statistic with itself is exactly 1). AbcShadowConfig and ThetaBounds are documented; docs/statistics.md is aligned with the code (attraction on sets with a hard-core, tolerances of the Poisson test, state after a failed calibration). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ted step The calibration estimates Cov( t ) at the starting theta, which can be far from the posterior. After the run, AbcTrace::estimated_step_scales gives h.P per parameter, with P estimated by Var( t_y ) / 2 over the trace, and a warning is logged above 1 (delta too large, posterior inflated) or below 0.02 (delta too small, slow chain), with the remedy: rerun, which recalibrates at the last theta, or give the deltas. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Review follow-up: - move the means and covariance of samples in memory to geode::statistics::sample_moments, reused by the calibration, the step diagnostic and the tests, and tested on its own - split shadow_step into one proposal function per mode, same draws - compute m_i in a single place - check_theta compares theta with its upper bound directly - remove internal references from messages and docs, give the real bound in the theta_max error, drop an unused include Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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
ABC shadow inference (Stoica et al., 2017): the parameters θ of a model are inferred from statistics observed on a domain, using the mutable parameters (#67) and the parameter validity rules (#68).
shadow_step. Metropolis proposals on θ with the shadow log ratio ⟨θ′ − θ, t_obs − t_y⟩ (computed in log, noexp) and a uniform prior on a box, on one coordinate or on all of them (ShadowProposal). Every draw goes through the givenRandomEngine: a run is replayable bit for bit at fixed seed.calibrate_deltas. With t_y frozen during the shadow chain, the outer chain behaves like an unadjusted Langevin chain with h = m·δ²/12: stable for h·P < 4, close to the posterior for h·P ≈ 0.2. δ_i = √(12·s_eff / (m_i·Var t_i)), with s_eff the step scale divided by a Gershgorin bound on the correlations. A statistic with a (near) zero variance is refused instead of giving an infinite or zero step.Model::theta_bounds. Per term, the interval of valid θ: −∞ for a hard-core, at most 0 if the attraction is not integrable, unbounded otherwise.set_thetasuses the same bounds: one source for the model and for the prior box.run_abc_shadow. Checks the configuration once before any computation (known, distinct, non hard-core terms; prior box inside the integrability domain, by default this domain; finite lower bound when nothing is observed; starting θ inside the box; no fixed objects until the observation rate is constant), calibrates the steps from the covariance of the statistics unless they are given, runs the outer chain on the simulation context and returns the trace in memory (AbcTrace). The model keeps the last θ: a second call continues the chain.AbcTrace::estimated_step_scalesgives h·P per parameter (P estimated from Var(t_y) over the trace) and a warning is logged above 1 (δ too large, posterior inflated) or below 0.02 (δ too small, slow chain), with the remedy.docs/statistics.md: what each statistic counts, its parameter and its boundary rule, the limits of the measurement on an outcrop, and how to run and tune the ABC shadow. Reference added to the README.Results unchanged
No Metropolis-Hastings path is touched: existing simulations are unchanged.
Tests
test-abc-shadow-step(1 s): stationary law of the shadow chain, proposal and acceptance counts, box respected even with δ larger than the box, replay at fixed seed; calibrated δ gives the expected posterior spread, with counter-tests at h·P = 2; degenerate variances refused.test-abc-shadow-poisson(46 s): Poisson process, whose posterior is known: posterior mean and spread, trace shape, given deltas, chain continuation, h·P diagnostic (calibrated, too large and too small δ), and every configuration refusal (unknown or duplicated term, hard-core, box outside the integrability domain, starting θ outside the box, t_obs = 0 with the default box, fixed objects).test-abc-shadow-strauss(65 s): a Strauss pattern simulated with known parameters; the ABC, started elsewhere, finds them within three posterior standard deviations, with a spread consistent with the Fisher information, in both proposal modes. At the posterior mean the model gives the observed statistics on average: comparing the statistics inside the domain with a model simulated on the extended domain is validated.test-model-parameters:theta_boundsfor each kind of term.Not in this PR
BREAKING CHANGEfooter: it will go on the last breaking change of the ABC series.🤖 Generated with Claude Code