Distributions.jl
Distributions.jl copied to clipboard
Sampling from von Mises Fisher yields NaN
This happens when the mean direction unit vector μ is along the x-axis. For instance:
julia> vMF = VonMisesFisher([1, 0], 1.0)
VonMisesFisher{Float64}(μ=[1.0, 0.0], κ=1.0)
julia> rand(vMF)
2-element Vector{Float64}:
NaN
NaN
This problem seems to persist in higher dimensions.
I'm not familiar with the implementation of the VonMisesFisher sampler but I suspect that the NaNs arise in https://github.com/JuliaStats/Distributions.jl/blob/8887d7a16a2801dc869ab42ba03cad03efc5ed9d/src/samplers/vonmisesfisher.jl#L103: for μ=[1.0, 0.0] we have v[1] = s = 0 in this line, and hence v[1] /= s should result in v[1] = NaN.