Skip to content

Commit 4989950

Browse files
author
Alexey Stukalov
committed
em_step!(): enforce symmetry
1 parent a305f71 commit 4989950

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

src/observed/EM.jl

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,8 +248,13 @@ function em_step!(
248248
mul!(Σ, μ, μ', -1, 1)
249249
μ .+= μ₀
250250

251-
# try to fix non-positive-definite Σ
252-
isnothing(min_eigval) || copyto!(Σ, trunc_eigvals(Σ, min_eigval))
251+
StatsBase._symmetrize!(Σ) # correct numerical errors
252+
if !isnothing(min_eigval)
253+
# try to fix non-positive-definite Σ
254+
reg_Σ = trunc_eigvals(Σ, min_eigval)
255+
# if no truncation was done, reg_Σ will be the same object
256+
(reg_Σ === Σ) || copyto!(Σ, reg_Σ)
257+
end
253258

254259
return Σ, μ
255260
end

0 commit comments

Comments
 (0)