Skip to content

forecast treats BinomialError's (y, N) data as two observation streams #273

Open

Description

@seabbs-bot

forecast and IDProblem read a NamedTuple of observation data as a
NamedTuple of observation streams. That is right for a Split, and wrong
for an error model whose data contract is a single stream carrying extra
per-time-point fields — BinomialError's (y = successes, N = trials).

Reproduction

model = IDModel(
    DirectInfections(; Z = RandomWalk(), initialisation = Normal(-3.0, 0.2)),
    BinomialError())
T = 10
y = (y = fill(20, T), N = fill(1000, T))
chain = sample(as_turing_model(model, y, T), Prior(), 10; progress = false)
forecast(model, y, chain, 3)
# ERROR: RandomWalk produces one path. Wrap it in a `Stratify` to give it a
# strata axis.

Three places that assume "one field per stream"

  • _obs_data_shape(obs, y_t::NamedTuple, time_steps) returns
    (infection_strata(obs, length(y_t)), time_steps), so (y = …, N = …)
    builds a two-stratum infection process. This runs at IDProblem build
    time too, not only in forecast.
  • _extend_series(y::NamedTuple, horizon) extends every field, so the
    trials vector N is padded with missing and no longer satisfies
    _binomial_trials.
  • _series_time_length(y::NamedTuple) reads the first field, which is N
    for (N = 10, y = …) and errors outright for a scalar N.

What needs deciding

Extending y over a horizon is well defined (pad with missing), extending
N is not: future trial counts are data the model cannot invent. So this
needs a decision on how a user supplies the horizon's extra fields, or an
explicit error saying forecast does not support this data contract, rather
than the current shape confusion.

Found while fixing #264. That issue (a missing entry in NamedTuple data
being written into the caller's array and frozen as data) is fixed in #272;
this is a separate defect in the same area and is not covered there.

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

Activity

  1. seabbs-bot commented on Sep 5, 2026

    @seabbs-bot
    CollaboratorAuthor

    Status after #363 and #373.

    The first of the three places is fixed by #363.
    _obs_data_shape now asks the observation model which axes of its data are streams, and an error family answers with the axis of its y field, so (y, N) builds a single-series infection process through IDProblem, the two-argument as_turing_model and forecast alike.

    The other two stand.
    _extend_series(y::NamedTuple, horizon) still pads every field, N included, and _series_time_length(y::NamedTuple) still reads whichever field comes first.
    The decision the issue asks for, how a caller supplies the horizon's trial counts, is still open, so this stays open for that half.


    Generated by Claude Code

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