Repository navigation
fix(Aggregate): right-align a delay nested inside an aggregation - #307
Merged
Merged
Conversation
An observation modifier nested inside an `Aggregate` shortens the window series, so the inner model returns fewer predictions than there are present windows and the scatter back to full length failed to build. Scatter onto the windows that survive, dropping the leading ones as every other observation chain does. Right-align a shorter expected series to the observed series too, so a delay applied outside the aggregation composes as well. Record in the docstring that the nesting decides whether the delay is in windows or in time points.
This was referenced Aug 20, 2026
Contributor
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="fix/aggregate-delay-right-align")
using ComposableTuringIDModelsOption 2: Local CheckoutIf you have the repo locally: git checkout fix/aggregate-delay-right-align
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:
|
seabbs
marked this pull request as ready for review
August 20, 2026 16:08
This was referenced Aug 20, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #292.
A
LatentDelaynested inside anAggregateshortened the window series, sothe inner model returned fewer predictions than there were present windows and
the scatter back to full length raised
DimensionMismatch.What changed
_return_aggregatenow places the inner predictions on the lastlength(pred_obs)reporting windows, dropping the leading ones. That is theissue's first option and it matches the right-alignment every other observation
chain in the package already uses.
Aggregatealso right-aligns aY_tthat is shorter thany_t, so the othernesting composes too (see below).
The docstring gains two sentences naming both orders and the units each gives.
No warning, no unit conversion.
Confirming the "partial window" reading
The issue's first option was described as resting on "a partially covered
window is dropped". That reading does not hold against the code. A window
reaching back before the start of the series is clipped, not dropped —
sum(Y_t[max(1, i - aggregation[i] + 1):i])sums whatever days exist.The right-alignment is still correct, but for a different reason:
LatentDelayitself right-aligns and drops its own leading entries, and the scatter simply
follows the alignment its inner model already chose. No new concept is needed,
and the existing clipping behaviour at the start of a series is unchanged.
A second bug, found while writing the docstring
The docstring is required to name both orders as valid. The other order did not
work:
Aggregatesized its windows offy_twhile indexingY_t, so a delay appliedoutside the aggregation ran off the end. Fixed with the same right-alignment
statement: a shorter
Y_tcovers the lastlength(Y_t)time points, and windowindices shift by the offset. A window reaching back before the start of
Y_tisclipped, exactly as one reaching before time 1 already was.
This is beyond the letter of #292 but not beyond its subject, and documenting an
order that raises
BoundsErrorwas not an option.Units, pinned by test
With weekly windows over 28 days, a spike on the last day of each window, and a
point-mass delay of lag two:
expectedat days 7, 14, 21, 28Aggregate(LatentDelay(...), agg)0, 0, 1, 2LatentDelay(Aggregate(...), pmf)0, 1, 2, 3Also tested: a delay exactly as long as the window series leaves one window, and
a delay longer than the window series throws.
Tests
Run in this worktree, on this branch:
Pkg.test(test_args = ["skip_quality"])— 1255 pass, 0 fail (21m44s).Pkg.test(test_args = ["quality_only"])— passed (Aqua, JET, formatting,doctests).
julia --project=test/ad test/ad/runtests.jl forwarddiff— 1008 pass,0 fail. The
DirectInfections+AggregateAD scenario is in that set.srcandtest.This was opened by a bot. Please ping @seabbs for any questions.