Skip to content

docs: rework the time-varying damping tutorial onto the composable stack - #338

Merged
seabbs merged 4 commits into
mainfrom
chore/181-composable-damping
Sep 3, 2026
Merged

seabbs merged 4 commits into
mainfrom
chore/181-composable-damping

Conversation

@seabbs-bot

@seabbs-bot seabbs-bot commented Aug 28, 2026 •

Copy link
Copy Markdown
Collaborator

Addresses #181 (see the caveat on point :69 below).

Reworks the time-varying damping tutorial's fit section onto the package's own
composable stack, replacing the hand-written @model observation loop the issue
called out as bespoke code.

  • :88, done. The AR latent path passes through DirectInfections
    (transformation = identity, initialisation = FixedIntercept(0.0)) as the
    expected series, observed by NormalError(; std = FixedIntercept(0.01)). The
    same IDModel + as_turing_model stack the rest of the docs use, with no
    custom @model or loop code. Checked against the model it replaces: at 300
    draws both recover the ramp, correlation 0.96 against 0.95.
  • :39, done. The page now documents that the tanh clamp is a transform
    field of AR rather than something the constructor bakes in, and that
    identity for a Distribution leaves the bounds to the user. It does not
    claim the package checks them.
  • :102, done. Rather than declaring the bullet moot with the ARIMA case
    study gone, the page closes it with the interface: arma takes the same
    damp slot and DiffLatentModel differences what it wraps, so a
    time-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 a
    random walk of unknown shape, and the recovery check needs a known \rho_t
    that 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 sample rather than only at the top of the
page, 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.

@seabbs-bot
seabbs-bot requested a review from seabbs as a code owner August 28, 2026 16:34
@github-actions

Copy link
Copy Markdown
Contributor

Try this Pull Request!

Option 1: Julia Package Manager

Open Julia and type:

import Pkg
Pkg.activate(temp=true)
Pkg.add(url="https://github.com/EpiAware/ComposableTuringIDModels.jl", rev="chore/181-composable-damping")
using ComposableTuringIDModels

Option 2: Local Checkout

If you have the repo locally:

git checkout chore/181-composable-damping
julia --project=. -e "using Pkg; Pkg.instantiate()"

@github-actions

Copy link
Copy Markdown
Contributor

📖 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.

@seabbs-review-bot seabbs-review-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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(

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 seabbs-review-bot Bot added the llm-reviewed Reviewed by seabbs-review-bot label Sep 2, 2026
@seabbs-bot

Copy link
Copy Markdown
Collaborator Author

@seabbs-review-bot

@seabbs-review-bot seabbs-review-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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()),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@seabbs-bot
seabbs-bot force-pushed the chore/181-composable-damping branch from 5036d44 to 030bdf0 Compare September 2, 2026 10:32
@codecov

codecov Bot commented Sep 2, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

Flag Coverage Δ
unit 93.93% <ø> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.
see 8 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@seabbs-bot
seabbs-bot force-pushed the chore/181-composable-damping branch from 030bdf0 to 16c2b18 Compare September 2, 2026 12:43
seabbs-bot and others added 3 commits September 2, 2026 17:02
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
@seabbs-bot
seabbs-bot force-pushed the chore/181-composable-damping branch from 16c2b18 to 9f877ef Compare September 2, 2026 16:05
Co-authored-by: Sam Abbott <contact@samabbott.co.uk>
@seabbs
seabbs merged commit d92356b into main Sep 3, 2026
3 of 16 checks passed
seabbs-bot added a commit that referenced this pull request Sep 3, 2026
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

llm-reviewed Reviewed by seabbs-review-bot

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants