-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
breakdown mcmc convergence test function
Adds more stats and a unit test
- Loading branch information
1 parent
73e80c1
commit 727a827
Showing
3 changed files
with
74 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
@testset "test MCMC convergence analysis on toy obs model" begin | ||
using JLD2, DataFramesMeta, Turing, EpiAware | ||
# Reuse the local config | ||
_output = load(joinpath(@__DIR__(), "test_data.jld2")) | ||
inference_config = _output["inference_config"] | ||
# Create a simple test model to test mcmc diagnostics via prior sampling | ||
obs = make_observation_model(SmoothEndemicPipeline()) | ||
@model function test_model() | ||
x ~ filldist(Normal(0, 1), 20) | ||
@submodel prefix="obs" y_t=generate_observations(obs, missing, exp.(x)) | ||
end | ||
n = 1000 | ||
samples = sample(test_model(), Prior(), n) | ||
|
||
# Create a simple output to test the function | ||
output = Dict( | ||
"inference_config" => inference_config, | ||
"inference_results" => (; samples,) | ||
) | ||
|
||
true_mean_gi = 10.0 | ||
scenario = "rough_endemic" | ||
df = make_mcmc_diagnostic_dataframe( | ||
output, true_mean_gi, "rough_endemic") | ||
# Check pass throughs | ||
@test typeof(df) == DataFrame | ||
@test size(df, 1) == 3 # Number of rows should match the length of used_gi_means | ||
@test df[1, :Scenario] == scenario | ||
@test df[1, :latent_model] == inference_config["latent_model"] | ||
@test df[1, :True_GI_Mean] == true_mean_gi | ||
# Prior sampling should be uncorrelated and meet all the convergence criteria | ||
@test all(df[:, :ess_bulk_prop_pass] .== 1.0) | ||
@test all(df[:, :ess_tail_prop_pass] .== 1.0) | ||
@test all(df[:, :rhat_diff_prop_pass] .== 1.0) | ||
@test all(df[:, :has_cluster_factor] .== true) | ||
@test all(df[1, :cluster_factor_tail] .> n / 2) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
include("make_prediction_dataframe_from_output.jl") | ||
include("make_truthdata_dataframe.jl") | ||
include("make_mcmc_diagnostic_dataframe.jl") |