Skip to content

Commit

Permalink
change default LatentDelay constructor to right truncation at 99th pe…
Browse files Browse the repository at this point in the history
…rc (#265)

* change default LatentDelay constructor to right truncation at 99th perc

* update docstring
  • Loading branch information
SamuelBrand1 committed Jun 9, 2024
1 parent e73fd9e commit 4688d20
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
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

0 comments on commit 4688d20

Please sign in to comment.