Skip to content

Commit

Permalink
make failrues of two_sample_ad_test produce more informative logs
Browse files Browse the repository at this point in the history
  • Loading branch information
torfjelde committed Jun 6, 2024
1 parent e1e7386 commit be1ec7f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
2 changes: 1 addition & 1 deletion test/experimental/gibbs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ has_dot_assume(::Model) = true
xs = Array(chain)
xs_true = Array(chain_true)
for i = 1:size(xs, 2)
@test two_sample_ad_test(xs[:, i], xs_true[:, i])
@test two_sample_ad_test(xs[:, i], xs_true[:, i]; warn_on_fail=true)
# Let's make sure that the significance level is not too low by
# checking that the KS test fails for some simple transformations.
# TODO: Replace the heuristic below with closed-form implementations
Expand Down
19 changes: 14 additions & 5 deletions test/test_utils/numerical_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -83,18 +83,27 @@ function check_MoGtest_default_z_vector(chain; atol=0.2, rtol=0.0)
end

"""
two_sample_ad_test(xs_left, xs_right; α=1e-3)
two_sample_ad_test(xs_left, xs_right; α=1e-3, warn_on_fail=false)
Perform a two-sample Anderson-Darling (AD) test on the two samples `xs_left` and `xs_right`.
# Arguments
- `xs_left::AbstractVector`: samples from the first distribution.
- `xs_right::AbstractVector`: samples from the second distribution.
# Keyword arguments
- `α::Real`: significance level for the test. Default: `1e-3`.
- `warn_on_fail::Bool`: whether to warn if the test fails. Default: `false`.
Makes failures a bit more informative.
"""
function two_sample_ad_test(xs_left, xs_right; α=1e-3)
function two_sample_ad_test(xs_left, xs_right; α=1e-3, warn_on_fail=false)
t = HypothesisTests.KSampleADTest(xs_left, xs_right)
# Just a way to make the logs a bit more informative in case of failure.
if HypothesisTests.pvalue(t) > α
@test true
true
else
@warn "Two-sample AD test failed with p-value $(HypothesisTests.pvalue(t))"
@test false
warn_on_fail && @warn "Two-sample AD test failed with p-value $(HypothesisTests.pvalue(t))"
false
end
end

Expand Down

0 comments on commit be1ec7f

Please sign in to comment.