Skip to content

Commit 2efd649

Browse files
Add epsilon to VonMisesFisher Householder summation
1 parent 1e6801d commit 2efd649

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/samplers/vonmisesfisher.jl

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,18 +84,20 @@ end
8484
_vmf_genw(rng::AbstractRNG, s::VonMisesFisherSampler) =
8585
_vmf_genw(rng, s.p, s.b, s.x0, s.c, s.κ)
8686

87-
function _vmf_householder_vec::Vector{Float64})
87+
function _vmf_householder_vec::Vector{Float64}, ε::Float64=1e-8)
8888
# assuming μ is a unit-vector (which it should be)
8989
# can compute v in a single pass over μ
90+
# Add small value, ε, to denominator to avoid dividing by zero
9091

9192
p = length(μ)
9293
v = similar(μ)
9394
v[1] = μ[1] - 1.0
9495
s = sqrt(-2*v[1])
95-
v[1] /= s
96+
v[1] /= (s + ε)
9697

9798
@inbounds for i in 2:p
98-
v[i] = μ[i] / s
99+
100+
v[i] = μ[i] / (s + ε)
99101
end
100102

101103
return v

0 commit comments

Comments
 (0)