MCMCChains.jl
MCMCChains.jl copied to clipboard
Simple chains throw errors when displayed
I'm not sure if this has been noted before, but creating a very simple chain or attempting to slice a chain in interactive mode (REPL, notebook) etc. fails:
using MCMCChains
Chains(zeros(1, 3, 1), [:a, :b, :c])
results in:
Chains MCMC chain (1×3×1 Array{Float64, 3}):
Iterations = 1:1:1
Number of chains = 1
Samples per chain = 1
parameters = a, b, c
┌ Warning: MCSE calculation failed: ArgumentError("number of draws after splitting must >4 but is 0.")
└ @ MCMCChains ~/.julia/packages/MCMCChains/AQENn/src/stats.jl:310
┌ Warning: Tail ESS calculation failed: ArgumentError("number of draws after splitting must >4 but is 0.")
└ @ MCMCChains ~/.julia/packages/MCMCChains/AQENn/src/stats.jl:319
┌ Warning: Bulk ESS/R-hat calculation failed: ArgumentError("number of draws after splitting must >4 but is 0.")
└ @ MCMCChains ~/.julia/packages/MCMCChains/AQENn/src/stats.jl:333
Error showing value of type Chains{Float64, AxisArrays.AxisArray{Float64, 3, Array{Float64, 3}, Tuple{AxisArrays.Axis{:iter, StepRange{Int64, Int64}}, AxisArrays.Axis{:var, Vector{Symbol}}, AxisArrays.Axis{:chain, UnitRange{Int64}}}}, Missing, @NamedTuple{parameters::Vector{Symbol}}, @NamedTuple{}}:
ERROR: ArgumentError: collection must be non-empty
Stacktrace:
[1] first(itr::@NamedTuple{})
@ Base ./abstractarray.jl:470
[2] ChainDataFrame(name::String, nt::@NamedTuple{})
@ MCMCChains ~/.julia/packages/MCMCChains/AQENn/src/summarize.jl:8
[3] summarystats(chains::Chains{…}; sections::Symbol, append_chains::Bool, autocov_method::AutocovMethod, maxlag::Int64, name::String, kwargs::@Kwargs{…})
@ MCMCChains ~/.julia/packages/MCMCChains/AQENn/src/stats.jl:338
[4] summarystats
@ ~/.julia/packages/MCMCChains/AQENn/src/stats.jl:286 [inlined]
[5] describe(io::Base.TTY, chains::Chains{…}; q::Vector{…}, etype::Symbol, kwargs::@Kwargs{})
@ MCMCChains ~/.julia/packages/MCMCChains/AQENn/src/stats.jl:191
[6] describe(io::Base.TTY, chains::Chains{Float64, AxisArrays.AxisArray{…}, Missing, @NamedTuple{…}, @NamedTuple{}})
@ MCMCChains ~/.julia/packages/MCMCChains/AQENn/src/stats.jl:184
[7] describe(c::Chains{Float64, AxisArrays.AxisArray{…}, Missing, @NamedTuple{…}, @NamedTuple{}}; args::@Kwargs{})
@ MCMCChains ~/.julia/packages/MCMCChains/AQENn/src/stats.jl:174
[8] describe
@ ~/.julia/packages/MCMCChains/AQENn/src/stats.jl:174 [inlined]
[9] show(io::IOContext{…}, mime::MIME{…}, chains::Chains{…})
@ MCMCChains ~/.julia/packages/MCMCChains/AQENn/src/chains.jl:352
[10] (::REPL.var"#55#56"{REPL.REPLDisplay{REPL.LineEditREPL}, MIME{Symbol("text/plain")}, Base.RefValue{Any}})(io::Any)
@ REPL ~/.julia/juliaup/julia-1.10.0+0.x64.linux.gnu/share/julia/stdlib/v1.10/REPL/src/REPL.jl:273
[11] with_repl_linfo(f::Any, repl::REPL.LineEditREPL)
@ REPL ~/.julia/juliaup/julia-1.10.0+0.x64.linux.gnu/share/julia/stdlib/v1.10/REPL/src/REPL.jl:569
[12] display(d::REPL.REPLDisplay, mime::MIME{Symbol("text/plain")}, x::Any)
@ REPL ~/.julia/juliaup/julia-1.10.0+0.x64.linux.gnu/share/julia/stdlib/v1.10/REPL/src/REPL.jl:259
[13] display
@ REPL ~/.julia/juliaup/julia-1.10.0+0.x64.linux.gnu/share/julia/stdlib/v1.10/REPL/src/REPL.jl:278 [inlined]
[14] display(x::Any)
@ Base.Multimedia ./multimedia.jl:340
[15] #invokelatest#2
@ Base ./essentials.jl:887 [inlined]
[16] invokelatest
@ Base ./essentials.jl:884 [inlined]
[17] print_response(errio::IO, response::Any, show_value::Bool, have_color::Bool, specialdisplay::Union{…})
@ REPL ~/.julia/juliaup/julia-1.10.0+0.x64.linux.gnu/share/julia/stdlib/v1.10/REPL/src/REPL.jl:315
[18] (::REPL.var"#57#58"{REPL.LineEditREPL, Pair{Any, Bool}, Bool, Bool})(io::Any)
@ REPL ~/.julia/juliaup/julia-1.10.0+0.x64.linux.gnu/share/julia/stdlib/v1.10/REPL/src/REPL.jl:284
[19] with_repl_linfo(f::Any, repl::REPL.LineEditREPL)
@ REPL ~/.julia/juliaup/julia-1.10.0+0.x64.linux.gnu/share/julia/stdlib/v1.10/REPL/src/REPL.jl:569
[20] print_response(repl::REPL.AbstractREPL, response::Any, show_value::Bool, have_color::Bool)
@ REPL ~/.julia/juliaup/julia-1.10.0+0.x64.linux.gnu/share/julia/stdlib/v1.10/REPL/src/REPL.jl:282
[21] (::REPL.var"#do_respond#80"{…})(s::REPL.LineEdit.MIState, buf::Any, ok::Bool)
@ REPL ~/.julia/juliaup/julia-1.10.0+0.x64.linux.gnu/share/julia/stdlib/v1.10/REPL/src/REPL.jl:911
[22] #invokelatest#2
@ Base ./essentials.jl:887 [inlined]
[23] invokelatest
@ Base ./essentials.jl:884 [inlined]
[24] run_interface(terminal::REPL.Terminals.TextTerminal, m::REPL.LineEdit.ModalInterface, s::REPL.LineEdit.MIState)
@ REPL.LineEdit ~/.julia/juliaup/julia-1.10.0+0.x64.linux.gnu/share/julia/stdlib/v1.10/REPL/src/LineEdit.jl:2656
[25] run_frontend(repl::REPL.LineEditREPL, backend::REPL.REPLBackendRef)
@ REPL ~/.julia/juliaup/julia-1.10.0+0.x64.linux.gnu/share/julia/stdlib/v1.10/REPL/src/REPL.jl:1312
[26] (::REPL.var"#62#68"{REPL.LineEditREPL, REPL.REPLBackendRef})()
@ REPL ~/.julia/juliaup/julia-1.10.0+0.x64.linux.gnu/share/julia/stdlib/v1.10/REPL/src/REPL.jl:386
Some type information was truncated. Use `show(err)` to see complete types.
This seems to be caused by the display
routine since the following works:
using MCMCChains
Chains(zeros(1, 3, 1), [:a, :b, :c]).value.data
The issue here seems to be that if ess
, rhat
, and mcse
all fail, then nt_additional
is empty, and this line tries to create an empty ChainDataFrame
, which is not allowed.
https://github.com/TuringLang/MCMCChains.jl/blob/4d2a2f4a4c89d1317e66637e8edcd35472f336c6/src/stats.jl#L338
A simple fix would be to allow an empty ChainDataFrame
. However, that will be replaced by #431.
There are a few other (slightly different and already fixed) issues regarding problems with describe
(and hence display
) if chains are too short. But I haven't been aware of this particular problem.
MCMCDiagnosticTools v0.3.10 contains a fix for this: https://github.com/TuringLang/MCMCDiagnosticTools.jl/pull/119
It seems fixed on the most recent release.