Add an IBIS sampler (job_type = ibis) that updates the exact posterior as observations arrive, absorbs revised observations, and finishes within wall_time_fit
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Idoneità per principianti
- 25/100
- Tipo di issue
- Funzionalità
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Stack tecnologico
- python
- Ambito
- backend, machine-learning
Direzione di ricerca
Start with prerequisite #819 and ADR-0051, then inspect the existing samplers and registration in pybnf/algorithms/samplers and the bngsim interfaces named in the issue. The proposed entry points are pybnf/algorithms/samplers/ibis.py and a segment primitive under pybnf/bngsim_model/. Done means supported deterministic ODE jobs produce standard samples, diagnostics, and atomic state updates, with the listed validation tests covering posterior agreement, revisions, path agreement, and wall_time_fit.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
PyBNF's samplers (am, mh, pt, dream, p_dream) sample the posterior for a fixed data set. When observations arrive one interval at a time, every new observation means a fresh run from scratch, and the cost of each run grows with the length of the series. This issue proposes a sequential Monte Carlo sampler in the IBIS family (iterated batch importance sampling; Chopin 2002), job_type = ibis. It carries a population of weighted parameter sets (particles) from one data vintage to the next and targets the exact posterior at every update: the same posterior am samples for the same job.
Requirements
- Exact target. At every update the particles target the posterior PyBNF's MCMC samplers target for the same job: the same priors (
pybnf/priors), the same noise model (pybnf/noise), and the same prediction transforms, including cumulative-to-incident differencing (ADR-0051). The only approximations are Monte Carlo error, which shrinks as particles are added and which the run estimates itself, and the ODE solver tolerance.
Kernel-smoothing parameter filters, such as Liu and West (2001), do not meet this requirement. Their jitter kernel makes the static parameters drift and pulls the population toward a Gaussian, so they sample the posterior of a different model, and the bias does not vanish as particles are added. - Incremental. An update with new observations starts from the saved population of the previous update, not from the prior.
- Revisions. Earlier observations may change between updates. A revision is absorbed by the update and does not need a from-scratch refit.
- Budget. An update honours
wall_time_fit(ADR-0093). When the budget runs out it still finishes with a usable population, its outputs, and an estimate of its Monte Carlo error. - Efficiency. Within those constraints, as fast as possible.
Recommended algorithm
An update takes the saved population, which targets π_old(θ) ∝ p(θ)·L_old(θ), to π_new(θ) ∝ p(θ)·L_new(θ). Here L_old is the likelihood of the data the population was built on, and L_new is the likelihood of the current data: the revised earlier rows plus the new rows.
-
Generalized tempering bridge (Cai et al. 2021). The update passes through the intermediate targets π_φ(θ) ∝ p(θ)·L_old(θ)^(1−φ)·L_new(θ)^φ as φ goes from 0 to 1. Each next φ is chosen by bisection so that the conditional ESS (Zhou, Johansen and Aston 2016) of the incremental weights hits a target, e.g. 0.5 to 0.9 of N.
- A quiet update (one new row, no revisions) whose weights keep the CESS above target reaches φ = 1 in one step. That step is plain IBIS reweighting (Chopin 2002).
- An informative row, or a large revision, is split into as many tempered steps as it needs, so the population never collapses.
- The first update of a job has L_old ≡ 1, which makes it ordinary adaptive likelihood tempering from the prior (Schäfer and Chopin 2013).
-
Cheap reweighting. The model is deterministic given θ, so each particle caches:
- its simulated prediction at every observation time;
- its model state at the last observation time;
- its log-likelihood.
From this cache:
- Revised rows are re-scored from the cached predictions with no simulation.
- A new row costs one integration of one observation interval per particle, from its cached state.
- Only particles created by an MCMC move need a full re-simulation from the start. That re-simulation also refills their cache.
-
Resampling. Resample (systematic) when the ESS falls below N/2.
-
Waste-free moves (Dau and Chopin 2022).
- Resample M ancestors, with M at least the number of cores and about 100 to 200.
- Run each as an MCMC chain of length P that leaves the current π_φ invariant.
- Keep all N = M·P states as the new particles.
- Choose P adaptively: double it until it exceeds κ times the autocorrelation time of the log-likelihood across the chains (κ from 2 to 10), capped by what remains of the budget.
-
Kernel. Gradient-free Metropolis–Hastings on unconstrained coordinates, using the same support-aware bijections
hmcuses (pybnf.priors.bijector_for_support). It is a mixture of:- an independent proposal: a Gaussian, or a Gaussian mixture, fitted to the current weighted particles (Chopin 2002; South, Pettitt and Drovandi 2019);
- a random walk with covariance (2.38²/d)·Σ̂, where Σ̂ is estimated from the particles.
At low to moderate dimension, random-walk and MALA kernels perform well (Buchholz, Chopin and Jacob 2021), and ADR-0059 keeps gradient-based samplers off the simulator path. So gradient moves are not part of v1, although bngsim's forward sensitivities would allow them later.
-
Compute. Everything runs in process. One particle's integration takes well under a millisecond, which is too small to be a dask job. Batch the full re-simulations of a move through bngsim's
Simulator.run_batch(num_processors=...), which releases the GIL and runs on threads. Several independentibisjobs can still share a cluster.
Scale: a reweighting step is N one-interval integrations, and a move sweep is about N re-simulations over the t intervals seen so far. For illustration, at about 0.05 ms per particle per interval with N = 4000 and t = 35:- a quiet update takes about 0.2 s;
- a move sweep takes about 7 s on one thread, and proportionally less on several.
Exactness: what the theory covers
- Adaptive kernels and adaptive tempering. Tuning the kernels from the particles, and choosing the tempering exponents by ESS bisection, keeps consistency and a CLT (Beskos, Jasra, Kantas and Thiery 2016).
- Waste-free moves. These are consistent with a CLT as P grows (Dau and Chopin 2022), and they give a single-run estimate of the Monte Carlo variance. The run should report that estimate.
- What no theorem covers. No single result covers ESS-triggered resampling, adaptive kernels and adaptive P together. That is standard practice, and the validation below is the check.
- The evidence estimate. Once the algorithm adapts, the log-evidence estimate is not unbiased (Zhou, Johansen and Aston 2016). Report it as an estimate.
Integration in PyBNF
-
Module. Add
pybnf/algorithms/samplers/ibis.py, registered withregister_fit_typein the Bayesian family, and write a new ADR for the design. -
State file. It holds:
- the particles (in sampling space
u), their log-prior and log-likelihood; - the cached predictions and model states;
- the φ schedule;
- the data each log-likelihood was computed against, so that revised rows are detected by comparison;
- a fingerprint of everything that defines the posterior: the free parameters and priors, the model, the noise model and the transforms.
A continued run refuses a state file whose fingerprint differs, naming the difference, and writes it atomically after every update.
- the particles (in sampling space
-
Segment primitive. Add one to
pybnf/bngsim_model/: set a particle's species state, integrate one observation interval, and return the new state and the outputs. bngsim'sSimulatoralready hasset_state/get_state.
The segment path and the full re-simulation path must give the same predictions, to solver tolerance. Otherwise the reweighting steps and the moves target different posteriors. Test this directly. -
Scope of v1. Deterministic ODE models on the bngsim backend. Anything v1 cannot honour is refused by name, per PyBNF's fail-loud convention:
- stochastic simulation methods, whose likelihood is itself random and would need SMC², Chopin, Jacob and Papaspiliopoulos 2013;
refine;bootstrap;- and so on.
-
Outputs.
- Samples in the standard samples format after every update, so the existing post-processing works: the ArviZ bridge (ADR-0055), histograms and credible intervals.
- Per-step diagnostics: φ, ESS and CESS, acceptance rates, P, distinct particles, the log-evidence increment, and the Monte Carlo error estimate.
- Optionally, posterior-predictive draws for a given number of observation intervals past the last row, integrated forward from each particle's cached state with noise from the job's noise model.
Prerequisite: #819
#819 must be fixed first. The cumulative-to-incident transform currently differences against the previous simulated row, not the previous measurement, so a prediction depends on the simulation grid.
IBIS evaluates the same predictions two ways:
- one observation interval at a time, from a cached state (reweighting);
- in a full re-simulation from the start (moves).
Under the current behaviour the two paths can disagree whenever the grids differ, and the sampler would then mix two different likelihoods. Once the increment is taken over the interval between measurements, as ADR-0051 intends, the two paths agree by construction.
Validation
- Fixed data. On a fixed data set, the final
ibisposterior matchesamwithin Monte Carlo error: quantiles and marginal distributions. - Sequential equivalence. Assimilating rows 1..t over k updates gives the same posterior, within Monte Carlo error, as one update on all t rows.
- Revisions. Revise an earlier row between updates; the result matches a from-scratch run on the revised data.
- Recovery. On synthetic data drawn at a known truth, credible intervals cover the truth at their nominal rate across seeds.
- Path agreement. Segment-path and full-simulation predictions agree to solver tolerance.
- Budget.
wall_time_fitis honoured, and a budget-truncated update still writes complete outputs and its Monte Carlo error.
Side benefit
With L_old ≡ 1 and all the data in one update, the same code is an adaptive-tempering SMC sampler for a fixed data set. That makes it a parallel alternative to am / mh, with an evidence estimate.
References
- Chopin, N. (2002). A sequential particle filter method for static models. Biometrika 89(3):539–551.
- Dau, H.-D.; Chopin, N. (2022). Waste-free sequential Monte Carlo. J. R. Stat. Soc. B 84(1):114–148. arXiv:2011.02328.
- Cai, M.; Del Negro, M.; Herbst, E.; Matlin, E.; Sarfati, R.; Schorfheide, F. (2021). Online estimation of DSGE models. The Econometrics Journal 24(1). NBER WP 26826.
- Zhou, Y.; Johansen, A. M.; Aston, J. A. D. (2016). Toward automatic model comparison: an adaptive sequential Monte Carlo approach. J. Comput. Graph. Stat. 25(3):701–726. arXiv:1303.3123.
- Schäfer, C.; Chopin, N. (2013). Sequential Monte Carlo on large binary sampling spaces. Stat. Comput. 23:163–184. arXiv:1101.6037.
- South, L. F.; Pettitt, A. N.; Drovandi, C. C. (2019). Sequential Monte Carlo samplers with independent Markov chain Monte Carlo proposals. Bayesian Anal. 14(3):753–776.
- Buchholz, A.; Chopin, N.; Jacob, P. E. (2021). Adaptive tuning of Hamiltonian Monte Carlo within sequential Monte Carlo. Bayesian Anal. 16(3):745–771. arXiv:1808.07730.
- Beskos, A.; Jasra, A.; Kantas, N.; Thiery, A. (2016). On the convergence of adaptive sequential Monte Carlo methods. Ann. Appl. Probab. 26(2):1111–1146. arXiv:1306.6462.
- Dai, C.; Heng, J.; Jacob, P. E.; Whiteley, N. (2022). An invitation to sequential Monte Carlo samplers. J. Am. Stat. Assoc. 117:1587–1600. arXiv:2007.11936.
- Chopin, N.; Jacob, P. E.; Papaspiliopoulos, O. (2013). SMC²: an efficient algorithm for sequential analysis of state-space models. J. R. Stat. Soc. B 75(3):397–426. arXiv:1101.1528.
- Liu, J.; West, M. (2001). Combined parameter and state estimation in simulation-based filtering. In Sequential Monte Carlo Methods in Practice, Springer, 197–223.
- Reference implementation: the
particlesPython library (N. Chopin),particles.smc_samplers.IBIS/AdaptiveTempering, which is waste-free by default. It has no within-update tempering and no revision handling, both of which this issue adds.
- Lingua principale
- Python
- Stelle
- 25
- Fork
- 25
- Merge medio
- 4h 5m
- PR unite (30g)
- 10
Preparare l'ambiente
- Include un Dockerfile o un file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di lanl/PyBNF
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
I maintainer di solito rispondono entro 1 giorno
-
bug minor
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
I maintainer di solito rispondono entro 1 giorno
-
bug tech debt
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
I maintainer di solito rispondono entro 1 giorno
-
bug minor
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
I maintainer di solito rispondono entro 1 giorno
-
bug silent-incorrectness
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
I maintainer di solito rispondono entro 1 giorno
Issue simili
-
Quick Installation step 2 installs from the plugin manager, but the plugin isn't published yetAperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 66/100
jenkinsci/user-guide-ai-chatbot-plugin#132 ·
I maintainer di solito rispondono entro 6 giorni
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
-
gh-sync ship audits cards before writing station done, so every ship reports false STATUS findingsApertaharness
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
mruangutai/harness#2455 ·
I maintainer di solito rispondono entro 1 giorno
-
stripthink leaves thinking text in place when the chat template opens the think tag in the promptForse già presa @MaiAditya l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 80/100
I maintainer di solito rispondono entro 1 giorno
-
xcorr sizes its bin array from the largest observed m/z, so one out-of-range peak kills the runForse già presa @BioGeek l’ha presa oggi. Apertabug
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
instadeepai/winnow#312 ·