arviz-devs / InferenceObjects.jl

Storage for results of Bayesian inference
https://julia.arviz.org/InferenceObjects
MIT License
14 stars 1 forks source link

Change default dimension interpretation for numeric vectors #30

Closed sethaxen closed 1 year ago

sethaxen commented 1 year ago

Currently, an AbstractVector{<:Real} of length n is assumed to represent a single draw with n chains:

julia> using InferenceObjects, DimensionalData

julia> x = randn(1_000);

julia> convert_to_dataset(x).x |> dims
Dim{:draw} Sampled{Int64} Base.OneTo(1) ForwardOrdered Regular Points,
Dim{:chain} Sampled{Int64} Base.OneTo(1000) ForwardOrdered Regular Points

There are several reasons why we should change this behavior. First, the vector and its transpose are then interpreted identically:

julia> convert_to_dataset(x').x |> dims
Dim{:draw} Sampled{Int64} Base.OneTo(1) ForwardOrdered Regular Points,
Dim{:chain} Sampled{Int64} Base.OneTo(1000) ForwardOrdered Regular Points

Second, simply reshaping the vector into a matrix with the same leading dimension is interpreted completely differently:

julia> convert_to_dataset(reshape(x, :, 1)).x |> dims
Dim{:draw} Sampled{Int64} Base.OneTo(1000) ForwardOrdered Regular Points,
Dim{:chain} Sampled{Int64} Base.OneTo(1) ForwardOrdered Regular Points

Third, this is a more natural interpretation and lets us more gracefully support cases where we are converting exact MC draws with no chains.

The current behavior is a holdover from when we used the reversed ordering of dimensions, when a vector would correctly have been interpreted as a vector of draws. So I would classify this as a bug.