Skip to content

Support observation windows shorter than the right-truncation PMF - #894

Open
developer-rpai wants to merge 1 commit into
CDCgov:mainfrom
developer-rpai:fix/short-observation-window-714
Open

developer-rpai wants to merge 1 commit into
CDCgov:mainfrom
developer-rpai:fix/short-observation-window-714

Conversation

@developer-rpai

Copy link
Copy Markdown

Closes #714.

What this does

compute_prop_already_reported no longer requires the observation window to
cover the full reporting-delay PMF support. When the prediction vector is
shorter than the delay support (minus right_truncation_offset), the function
now returns the trailing slice of the reported-proportion tail, i.e. the
proportions for the most recent timepoints. _apply_right_truncation drops the
ValueError that forced callers to pad short windows, so short observation
windows just work.

Root cause

The function built its output as [ones(n_pad), tail] with
n_pad = n_timepoints - len(tail). For a short window n_pad goes negative,
which died inside JAX with a cryptic TypeError: broadcast_in_dim shape must have every element be nonnegative, and the model-level caller raised its own
ValueError before even getting there. The tail is ordered oldest to newest
with tail[0] = 1.0, so a short window covering only recent timepoints is
exactly tail[len(tail) - n_timepoints:]. Full-window behavior is unchanged.

Reproduction (pristine code)

from pyrenew.convolve import compute_prop_already_reported
import jax.numpy as jnp
compute_prop_already_reported(jnp.array([0.5, 0.3, 0.2]), 2, 0)
# TypeError: broadcast_in_dim shape must have every element be nonnegative, got (-1,)

After the fix this returns [0.8, 0.5], matching the last two entries of the
full-window result [1.0, 1.0, 1.0, 0.8, 0.5].

Tests

  • test/test_convolve.py: new test_compute_prop_already_reported_short_window
    (hand-calculated values, including the boundary where the window exactly
    matches the tail length) and
    test_compute_prop_already_reported_short_window_matches_full (short-window
    output equals the trailing entries of the full-window output, over window
    lengths 1..5 and offsets 0..1).
  • test/test_observation_counts.py: TestRightTruncation:: test_short_observation_window_raises rewritten as
    test_short_observation_window_supported, asserting via the
    prop_already_reported deterministic site that a 2-day window with PMF
    [0.2, 0.3, 0.5] yields [0.5, 0.2].

Results: test_convolve.py 40 passed, test_observation_counts.py 96 passed
(136 total). ruff check and ruff format --check clean on all touched files.

Note: this sandbox runs Python 3.12 while the package declares >=3.13, so the
editable install was skipped and tests ran with PYTHONPATH instead. The
touched code paths are version agnostic, but CI is the final judge.

Generalizes compute_prop_already_reported so that a prediction vector
shorter than the reporting-delay PMF support returns the trailing slice
of the reported-proportion tail instead of failing. _apply_right_truncation
no longer requires the observation window to cover the full delay
support. Closes CDCgov#714.

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support prediction vectors shorter than the right-truncation PMF in compute_prop_already_reported

1 participant