Skip to content

feat(ABCShadow): infer the model parameters with the ABC shadow algorithm - #69

Open
francoisbonneau wants to merge 9 commits into
nextfrom
feat/abc-shadow
Open

francoisbonneau wants to merge 9 commits into
nextfrom
feat/abc-shadow

Conversation

@francoisbonneau

Copy link
Copy Markdown
Member

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 chain — shadow_step. Metropolis proposals on θ with the shadow log ratio ⟨θ′ − θ, t_obs − t_y⟩ (computed in log, no exp) and a uniform prior on a box, on one coordinate or on all of them (ShadowProposal). Every draw goes through the given RandomEngine: a run is replayable bit for bit at fixed seed.
  • Calibrated steps — 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_thetas uses 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.
  • Step diagnostic. After a run, AbcTrace::estimated_step_scales gives 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.
  • Documentation. New 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_bounds for each kind of term.
  • Each statistical tolerance is justified in a comment (effective sample size, shadow bias on the variance).
  • Full suite: 42/42.

Not in this PR

  • Fracture validation (p20, p21, X-nodes near the boundary): dedicated test when the ABC is used on a real outcrop.
  • Contexts with fixed objects: refused until the observation rate is constant.
  • No BREAKING CHANGE footer: it will go on the last breaking change of the ABC series.

🤖 Generated with Claude Code

francoisbonneau and others added 9 commits December 2, 2026 12:27
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>
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