Skip to content

Make Chains objects display only information and not statistical eval #307

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

Merged
Merged
Show file tree
Hide file tree
Changes from 6 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
2 changes: 2 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ version = "6.0.7"
[deps]
AbstractMCMC = "80f14c24-f653-4e6a-9b94-39d6b0f70001"
AxisArrays = "39de3d68-74b9-583c-8d2d-e117c070f3a9"
DataAPI = "9a962f9c-6df0-11e9-0e5d-c546b8b5ee8a"
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
IteratorInterfaceExtensions = "82899510-4779-5014-852e-03e436cf321d"
Expand All @@ -29,6 +30,7 @@ Tables = "bd369af6-aec1-5ad0-b16a-f7cc5008161c"
[compat]
AbstractMCMC = "0.4, 0.5, 1.0, 2.0, 3.0, 4, 5"
AxisArrays = "0.4.4"
DataAPI = "1.16.0"
Dates = "<0.0.1, 1"
Distributions = "0.21, 0.22, 0.23, 0.24, 0.25"
IteratorInterfaceExtensions = "0.1.1, 1"
Expand Down
1 change: 1 addition & 0 deletions src/MCMCChains.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ using Distributions
using RecipesBase
using Dates
using KernelDensity: kde, pdf
import DataAPI
import StatsBase: autocov, counts, sem, AbstractWeights,
autocor, describe, quantile, sample, summarystats, cov

Expand Down
10 changes: 2 additions & 8 deletions src/chains.jl
Original file line number Diff line number Diff line change
Expand Up @@ -347,13 +347,7 @@ end

function Base.show(io::IO, mime::MIME"text/plain", chains::Chains)
print(io, "Chains ", chains, ":\n\n", header(chains))

# Show summary stats.
summaries = describe(chains)
for summary in summaries
println(io)
show(io, mime, summary)
end
println(io, "\nUse `describe(chains)` for summary statistics and quantiles.")
end

Base.keys(c::Chains) = names(c)
Expand Down Expand Up @@ -889,4 +883,4 @@ function replacenames(chains::Chains, old_new::Pair...)
)

return Chains(value, chains.logevidence, namemap, chains.info)
end
end
24 changes: 15 additions & 9 deletions src/stats.jl
Original file line number Diff line number Diff line change
Expand Up @@ -171,28 +171,34 @@ function changerate(chains::AbstractArray{<:Real,3})
changerates, mvchangerate
end

describe(c::Chains; args...) = describe(stdout, c; args...)

"""
describe(io, chains[;
q = [0.025, 0.25, 0.5, 0.75, 0.975],
etype = :bm,
kwargs...])

Print the summary statistics and quantiles for the chain.
Print chain metadata, summary statistics, and quantiles. Use `describe(chains)` for REPL output to `stdout`, or specify `io` for other streams (e.g., file output).
"""
function describe(
function DataAPI.describe(
io::IO,
chains::Chains;
q = [0.025, 0.25, 0.5, 0.75, 0.975],
etype = :bm,
kwargs...
)
dfs = vcat(summarystats(chains; etype = etype, kwargs...),
quantile(chains; q = q, kwargs...))
return dfs
print(io, "Chains ", chains, ":\n\n", header(chains))

summstats = summarystats(chains; etype = etype, kwargs...)
println(io)
show(io, MIME("text/plain"), summstats)

qs = quantile(chains; q = q, kwargs...)
println(io)
show(io, MIME("text/plain"), qs)
end

# Convenience method for default IO
DataAPI.describe(chains::Chains; kwargs...) = DataAPI.describe(stdout, chains; kwargs...)

function _hpd(x::AbstractVector{<:Real}; alpha::Real=0.05)
n = length(x)
m = max(1, ceil(Int, alpha * n))
Expand Down Expand Up @@ -373,4 +379,4 @@ end

mean(chn::Chains, syms) = mean(chn[:, syms, :])
# resolve method ambiguity with `mean(f, ::AbstractArray)`
mean(chn::Chains, syms::AbstractVector) = mean(chn[:, syms, :])
mean(chn::Chains, syms::AbstractVector) = mean(chn[:, syms, :])
Loading