Skip to content

Commit 76a614a

Browse files
authored
docs: Fix failing doctest for almost-zero model weights (#97)
* docs: Show weights NamedTuples instead of pairs in doctests * docs: Relax doctest filter to pass on small but nonzero numbers * chore: Update changelog
1 parent c27e0da commit 76a614a

3 files changed

Lines changed: 10 additions & 15 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
### Documentation
2222

2323
- Fix shape of expected array in LOO docs ([#96](https://github.com/arviz-devs/PosteriorStats.jl/pull/96))
24+
- Fix failing doctest for almost-zero model weights ([#97](https://github.com/arviz-devs/PosteriorStats.jl/pull/97))
2425

2526
## v0.4.8 (2026-03-07)
2627

src/compare.jl

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ The ELPD is estimated by Pareto smoothed importance sampling leave-one-out cross
2727
2828
Compare the centered and non centered models of the eight school problem:
2929
30-
```jldoctest compare; filter = [r"└.*", r"(\\d+\\.\\d{3})\\d*" => s"\\1"]
30+
```jldoctest compare; filter = [r"└.*", r"(\\d+\\.\\d{3})\\d*" => s"\\1", r"(centered\\s*=\\s*)(?:0\\.0|[-+]?\\d+(?:\\.\\d+)?e-(?:1[5-9]|[2-9]\\d|1\\d{2,}))" => s"\\g<1>0.0"]
3131
julia> using ArviZExampleData
3232
3333
julia> models = (
@@ -42,10 +42,8 @@ ModelComparisonResult with Stacking weights
4242
rank elpd se_elpd elpd_diff se_elpd_diff weight p se_p
4343
non_centered 1 -31 1.5 0 0.0 1.0 0.9 0.32
4444
centered 2 -31 1.4 0.03 0.061 0.0 0.9 0.33
45-
julia> mc.weight |> pairs
46-
pairs(::NamedTuple) with 2 entries:
47-
:non_centered => 1.0
48-
:centered => 3.50546e-31
45+
julia> mc.weight
46+
(non_centered = 1.0, centered = 0.0)
4947
```
5048
5149
Compare the same models from pre-computed PSIS-LOO results and computing

src/model_weights.jl

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ See also: [`AbstractModelWeightsMethod`](@ref), [`compare`](@ref)
2929
3030
Compute [`Stacking`](@ref) weights for two models:
3131
32-
```jldoctest model_weights; filter = [r"└.*", r"(\\d+\\.\\d{3})\\d*" => s"\\1"]
32+
```jldoctest model_weights; filter = [r"└.*", r"(\\d+\\.\\d{3})\\d*" => s"\\1", r"(centered\\s*=\\s*)(?:0\\.0|[-+]?\\d+(?:\\.\\d+)?e-(?:1[5-9]|[2-9]\\d|1\\d{2,}))" => s"\\g<1>0.0"]
3333
julia> using ArviZExampleData
3434
3535
julia> models = (
@@ -44,19 +44,15 @@ julia> elpd_results = map(models) do idata
4444
┌ Warning: 1 parameters had Pareto shape values 0.7 < k ≤ 1. Resulting importance sampling estimates are likely to be unstable.
4545
└ @ PSIS ~/.julia/packages/PSIS/...
4646
47-
julia> model_weights(elpd_results; method=Stacking()) |> pairs
48-
pairs(::NamedTuple) with 2 entries:
49-
:centered => 3.50546e-31
50-
:non_centered => 1.0
47+
julia> model_weights(elpd_results; method=Stacking())
48+
(centered = 0.0, non_centered = 1.0)
5149
```
5250
5351
Now we compute [`BootstrappedPseudoBMA`](@ref) weights for the same models:
5452
55-
```jldoctest model_weights; setup = :(using Random; Random.seed!(94))
56-
julia> model_weights(elpd_results; method=BootstrappedPseudoBMA()) |> pairs
57-
pairs(::NamedTuple) with 2 entries:
58-
:centered => 0.492513
59-
:non_centered => 0.507487
53+
```jldoctest model_weights; setup = :(using Random; Random.seed!(94)), filter = [r"(=\\s+0\\.\\d{2})\\d*" => s"\\1"]
54+
julia> model_weights(elpd_results; method=BootstrappedPseudoBMA())
55+
(centered = 0.492513, non_centered = 0.507487)
6056
```
6157
6258
# References

0 commit comments

Comments
 (0)