Skip to content

Aggregate indexes the expected series at the data step #315

Closed as not planned

Description

@seabbs-bot

Found while right-aligning BinomialError's trials vector (#306).

Aggregate sizes everything off the data and then indexes the expected
series at the data step:

n = length(y_t)
aggregation = broadcast_rule(RepeatEach(), ag.aggregation, n, m)
present = broadcast_rule(RepeatEach(), ag.present, n, m)
agg_Y_t = map(findall(present)) do i
    sum(Y_t[max(1, i - aggregation[i] + 1):i])
end

i runs over the observation series, so when the two series differ in
length the windows are taken from the wrong end of Y_t.

Since #302 the error families right-align the observed and expected series
and score their overlap, so a stream whose expected series is longer than
its data is a supported shape — exactly what a Split branch with a
shorter lead-in produces. Wrapping such a branch in Aggregate sums the
head of Y_t against observations that belong to its tail. Nothing errors;
the windows are just silently off by the difference in lengths. In the
other direction (y_t longer than Y_t, the chain's own lead-in) the
Y_t[...] slice runs past the end of the series.

Suggested fix

Give Aggregate the same alignment the error families now use: compute the
offset between the two series, take the aggregation windows off the end of
Y_t, and hand the inner model a data series and an expected series that
are right-aligned with one another.

Related

ReportTriangle has the same equal-length assumption, but asserts it
(size(observed, 1) == n) rather than misaligning, so a shorter data
triangle fails loudly. It would need the same treatment before a
ReportTriangle branch could sit under a Split with unequal lead-ins.

This was opened by a bot. Please ping @seabbs for any questions.

Activity

  1. seabbs-bot commented on Aug 20, 2026

    @seabbs-bot
    CollaboratorAuthor

    Withdrawing this. I read Aggregate.jl in a worktree that had not yet merged main, so the code I quoted was already out of date when I filed.

    On main, #307 replaced that block with an explicit alignment offset:

    offset = n - length(Y_t)
    agg_Y_t = map(idx) do i
        sum(Y_t[max(1, i - aggregation[i] + 1 - offset):max(0, i - offset)])
    end

    which handles both directions. With Y_t longer than the data the offset is negative, so the last data step reads Y_t[length(Y_t)] and the windows come off the tail rather than the head — the behaviour I claimed was missing.

    #301 already covers this, and looks resolved by the same change. The ReportTriangle half of what I wrote here is real and separate, so I have moved it to its own issue rather than leaving it buried in a withdrawn one.

    Apologies for the noise.

    This was posted by a bot. Please ping @seabbs for any questions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions