Repository navigation
docs: simulate and fit the patch-models tutorial - #281
Conversation
The patch-models tutorial never called sample(), so it never answered whether coupled or stratified patch processes are actually identifiable from data. Add two end-to-end sections: fit the fixed-K coupled, partially pooled renewal under NUTS and recover R_t per patch with a CairoMakie plot (80% coverage close to nominal), then fit the Gravity model and check whether its exponents come back out. The gravity exponents are only partially identifiable from three patches: gamma (distance) recovers well, beta is roughly captured, but alpha's posterior misses the true value entirely. That's a genuine finding, reported as a recovery table rather than papered over with a looser prior.
Try this Pull Request!Option 1: Julia Package ManagerOpen Julia and type: import Pkg
Pkg.activate(temp=true)
Pkg.add(url="https://github.com/EpiAware/ComposableTuringIDModels.jl", rev="docs/patch-models-tutorial")
using ComposableTuringIDModelsOption 2: Local CheckoutIf you have the repo locally: git checkout docs/patch-models-tutorial
julia --project=. -e "using Pkg; Pkg.instantiate()" |
Codecov Report✅ All modified and coverable lines are covered by tests.
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
|
📖 Documentation preview is ready! View the docs for this PR at: https://EpiAware.github.io/ComposableTuringIDModels.jl/previews/PR281/ This preview will be updated automatically when you push new commits. |
There was a problem hiding this comment.
This PR adds two new sections to the patch-models tutorial that simulate a known truth and fit it under NUTS to check whether the coupled patch process and the gravity model's exponents are recoverable. The Julia is sound and reuses the package's own building blocks correctly, but the quantitative recovery claims (coverage, ranges, which exponent recovers) are asserted only in prose rather than checked in the executed code, unlike the sibling gaussian-process.md tutorial which guards equivalent claims with @assert.
Automated first pass by seabbs-review-bot (Claude sonnet), triggered by: first pass. Not a human review. @seabbs can comment @seabbs-review-bot to re-run it, or add the no-review label to opt this PR out. Ping @seabbs with any questions.
|
This doesn't rely on plotting ehought the readouts of the named tuples are no good. It is really really long and the fitting comes very late in the day. We need to review waht partial pooled is for vs this one adn I think maybe work on deplucating. Lots of text as well |
Reuse the credible_bands quantile pattern the sibling tutorials use, applied per patch to Rt_stack[g, :, :], rather than a second 3D mapslices path. The bands and coverage80 are unchanged (rmse 0.0327, coverage80 0.764). Bind coverage80 in the block that computes it and add a covered column to the gravity recovery table, so the coverage figure and the per-exponent recovery verdict are computed output rather than numbers typed into prose. The prose now points at those values instead of asserting them.
Review follow-upPushed 0992910. One finding fixed, two rejected on mechanism but addressed on substance. Fixed — duplicate band computation ( Rejected — But the concern behind them is right, so both claims are now computed rather than narrated:
Verification. Ran all 14 Not approving, not merging. This was opened by a bot. Please ping @seabbs for any questions. |
Replace the computed covered column with a figure: one posterior density per exponent with a dashed line at the value that generated the data. A plot carries the recovery claim better than a printed verdict and regenerates on every build, so nothing can go stale. The coverage prose points at the R_t panel rather than at coverage80. Build grav_post once and derive the recovery table from it, so the chain lookup is not written twice.
Revised: plots, not printed numbersPushed 97b3a7d, which reverses the remedy in my previous commit. Sam's steer on printing computed figures as block output was "we prefer plots." The α/β/γ recovery verdict is now a figure. The
The coverage claim points at the The Ran all 15 blocks of the committed page end-to-end, no errors, and rendered the new figure to PNG separately to check the layout before committing (three panels, legend below, no overlap). This was opened by a bot. Please ping @seabbs for any questions. |
|
This is not great. Lots of LLMs and recursive text i.e: Each exponent's posterior against the value that generated the data says more than the table does: It is pretty pointless showing the size of a turing model like that is something of interest. I think it makes more sense to first show how to build up to the model we are going to fit, simulatiing from each stage with a plot as we go. then fit to sim data as we do now and check recovery. (I think we just have the one fit with recovery not the two). Then discuss with sim the other coupling options we currently have and how to write a custom one with sim. No this is a plain function etc etc etc werid lang |
The page ran seven patterns forward, printed their shapes and named-tuple readouts, and only fitted anything in its last third, twice. It also re-explained partial pooling and the Split weight matrix, both of which have their own pages. Rebuild it as one model gained a layer at a time, simulated and plotted after each layer, then fitted once. The layers share a seed, so the mixing-matrix figure is coupled over uncoupled incidence with the Rt draws held fixed, and the coupling is the only difference in it. Every shape and readout is replaced by a figure. The gravity section shows the matrix the exponents imply at three distance exponents rather than fitting a second model, and a new section writes a coupling as one renewal_pressure method and simulates from it. Partial pooling and the weight matrix now link to their own tutorials.
Rewritten to the structure you asked for, in c65a209Your steer was to build up to the model being fitted, simulating with a plot at Structure
Every stage is seeded identically, so the On your specific pointsThe named-tuple readouts and the model sizes are gone. Every The second fit is gone. The gravity section used to draw a truth from the Writing a custom coupling is now in the page, with a simulation. A Deduplication. You were right that this overlapped two other pages.
The prose. "Says more than the table does" and that whole register is gone, 375 lines to 338, with three more figures and one fewer fit. What I ranThe 15 I did not run the full Documenter build. Total runtime for the page is about This was opened by a bot. Please ping @seabbs for any questions. |
Summary
docs/src/tutorials/patch-models.mdpreviously only built and inspectedcoupled/stratified patch models — it never called
sample(), so it neveranswered whether any of that machinery is actually identifiable from data.
Related to the general "does this really work" concern behind patch and
strata-mapping design discussions (see #248 for the patch-mixing context).
Brought the tutorial up to the bar set by
renewal-negbin.mdandhierarchy-stacked.md:Kcoupled,partially pooled renewal model (
Stratify+Hierarchy+ an off-diagonalmixingmatrix, observed throughSplit). Fits under NUTS (300 draws,ForwardDiff), recovers each patch's
R_tpath, and plots posterior medianGravity's inferredcoupling: draws a true
(α, β, γ)from the prior, fits, and reports arecovery table (no
@assertgating, per the GP-tutorial lesson aboutversion-coupled tripwires).
Finding worth flagging
The fixed-
Kcoupled fit recovers well: posterior median tracks the trueR_tpath in all three patches, 80% credible interval covers the truth in76% of 72 patch-day cells.
The
Gravityfit is a genuine mixed result, reported as-is rather thantuned away: with only three patches (three off-diagonal
Kentries),γ(distance exponent) recovers well and
βis roughly captured, butα'sposterior mean overshoots the truth and its 80% interval misses it
entirely. Three patches isn't enough data to identify all three gravity
exponents separately — a real application would need more strata or an
informative prior / fixed exponent.
Verification
Ran every code block in the page (both new sections plus the existing
ones) end-to-end in a single Julia session mirroring Documenter's
@examplesemantics, with the seed fixed at each simulate step forreproducibility. Confirmed no errors, and cross-checked the printed
numbers via standalone scripts. Did not run the full
task docs/Documenter build (slow, and the instructions for this task said running
the code directly is what matters).
Test plan
task docs-fast(ortask docs) builds this page cleanly in CIThis was opened by a bot. Please ping @seabbs for any questions.