Repository navigation
docs: rework the time-varying damping tutorial onto the composable stack - #338
Conversation
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="chore/181-composable-damping")
using ComposableTuringIDModelsOption 2: Local CheckoutIf you have the repo locally: git checkout chore/181-composable-damping
julia --project=. -e "using Pkg; Pkg.instantiate()" |
|
📖 Documentation preview is ready! View the docs for this PR at: https://EpiAware.github.io/ComposableTuringIDModels.jl/previews/PR338/ This preview will be updated automatically when you push new commits. |
There was a problem hiding this comment.
This is a docs-only rewrite of the time-varying-damping tutorial: it drops a dead using Turing: to_submodel import, replaces the hand-written @model observe_path loop with the package's own IDModel(DirectInfections(...), NormalError(...)) composition, and adds prose explaining the AR transform field. I checked the new composition against DirectInfections.jl, NormalError.jl, Intercept.jl, compose.jl and AR.jl: the field names, defaults, and the flat (non-prefixed) as_turing_submodel semantics all check out, so fit[:ρ] still resolves correctly through the extra composition layer. The one real defect is a formatting slip in the new DirectInfections(...) call that doesn't match the codebase's canonical Runic style, which plausibly explains the failing pre-commit check; the widespread test-matrix failures across every Julia version/OS look unrelated to this docs-only diff and are worth confirming separately as a pre-existing issue.
Automated first pass by seabbs-review-bot (Claude sonnet), triggered by: first pass. Not a human review. Comment @seabbs-review-bot to ask for another pass: @seabbs any time, the author's agent once it has pushed changes. Add the no-review label to opt this PR out. Ping @seabbs with any questions.
| model = observe_path(z, n) | ||
| fit = sample(model, NUTS(0.85; adtype = Turing.AutoForwardDiff()), 300; | ||
| model = IDModel( | ||
| DirectInfections( |
There was a problem hiding this comment.
issue This call opens DirectInfections( then starts the next line with ; Z = .... Every other multi-line keyword call in the repo (compose.jl:149, AR.jl:93, Renewal.jl:152) puts the ; at the end of the opening line instead: DirectInfections(;. This is the only ; name = value line-start in the whole codebase, and it lines up with the pre-commit check failing on this head (Runic will want to reformat it). Fix:
model = IDModel(
DirectInfections(;
Z = AR(; damp = RandomWalk()), transformation = identity,
initialisation = FixedIntercept(0.0)),
NormalError(std = FixedIntercept(0.01)))|
@seabbs-review-bot |
There was a problem hiding this comment.
This is a docs-only rewrite of the time-varying-damping tutorial onto the composable IDModel/DirectInfections/NormalError stack, plus a fix relabelling the plotted statistic from "mean" to "median" (matching the quantile it actually plots). The new API usage checks out against the source (AR, DirectInfections, NormalError, FixedIntercept, arma, DiffLatentModel all match their signatures and docstrings). One reuse issue: the closing ARIMA example manually recomposes DiffLatentModel(model = arma(...)) instead of calling the package's own exported arima() helper that already does this, undercutting its own "no custom code" claim.
Automated first pass by seabbs-review-bot (Claude sonnet), triggered by: re-review requested by seabbs-bot. Not a human review. Comment @seabbs-review-bot to ask for another pass: @seabbs any time, the author's agent once it has pushed changes. Add the no-review label to opt this PR out. Ping @seabbs with any questions.
| [`arma`](@ref) takes the same `damp` slot, and [`DiffLatentModel`](@ref) differences whatever it wraps, so a time-varying-damping ARIMA is the two of them composed with no custom code: | ||
|
|
||
| ```@example tvdamp | ||
| arima_tv = DiffLatentModel(; model = arma(; damp = RandomWalk()), |
There was a problem hiding this comment.
suggestion This manually rebuilds DiffLatentModel(; model = arma(...)), but src/latent_models/combinations/arima.jl already exports arima(; ar_init, diff_init, damp, θ, ϵ_t) which does exactly this composition. Prefer arima_tv = arima(; damp = RandomWalk(), diff_init = [Normal(0.3, 0.3)]) — it makes the point better, since it shows the existing public arima constructor absorbing a time-varying damp with zero changes, rather than re-deriving arima's body inline.
5036d44 to
030bdf0
Compare
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:
|
030bdf0 to
16c2b18
Compare
Replace the hand-written @model observation loop (issue #181's objection) with the package's own stack: DirectInfections(transformation = identity, initialisation = FixedIntercept(0.0)) passes the AR latent path through as the expected series, and NormalError(std = FixedIntercept(0.01)) observes it. The coefficient path is still recovered as the generated quantity ρ; the fit reports the posterior-mean correlation with the true ramp. Also documents that the tanh transform is a first-class AR field (issue point :39), and notes the ARIMA case study material now lives in the delays-dayofweek tutorial via DiffLatentModel. Closes #181
Split the two added paragraphs into one sentence per line, drop the repeated rationale, and wrap the over-long `sample` call. Restore "covers" for the credible band, which is what the figure shows. Verified the reworked composition against the model it replaces: at 300 draws both recover the ramp, correlation 0.96 against 0.95. Co-Authored-By: Sam Abbott <contact@samabbott.co.uk> Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UmmqqzQPhrB74RfAv2TqBQ
…sform The page said `identity` is the default "for an already-bounded `Distribution`". Nothing checks boundedness: `_default_transform(::Distribution)` returns `identity` for any distribution, and the page's own constant example uses an unbounded `Normal(0.4, 0.1)`. The source comment says bounded *by the user*; say that instead of promising a guarantee the package does not make. Also from review: - Seed immediately before `sample`. The simulation above consumes the stream, so the fit's numbers moved with unrelated edits. At the fixed seed the page now prints correlation 0.96 with 80% band coverage 1.0, which is what the surrounding prose claims. - Label the plotted median "posterior median". It was `quantile(…, 0.5)` drawn under a "posterior mean" legend. - Say why the ramp is written out rather than drawn from `AR`: the recovery check needs a known ``\rho_t`` that crosses zero. That is issue point :69, and it is a deliberate no rather than an oversight. - Close issue point :102 with the interface instead of declaring it moot. `arma` takes the same `damp` slot and `DiffLatentModel` differences what it wraps, so a time-varying-damping ARIMA is two lines and no custom code. - `NormalError(; std = …)`, split out `posterior`, and drop the paragraph's repeated sentence and its commentary on the previous revision. Co-Authored-By: Sam Abbott <contact@samabbott.co.uk> Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UmmqqzQPhrB74RfAv2TqBQ
16c2b18 to
9f877ef
Compare
Co-authored-by: Sam Abbott <contact@samabbott.co.uk>
Reflows every authored documentation page so prose is one sentence per line, splits sentences joined by a colon, semicolon or dash, and cuts restatement and filler. Also, on top of the earlier pass: - a sentence immediately after a code block that re-asserted what the block showed is gone, - a `##` comment in the literate tutorial that carried explanation moved into the surrounding markdown, - trailing clauses making a wry or self-satisfied point are cut, keeping the fact. `design.md`, `delays-dayofweek.md`, `renewal-negbin.md`, `time-varying-damping.md` and `renewal-modifiers.jl` are treated afresh on top of #276, #338 and #345. No fenced code block content changes. Co-Authored-By: Sam Abbott <contact@samabbott.co.uk> Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Addresses #181 (see the caveat on point
:69below).Reworks the time-varying damping tutorial's fit section onto the package's own
composable stack, replacing the hand-written
@modelobservation loop the issuecalled out as bespoke code.
:88, done. The AR latent path passes throughDirectInfections(
transformation = identity,initialisation = FixedIntercept(0.0)) as theexpected series, observed by
NormalError(; std = FixedIntercept(0.01)). Thesame
IDModel+as_turing_modelstack the rest of the docs use, with nocustom
@modelor loop code. Checked against the model it replaces: at 300draws both recover the ramp, correlation 0.96 against 0.95.
:39, done. The page now documents that thetanhclamp is atransformfield of
ARrather than something the constructor bakes in, and thatidentityfor aDistributionleaves the bounds to the user. It does notclaim the package checks them.
:102, done. Rather than declaring the bullet moot with the ARIMA casestudy gone, the page closes it with the interface:
armatakes the samedampslot andDiffLatentModeldifferences what it wraps, so atime-varying-damping ARIMA is those two composed in two lines with no custom
code.
:69, deliberately not done. Simulating from the model spec would draw arandom walk of unknown shape, and the recovery check needs a known
\rho_tthat crosses zero. The recursion stays written out and the page now says why.
Reopen or split this bullet if the intent was different.
The fit is seeded immediately before
samplerather than only at the top of thepage, so the printed correlation stops moving with unrelated edits above it. At
that seed it is 0.96, with 80% band coverage 1.0.
This was opened by a bot. Please ping @seabbs for any questions.