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

Issue 561: Soft min transformation #562

Merged
merged 1 commit into from
Dec 19, 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
22 changes: 21 additions & 1 deletion pipeline/src/constructors/make_observation_model.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
Constructs an observation model for the given pipeline. This is the defualt method.
Constructs an observation model for the given pipeline. This is the default method.

# Arguments
- `pipeline::AbstractEpiAwarePipeline`: The pipeline for which the observation model is constructed.
Expand All @@ -18,3 +18,23 @@ function make_observation_model(pipeline::AbstractEpiAwarePipeline)
obs = LatentDelay(dayofweek_logit_ascert, delay_distribution)
return obs
end

const negC = -1e15
"""
Soft minimum function for a smooth transition from `x -> x` to a maximum value of 1e15.
"""
_softmin(x) = -logaddexp(negC, -x)

function make_observation_model(pipeline::AbstractRtwithoutRenewalPipeline)
default_params = make_default_params(pipeline)
#Model for ascertainment based on day of the week
dayofweek_logit_ascert = ascertainment_dayofweek(
NegativeBinomialError(cluster_factor_prior = HalfNormal(default_params["cluster_factor"]));
transform = (x, y) -> _softmin.(x .* y))

#Default continuous-time model for latent delay in observations
delay_distribution = make_delay_distribution(pipeline)
#Model for latent delay in observations
obs = LatentDelay(dayofweek_logit_ascert, delay_distribution)
return obs
end
8 changes: 3 additions & 5 deletions pipeline/test/pipeline/test_pipelinefunctions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,14 @@ end

@testset "do_inference tests" begin
function make_inference(pipeline)
truthdata_dg_task = do_truthdata(pipeline)
truthdata = fetch.(truthdata_dg_task)
truthdata = do_truthdata(pipeline)
do_inference(truthdata[1], pipeline)
end

for pipetype in [SmoothOutbreakPipeline, MeasuresOutbreakPipeline,
SmoothEndemicPipeline, RoughEndemicPipeline]
pipeline = pipetype(; ndraws = 20, nchains = 1, testmode = true)
inference_results_tsk = make_inference(pipeline)
inference_results = fetch.(inference_results_tsk)
pipeline = pipetype(; ndraws = 1000, nchains = 1, testmode = true)
inference_results = make_inference(pipeline)
@test length(inference_results) == 1
@test all([result["inference_results"] isa EpiAwareObservables
for result in inference_results])
Expand Down
Loading