Skip to content

Commit 8b46258

Browse files
github-actions[bot]CompatHelper Juliasethaxen
authored
CompatHelper: bump compat for PosteriorStats in [weakdeps] to 0.3, (keep existing compat) (#100)
* CompatHelper: bump compat for PosteriorStats in [weakdeps] to 0.3, (keep existing compat) * Drop support for older PosteriorStats versions * Update/unify hdi/ci implementations * Update PosteriorStats tests * Add local InferenceObjects to docs sources * Fix typos in docstrings * Update doctests * Build docs with larger terminal width * Run formatter * Remove outdated version checks * Only use larger terminal width on extension doctests * Increment patch number * Revert "Only use larger terminal width on extension doctests" This reverts commit 8da4fa9. * Don't run extension doctests twice These already seem to be picked up by the main docs build * Remove accidentally-introduced div char * Only use SummaryStats' public API --------- Co-authored-by: CompatHelper Julia <[email protected]> Co-authored-by: Seth Axen <[email protected]>
1 parent 89d6e5f commit 8b46258

File tree

11 files changed

+135
-145
lines changed

11 files changed

+135
-145
lines changed

Project.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "InferenceObjects"
22
uuid = "b5cf5a8d-e756-4ee3-b014-01d49d192c00"
33
authors = ["Seth Axen <[email protected]> and contributors"]
4-
version = "0.4.12"
4+
version = "0.4.13"
55

66
[deps]
77
ANSIColoredPrinters = "a4c015fc-c6ff-483c-b24f-f7ea428134e9"
@@ -32,7 +32,7 @@ MLJBase = "1"
3232
NCDatasets = "0.12.6, 0.13, 0.14"
3333
OffsetArrays = "1"
3434
OrderedCollections = "1.6"
35-
PosteriorStats = "0.1.1, 0.2"
35+
PosteriorStats = "0.3"
3636
Random = "1"
3737
StatsBase = "0.33.7, 0.34"
3838
Tables = "1.11.0"

docs/Project.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ NCDatasets = "85f8d34a-cbdd-5861-8df4-14fed0d494ab"
88
PosteriorStats = "7f36be82-ad55-44ba-a5c0-b8b5480d7aa5"
99
StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"
1010

11+
[sources]
12+
InferenceObjects = {path = ".."}
13+
1114
[compat]
1215
Documenter = "1"
1316
DocumenterInterLinks = "1"

docs/make.jl

Lines changed: 30 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -29,34 +29,37 @@ doctestfilters = [
2929
r"\s+\"created_at\" => .*", # ignore timestamps in doctests
3030
]
3131

32-
makedocs(;
33-
modules=[
34-
InferenceObjects,
35-
Base.get_extension(InferenceObjects, :InferenceObjectsMCMCDiagnosticToolsExt),
36-
Base.get_extension(InferenceObjects, :InferenceObjectsPosteriorStatsExt),
37-
],
38-
authors="Seth Axen <[email protected]> and contributors",
39-
repo=Remotes.GitHub("arviz-devs", "InferenceObjects.jl"),
40-
sitename="InferenceObjects.jl",
41-
format=Documenter.HTML(;
42-
prettyurls=get(ENV, "CI", "false") == "true",
43-
canonical="https://arviz-devs.github.io/InferenceObjects.jl",
44-
edit_link="main",
45-
assets=String[],
46-
),
47-
pages=[
48-
"Home" => "index.md",
49-
"Dataset" => "dataset.md",
50-
"InferenceData" => "inference_data.md",
51-
"Extensions" => [
52-
"MCMCDiagnosticTools" => "extensions/mcmcdiagnostictools.md",
53-
"PosteriorStats" => "extensions/posteriorstats.md",
32+
# Increase the terminal width from 80 to 100 chars to avoid column truncation
33+
withenv("COLUMNS" => 100) do
34+
makedocs(;
35+
modules=[
36+
InferenceObjects,
37+
Base.get_extension(InferenceObjects, :InferenceObjectsMCMCDiagnosticToolsExt),
38+
Base.get_extension(InferenceObjects, :InferenceObjectsPosteriorStatsExt),
5439
],
55-
],
56-
doctestfilters=doctestfilters,
57-
warnonly=:missing_docs,
58-
plugins=[links],
59-
)
40+
authors="Seth Axen <[email protected]> and contributors",
41+
repo=Remotes.GitHub("arviz-devs", "InferenceObjects.jl"),
42+
sitename="InferenceObjects.jl",
43+
format=Documenter.HTML(;
44+
prettyurls=get(ENV, "CI", "false") == "true",
45+
canonical="https://arviz-devs.github.io/InferenceObjects.jl",
46+
edit_link="main",
47+
assets=String[],
48+
),
49+
pages=[
50+
"Home" => "index.md",
51+
"Dataset" => "dataset.md",
52+
"InferenceData" => "inference_data.md",
53+
"Extensions" => [
54+
"MCMCDiagnosticTools" => "extensions/mcmcdiagnostictools.md",
55+
"PosteriorStats" => "extensions/posteriorstats.md",
56+
],
57+
],
58+
doctestfilters=doctestfilters,
59+
warnonly=:missing_docs,
60+
plugins=[links],
61+
)
62+
end
6063

6164
# run doctests on extensions
6265
function get_extension(mod::Module, name::Symbol)
@@ -67,16 +70,6 @@ function get_extension(mod::Module, name::Symbol)
6770
end
6871
end
6972

70-
using MCMCDiagnosticTools: MCMCDiagnosticTools
71-
using PosteriorStats: PosteriorStats
72-
for extended_pkg in (MCMCDiagnosticTools, PosteriorStats)
73-
extension_name = Symbol("InferenceObjects", extended_pkg, "Ext")
74-
@info "Running doctests for extension $(extension_name)"
75-
mod = get_extension(InferenceObjects, extension_name)
76-
DocMeta.setdocmeta!(mod, :DocTestSetup, :(using $(Symbol(extended_pkg))))
77-
doctest(mod; manual=false)
78-
end
79-
8073
deploydocs(;
8174
repo="github.com/arviz-devs/InferenceObjects.jl", devbranch="main", push_preview=true
8275
)

ext/InferenceObjectsPosteriorStatsExt/InferenceObjectsPosteriorStatsExt.jl

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@ using InferenceObjects: InferenceObjects
66
using PosteriorStats: PosteriorStats
77
using StatsBase: StatsBase
88

9-
import PosteriorStats: hdi, loo, loo_pit, r2_score, summarize, waic
9+
import PosteriorStats: eti, hdi, loo, loo_pit, r2_score, summarize, waic
1010
import StatsBase: summarystats
1111

12-
export hdi, loo, loo_pit, r2_score, summarize, waic, summarystats
12+
export eti, hdi, loo, loo_pit, r2_score, summarize, waic, summarystats
13+
14+
maplayers = isdefined(DimensionalData, :maplayers) ? DimensionalData.maplayers : map
1315

1416
include("utils.jl")
15-
include("hdi.jl")
17+
include("ci.jl")
1618
include("loo.jl")
1719
include("waic.jl")
1820
include("loo_pit.jl")
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
2+
for (ci_fun, ci_desc) in
3+
(:eti => "equal-tailed interval (ETI)", :hdi => "highest density interval (HDI)")
4+
@eval begin
5+
# this pattern ensures that the type is completely specified at compile time
6+
@doc """
7+
$($ci_fun)(data::InferenceData; kwargs...) -> Dataset
8+
$($ci_fun)(data::Dataset; kwargs...) -> Dataset
9+
10+
Calculate the $($ci_desc) for each parameter in the data.
11+
12+
For more details and a description of the `kwargs`, see
13+
[`PosteriorStats.$($ci_fun)`](@extref).
14+
"""
15+
function PosteriorStats.$(ci_fun)(data::InferenceObjects.InferenceData; kwargs...)
16+
return PosteriorStats.$(ci_fun)(data.posterior; kwargs...)
17+
end
18+
function PosteriorStats.$(ci_fun)(data::InferenceObjects.Dataset; kwargs...)
19+
ds = maplayers(data) do var
20+
return _as_dimarray(
21+
PosteriorStats.$(ci_fun)(_params_array(var); kwargs...), var
22+
)
23+
end
24+
return DimensionalData.rebuild(ds; metadata=DimensionalData.NoMetadata())
25+
end
26+
end
27+
end

ext/InferenceObjectsPosteriorStatsExt/hdi.jl

Lines changed: 0 additions & 37 deletions
This file was deleted.

ext/InferenceObjectsPosteriorStatsExt/loo.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ julia> idata = load_example_data("centered_eight");
1919
2020
julia> loo(idata)
2121
PSISLOOResult with estimates
22-
elpd elpd_mcse p p_mcse
23-
-31 1.4 0.9 0.33
22+
elpd se_elpd p se_p
23+
-31 1.4 0.9 0.33
2424
2525
and PSISResult with 500 draws, 4 chains, and 8 parameters
2626
Pareto shape (k) diagnostic values:

ext/InferenceObjectsPosteriorStatsExt/summarize.jl

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ function StatsBase.summarystats(data::InferenceObjects.Dataset; kwargs...)
1313
end
1414

1515
@doc """
16-
summarize(data::InferenceData, group=:posterior, stats_funs...; kwargs...)
16+
summarize(data::InferenceData, stats_funs...; group=:posterior, kwargs...)
1717
summarize(data::Dataset, stats_funs...; kwargs...)
1818
1919
Compute summary statistics for the data using the provided functions.
2020
21-
For verbose variable labels, provide `compat_labels=false`. For details on `stats_funs` and
21+
For verbose variable labels, provide `compact_labels=false`. For details on `stats_funs` and
2222
`kwargs`, see [`PosteriorStats.summarize`](@extref).
2323
2424
# Examples
@@ -33,18 +33,17 @@ julia> data = load_example_data("centered_eight");
3333
3434
julia> summarize(data)
3535
SummaryStats
36-
mean std hdi_3% hdi_97% mcse_mean mcse_std ess ⋯
37-
mu 4.2 3.3 -1.61 10.3 0.21 0.088 ⋯
38-
theta[Choate] 6.4 5.9 -3.68 17.9 0.25 0.20 ⋯
39-
theta[Deerfield] 5.0 4.9 -4.98 13.4 0.21 0.15 ⋯
40-
theta[Phillips Andover] 3.4 5.4 -7.54 12.9 0.23 0.17 ⋯
41-
theta[Phillips Exeter] 4.8 5.2 -5.11 14.1 0.21 0.21 ⋯
42-
theta[Hotchkiss] 3.5 4.8 -6.12 12.0 0.25 0.15 ⋯
43-
theta[Lawrenceville] 3.7 5.2 -6.50 12.7 0.22 0.21 ⋯
44-
theta[St. Paul's] 6.5 5.2 -2.67 16.9 0.22 0.15 ⋯
45-
theta[Mt. Hermon] 4.8 5.7 -5.97 15.4 0.24 0.23 ⋯
46-
tau 4.3 3.0 0.715 9.41 0.22 0.14 ⋯
47-
3 columns omitted
36+
mean std eti94 ess_tail ess_bulk rhat mcse_mean mcse_std
37+
mu 4.2 3.3 -2.11 .. 9.90 622 241 1.03 0.21 0.088
38+
theta[Choate] 6.4 5.9 -3.05 .. 19.1 937 572 1.01 0.25 0.20
39+
theta[Deerfield] 5.0 4.9 -4.49 .. 14.2 1214 532 1.01 0.21 0.15
40+
theta[Phillips Andover] 3.4 5.4 -8.17 .. 12.7 1017 511 1.01 0.23 0.17
41+
theta[Phillips Exeter] 4.8 5.2 -4.84 .. 14.5 911 572 1.01 0.21 0.21
42+
theta[Hotchkiss] 3.5 4.8 -6.11 .. 12.0 789 347 1.02 0.25 0.15
43+
theta[Lawrenceville] 3.7 5.2 -6.62 .. 12.6 957 506 1.01 0.22 0.21
44+
theta[St. Paul's] 6.5 5.2 -2.38 .. 18.3 1031 528 1.01 0.22 0.15
45+
theta[Mt. Hermon] 4.8 5.7 -5.52 .. 16.0 1045 538 1.01 0.24 0.23
46+
tau 4.3 3.0 1.06 .. 11.5 214 128 1.03 0.22 0.14
4847
```
4948
5049
Compute the mean, standard deviation, median, and median absolute deviation of the `theta`

ext/InferenceObjectsPosteriorStatsExt/utils.jl

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,17 @@ function observations_and_predictions(
159159
end
160160
end
161161

162+
# reshape to (ndraws, nchains, nparams...) and drop the dimensions
163+
function _params_array(data)
164+
sample_dims = Dimensions.dims(data, InferenceObjects.DEFAULT_SAMPLE_DIMS)
165+
param_dims = Dimensions.otherdims(data, sample_dims)
166+
dims_combined = Dimensions.combinedims((sample_dims..., param_dims...))
167+
Dimensions.dimsmatch(Dimensions.dims(data), dims_combined) && return data
168+
return PermutedDimsArray(data, dims_combined)
169+
end
170+
162171
_as_dimarray(x::DimensionalData.AbstractDimArray, ::DimensionalData.AbstractDimArray) = x
163-
function _as_dimarray(x::Union{Real,Missing}, arr::DimensionalData.AbstractDimArray)
172+
function _as_dimarray(x, arr::DimensionalData.AbstractDimArray)
164173
return Dimensions.rebuild(arr, fill(x), ())
165174
end
166175

ext/InferenceObjectsPosteriorStatsExt/waic.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ julia> idata = load_example_data("centered_eight");
1919
2020
julia> waic(idata)
2121
WAICResult with estimates
22-
elpd elpd_mcse p p_mcse
23-
-31 1.4 0.9 0.32
22+
elpd se_elpd p se_p
23+
-31 1.4 0.9 0.32
2424
```
2525
"""
2626
function PosteriorStats.waic(

0 commit comments

Comments
 (0)