Skip to content

Distributions and Sampleables with keys for the variates

License

Notifications You must be signed in to change notification settings

invenia/KeyedDistributions.jl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

KeyedDistributions

Stable Dev Build Status Coverage Code Style: Blue ColPrac: Contributor's Guide on Collaborative Practices for Community Packages

KeyedDistributions.jl provides thin wrappers of Distribution and Sampleable, to store keys and dimnames for the variates.

julia> using KeyedDistributions, Distributions, NamedDims;

julia> kd = KeyedDistribution(MvNormal(3, 1.0); id=[:x, :y, :z]);

julia> axiskeys(kd)
([:x, :y, :z],)

julia> dimnames(kd)
(:id,)

julia> distribution(kd)
ZeroMeanIsoNormal(
dim: 3
μ: 3-element Zeros{Float64}
Σ: [1.0 0.0 0.0; 0.0 1.0 0.0; 0.0 0.0 1.0]
)

Methods for Distribution and Sampleable return KeyedArrays in place of regular Arrays, where applicable.

julia> mean(kd)
1-dimensional KeyedArray(NamedDimsArray(...)) with keys:
   id  3-element Vector{Symbol}
And data, 3-element Zeros{Float64}:
 (:x)  0.0
 (:y)  0.0
 (:z)  0.0
 
julia> rand(kd, 2)
2-dimensional KeyedArray(...) with keys:
   id  3-element Vector{Symbol}
   sample  2-element OneTo{Int}
And data, 3×2 Matrix{Float64}:
        (1)           (2)
  (:x)   -1.11227      -0.279841
  (:y)    0.00784496    0.871718
  (:z)   -0.930186     -0.8922

In this way, KeyedDistributions.jl extends the AxisKeys and NamedDims ecosystems to Distributions.jl.