Repository navigation
feat(latent): add broadcast_window for an effect confined to a window - #345
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="166-windowed")
using ComposableTuringIDModelsOption 2: Local CheckoutIf you have the repo locally: git checkout 166-windowed
julia --project=. -e "using Pkg; Pkg.instantiate()" |
There was a problem hiding this comment.
This is a docs-only PR (plus one new @testitem) that shows a windowed effect built from existing TransformLatentModel and CombineLatentModels components, with no new source code. The composition claims check out against the actual implementations (index-based gating, prefix naming, AR damp as a process), and the test exercises real behaviour rather than restating the implementation. Sound change; one minor gap worth a look.
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.
| keys(rand(as_turing_model(shifted, 40))) | ||
| ``` | ||
|
|
||
| [`CombineLatentModels`](@ref) sums, so a multiplicative window effect on a |
There was a problem hiding this comment.
suggestion This closing sentence asserts a new technique (multiplicative windowing via log-space composition wrapped in exp) but unlike every other claim in this section it has no code block backing it. Either cut the sentence or add a short @example design block demonstrating it, so the page doesn't end on an untested assertion.
seabbs
left a comment
There was a problem hiding this comment.
rather than just docing shall we make a helper for this common pattern?
An effect confined to an index window needs no new latent modifier. `TransformLatentModel` reads the index and `CombineLatentModels` sums paths, so a window is the two together. Add a design section covering the fixed effect, the estimated effect size, stacking two windows, and the same gated process used as a per-step parameter. Add a regression test so the composition and its prefixed parameter names cannot drift. Investigated for #166. 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
`broadcast_window(model, window)` builds a latent model that equals `model` on `window` and zero everywhere else, so summing it onto a base path with `CombineLatentModels` confines the effect to that window. It is a `BroadcastLatentModel` under a new `InWindow` rule, the same shape as `broadcast_dayofweek` under `RepeatEach`, so it needs no new component type and stacks by ordinary composition. The rule asks for a series as long as the window, so a process member is generated over the window rather than over the whole series. The inner slot is a PATH slot, which lets one helper serve a known effect, an estimated level and a process. A window touching either end of the series is an ordinary case. Carry the broadcast rule into the model tree label, so a day-of-week effect and a windowed effect no longer print identically and the window is visible without reading the code. The label is built from the type name rather than from `show`, which module-qualifies outside the package's own scope. Rewrite the design section to lead with the helper and keep the from-scratch composition underneath as the explanation. Closes #166. 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
9e2d856 to
e318159
Compare
|
Built the helper as asked rather than only documenting.
One helper turned out to cover both the fixed and the estimated effect, because the inner slot is a PATH slot: Two things worth flagging: Making the window visible in the tree needed more than following The docs section now leads with the helper and keeps the from-scratch composition underneath, with a test asserting the two agree and draw the same prefixed names. Rebased onto current main, so #346, #347 and #351 are in. This was opened by a bot. Please ping @seabbs for any questions. |
|
@seabbs-review-bot |
There was a problem hiding this comment.
broadcast_window adds a well-tested InWindow broadcast rule that places an inner latent process on a declared window and zeroes the rest, wired through the existing PATH-slot/BroadcastLatentModel machinery with no new abstraction. Behaviour is correct (window bounds, zero-fill, AD-safe zero via eltype(latent), tree-label override) and tests cover fixed/estimated/process cases, edge windows and the manual-composition equivalence. The main nit is documentation length: the same PATH-slot and edge-window explanation is repeated near-verbatim across three places.
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.
|
|
||
| The result is a latent model that equals `model` on `window` and zero everywhere else, so summing it onto a base path with [`CombineLatentModels`](@ref) gives an effect that is active only over the window. | ||
|
|
||
| The `model` slot is a PATH slot, which is what lets one helper serve both a fixed and an estimated effect. |
There was a problem hiding this comment.
suggestion This paragraph repeats content already stated in three places: BroadcastLatentModel's own docstring (LatentModel.jl:67-70) covers the PATH-slot/auto-wrap behaviour, InWindow's docstring (rules.jl:44-58) covers the window semantics, and design.md's new 'How it is built' section restates both again. Trim broadcast_window's docstring to what is specific to the helper (that it composes BroadcastLatentModel with InWindow) and link to BroadcastLatentModel/InWindow for the shared behaviour, rather than re-explaining it a third time.
Review feedback. The closing sentence claimed a multiplicative window effect works in log space under an `exp` transform, and was the only claim in the section with no runnable block behind it. Add the block, and a test asserting the ratio to the unwindowed path is the effect inside the window and one outside. 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
|
Acted on the review. Accepted the one finding. The closing sentence on the multiplicative window was the only claim in the section with no runnable block behind it. It now has one, and a test asserting the ratio to the unwindowed path is the effect inside the window and exactly one outside. I checked the claim was true before writing the example rather than the other way round. I also reframed it while adding the code. The old wording said a multiplicative effect on a positive path is the composition in log space wrapped in Verification on this revision: full suite for this worktree excluding the Documenter is still unverified, and per #353 that is repo-wide: the shared This was opened by a bot. Please ping @seabbs for any questions. |
Benchmark comparison vs baseMinimum time per call. Buckets are PR time as a % of base, so lower is faster (🟢 faster, ⚪ within 5%, 🔴 slower). Counts of benchmarks per bucket:
Evaluation — 9 benchmarks (by time change)
AD gradients — 7 benchmarks (by time change)
|
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>
Closes #166.
The investigation on #166 found a windowed effect was already reachable by composing existing modifiers, and this PR started as documentation of that. Sam asked for a helper as well, so it now ships one.
broadcast_windowbroadcast_window(model, window)builds a latent model that equalsmodelonwindowand zero everywhere else. Summing it onto a base path withCombineLatentModelsconfines the effect to that window.It is a
BroadcastLatentModelunder a newInWindowrule, the same shapebroadcast_dayofweekhas underRepeatEach. No new component type, and it stacks by ordinary composition.One helper covers every effect form because the inner slot is a PATH slot.
FixedIntercept(2.0)gives a known constant, a bareDistributiongives one estimated level held across the window, and a process gives an effect that varies within it. The rule asks for a series as long as the window, so a process member is generated over the window rather than over the whole series and then masked.A window touching either end is an ordinary case. This is the one place the obvious alternative fails: partitioning the series with
ConcatLatentModelsneeds a zero-length segment for1:10and throwsAssertionError: Non-positive dimensions are not allowed. There is a test for each edge.The window is visible in the model tree
A
BroadcastLatentModeldoes what its rule says, not what its own type says, so the tree label now carries the rule.Before this a day-of-week effect and a windowed effect printed identically as bare
BroadcastLatentModel. The label is built from the type name rather than fromshow, becauseshowmodule-qualifies the rule name outside the package's own scope.src/base/prettyprinting.jlis in this diff because that label needed a seam:_node_label(model) = string(nameof(typeof(model)))is the previous expression verbatim, so every component that does not override it prints exactly as before, andBroadcastLatentModelis the single override.Docs
The
design.mdsection leads with the helper and keeps the from-scratch composition underneath, so the mechanism is still on the page. A test asserts the two routes agree, including that they draw the same prefixed parameter names, so a model can move to the helper without renaming anything.Tests
test/unit/latent_models/windowed.jl: the rule's placement and its assertion failures, the effect landing exactly on the window, zero contribution outside, the prefixed parameter names, both edge-touching windows and the whole-series window, a process member generated over the window, the tree label, and the equivalence with the from-scratch composition.Verification
:aditems: 2128 pass, 5 pre-existing broken, no failures (18m21s).Runic --check src test docs benchmark ext: exit 0.@example designblock in the new section runs in order in a clean module.Not verified: the full Documenter build. Its CI job was cancelled rather than failed on both attempts of the previous revision, and a local build did not finish. Treat the docs build as unconfirmed until CI reports green on this revision.
This was opened by a bot. Please ping @seabbs for any questions.
🤖 Generated with Claude Code
https://claude.ai/code/session_01UmmqqzQPhrB74RfAv2TqBQ