Support observation windows shorter than the right-truncation PMF - #894
Open
developer-rpai wants to merge 1 commit into
Open
developer-rpai wants to merge 1 commit into
developer-rpai wants to merge 1 commit into
Conversation
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.
developer-rpai
requested review from
cdc-mitzimorris,
dylanhmorris and
sbidari
as code owners
September 24, 2026 05:44
This branch has not been deployed
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.
Closes #714.
What this does
compute_prop_already_reportedno longer requires the observation window tocover the full reporting-delay PMF support. When the prediction vector is
shorter than the delay support (minus
right_truncation_offset), the functionnow returns the trailing slice of the reported-proportion tail, i.e. the
proportions for the most recent timepoints.
_apply_right_truncationdrops theValueErrorthat forced callers to pad short windows, so short observationwindows just work.
Root cause
The function built its output as
[ones(n_pad), tail]withn_pad = n_timepoints - len(tail). For a short windown_padgoes 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 ownValueErrorbefore even getting there. The tail is ordered oldest to newestwith
tail[0] = 1.0, so a short window covering only recent timepoints isexactly
tail[len(tail) - n_timepoints:]. Full-window behavior is unchanged.Reproduction (pristine code)
After the fix this returns
[0.8, 0.5], matching the last two entries of thefull-window result
[1.0, 1.0, 1.0, 0.8, 0.5].Tests
test/test_convolve.py: newtest_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-windowoutput 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_raisesrewritten astest_short_observation_window_supported, asserting via theprop_already_reporteddeterministic site that a 2-day window with PMF[0.2, 0.3, 0.5]yields[0.5, 0.2].Results:
test_convolve.py40 passed,test_observation_counts.py96 passed(136 total).
ruff checkandruff format --checkclean 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
PYTHONPATHinstead. Thetouched code paths are version agnostic, but CI is the final judge.