Skip to content
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

Indexing a multible parameters fails #411

Open
scheidan opened this issue Mar 23, 2023 · 1 comment
Open

Indexing a multible parameters fails #411

scheidan opened this issue Mar 23, 2023 · 1 comment

Comments

@scheidan
Copy link

scheidan commented Mar 23, 2023

Indexing to get a more than one parameter fails (MCMCChains v6.0.0) with a not very helpful error message:

chn = Chains(rand(100, 3, 2))

# all this leads to:
# ERROR: ArgumentError: number of draws after splitting must >4 but is 2.
chn[1:5, :, :]
chn[1:5, 1:3, :]
chn[1:5, 1:2, :]
chn[1:5, :, 1]
chn[1:5, :, 1:2]

This is rather surprising as chn[1:5, 1, :] works as nicely.

Of course, we can do instead

chn[1:5] # leads to the same error

which works as expected (but I think is not documented).

@devmotion
Copy link
Member

Splitting works fine, only ess with the default splitting strategy can't be computed for the resulting chain and hence the display call in the REPL errors which includes a call to ess:

julia> using MCMCChains

julia> chn = Chains(rand(100, 3, 2));

julia> c1 = chn[1:5, :, :];

julia> c1
Chains MCMC chain (5×3×2 Array{Float64, 3}):

Iterations        = 1:1:5
Number of chains  = 2
Samples per chain = 5
parameters        = param_1, param_2, param_3
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,), Tuple{Vector{Symbol}}}, NamedTuple{(), Tuple{}}}:
ERROR: ArgumentError: number of draws after splitting must >4 but is 2.
...

julia> ess(c1)
ERROR: ArgumentError: number of draws after splitting must >4 but is 2.
...

julia> ess(c1; split_chains=1)
ESS
  parameters       ess   ess_per_sec 
      Symbol   Float64       Missing 

     param_1    4.3214       missing
     param_2   10.0000       missing
     param_3   10.0000       missing

Of course, we can do instead

chn[1:5]

which works as expected (but I think is not documented).

I'm not sure exactly what you mean, for me this leads (as expected) to the same error? Maybe you added a semicolon in the latter case such that printing was skipped?

julia> chn[1:5]
Chains MCMC chain (5×3×2 Array{Float64, 3}):

Iterations        = 1:1:5
Number of chains  = 2
Samples per chain = 5
parameters        = param_1, param_2, param_3
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,), Tuple{Vector{Symbol}}}, NamedTuple{(), Tuple{}}}:
ERROR: ArgumentError: number of draws after splitting must >4 but is 2.
...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants