diff --git a/EpiAware/src/EpiObsModels/LatentDelay.jl b/EpiAware/src/EpiObsModels/LatentDelay.jl index ce4939ffc..028428597 100644 --- a/EpiAware/src/EpiObsModels/LatentDelay.jl +++ b/EpiAware/src/EpiObsModels/LatentDelay.jl @@ -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. @@ -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 diff --git a/EpiAware/test/EpiObsModels/LatentDelay.jl b/EpiAware/test/EpiObsModels/LatentDelay.jl index 582c6aeae..4737022d2 100644 --- a/EpiAware/test/EpiObsModels/LatentDelay.jl +++ b/EpiAware/test/EpiObsModels/LatentDelay.jl @@ -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