Closed damonbayer closed 2 months ago
I think the previous version was to allow the kind of behavior we've now decided to forbid. But I agree with forbidding it, at least by default.
The issue is actually more with the post-convolve indexing, but this change makes it easier to avoid that error.
The issue is actually more with the post-convolve indexing, but this change makes it easier to avoid that error.
Can you point me to the issue/error that is being referenced here for my knowledge? @damonbayer @dylanhmorris
With mode="full"
you will get results that implicitly pad the arrays with with 0's. When using mode="valid"
, this does not happen.
With mode="full"
, you then have to slice the head and the tail of the resulting array to get the desired output. With mode="valid"
you only need the tail.
With
mode="full"
, you then have to slice the head and the tail of the resulting array to get the desired output. Withmode="valid"
you only need the tail.
The current implementation only includes slicing one end of the array resulting from convolution.
Using mode = "valid"
results in latent_hospital_admissions
array smaller than desired shape i.e latent_hospital_admissions_raw.shape[0]
. Did you want to say mode = "same"
?
Using
mode = "valid"
results inlatent_hospital_admissions
array smaller than desired shape i.elatent_hospital_admissions_raw.shape[0]
. Did you want to saymode = "same"
?
No, the "valid" mode is correct. The desired shape in the end should be the length of the observed admissions. We can do that here or later on in the "model" code.
The desired shape in the end should be the length of the observed admissions. We can do that here or later on in the "model" code.
Right! We want the final latent_hospital_admission
same length as observed_hosp_admissions
. But convolve mode = "valid"
yields latent_hospital_admissions
array with length smaller than observed_hosp_admissions
.
But convolve
mode = "valid"
yieldslatent_hospital_admissions
array with length smaller thanobserved_hosp_admissions
.
What are the lengths of the relevant quantities?
But convolve
mode = "valid"
yieldslatent_hospital_admissions
array with length smaller thanobserved_hosp_admissions
.What are the lengths of the relevant quantities?
latent_hospital_admissions = jnp.convolve(
latent_hospital_admissions_raw,
infection_to_admission_interval.value,
mode="full",
)[:latent_hospital_admissions_raw.shape[0]]
latent_hospital_admissions.shape
# (105, )
latent_hospital_admissions = jnp.convolve(
latent_hospital_admissions_raw,
infection_to_admission_interval.value,
mode="valid",
)
latent_hospital_admissions.shape
# (51, )
observed_hosp_admissions.shape
# (90, )
We should use
mode="valid"
to ensure the output reflects the entireinfection_to_admission_interval
being used.https://github.com/CDCgov/multisignal-epi-inference/blob/main/model/src/pyrenew/latent/hospitaladmissions.py#L189-L193
I believe these lines should be replaced with