Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change default LatentDelay constructor to right truncation at 99th perc #265

Merged
merged 2 commits into from
Jun 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions EpiAware/src/EpiObsModels/LatentDelay.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@ observed data.
- `pmf::T`: The probability mass function (PMF) representing the delay distribution.

## Constructors
- `LatentDelay(model::M, distribution::C; D = 15, Δd = 1.0) where {M <: AbstractTuringObservationModel, C <: ContinuousDistribution}`: Constructs a `LatentDelay` object with the given underlying observation model and continuous distribution. The `D` parameter specifies the number of discrete delay intervals, and the `Δd` parameter specifies the width of each delay interval.
- `LatentDelay(model::M, distribution::C; D = nothing, Δd = 1.0)
where {M <: AbstractTuringObservationModel, C <: ContinuousDistribution}`: Constructs
a `LatentDelay` object with the given underlying observation model and continuous
distribution. The `D` parameter specifies the right truncation of the distribution,
with default `D = nothing` indicating that the distribution should be truncated at its
99th percentile rounded to nearest integer. The `Δd` parameter specifies the
width of each delay interval.

- `LatentDelay(model::M, pmf::T) where {M <: AbstractTuringObservationModel, T <: AbstractVector{<:Real}}`: Constructs a `LatentDelay` object with the given underlying observation model and delay PMF.

Expand All @@ -26,9 +32,12 @@ struct LatentDelay{M <: AbstractTuringObservationModel, T <: AbstractVector{<:Re
model::M
pmf::T

function LatentDelay(model::M, distribution::C; D = 15,
function LatentDelay(model::M, distribution::C; D = nothing,
Δd = 1.0) where {
M <: AbstractTuringObservationModel, C <: ContinuousDistribution}
if isnothing(D)
D = invlogcdf(distribution, log(0.99)) |> round
end
pmf = censored_pmf(distribution; Δd = Δd, D = D)
return LatentDelay(model, pmf)
end
Expand Down
10 changes: 10 additions & 0 deletions EpiAware/test/EpiObsModels/LatentDelay.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@

@test obs_model.model == dummy_model
@test length(obs_model.pmf) == D_delay

# Test case 3: check default right truncation
delay_distribution = Gamma(3, 15 / 3)
D_delay = nothing
Δd = 1.0

obs_model = LatentDelay(dummy_model, delay_distribution, D = D_delay, Δd = Δd)

nn_perc_rounded = invlogcdf(delay_distribution, log(0.99)) |> x -> round(Int64, x)
@test length(obs_model.pmf) == nn_perc_rounded
end

@testitem "Testing delay obs against theoretical properties" begin
Expand Down
Loading