Distributions.jl icon indicating copy to clipboard operation
Distributions.jl copied to clipboard

MvNormal undocumented constructor

Open Nimrais opened this issue 2 years ago • 2 comments

I found that there is an undocumented working constructor, MvNormal(x::Vector), that works strangely: it converts vector values to their absolute values and puts it on the diagonal and sets the mean vector to zero vector.

julia> MvNormal(zeros(2))
ZeroMeanDiagNormal(
dim: 2
μ: Zeros(2)
Σ: [0.0 0.0; 0.0 0.0]
)

julia> MvNormal([-1,0])
MvNormal{Int64, PDMats.PDiagMat{Int64, Vector{Int64}}, FillArrays.Zeros{Int64, 1, Tuple{Base.OneTo{Int64}}}}(
dim: 2
μ: Zeros(2)
Σ: [1 0; 0 0]
)

Moreover, it is possible to sample from these distributions:

julia> rand(MvNormal([0, 0]), 10)
2×10 Matrix{Float64}:
 0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0
 0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0
 
 julia> rand(MvNormal([1, 0]), 10)
2×10 Matrix{Float64}:
 1.03324  -2.2997  0.140153  -0.878153  -0.461629  -0.425138  -1.10402  1.03676  -0.745389  1.05095
 0.0       0.0     0.0        0.0        0.0        0.0        0.0      0.0       0.0       0.0

Even more it a bit unintuitive that rand(MvNormal([1, 1]), 10_000), dims = 2) will give samples from zero centered distribution and not ones centered.

Nimrais avatar Oct 07 '22 10:10 Nimrais

It's not documented because it's deprecated and will be removed: https://github.com/JuliaStats/Distributions.jl/blob/7831193ecbb70967b9f1af71e1c8f0850b89f3a5/src/multivariate/mvnormal.jl#L223

sethaxen avatar Oct 07 '22 12:10 sethaxen

I see now! But not all use Julia with the deprecation flag: if it were possible to make it more visible, it would be nice. Thanks for the clarification.

Nimrais avatar Oct 11 '22 08:10 Nimrais