Skip to content

Commit

Permalink
handling zeros in kl-divergence from X
Browse files Browse the repository at this point in the history
  • Loading branch information
john-waczak committed Jul 7, 2024
1 parent f92d504 commit 070d4d9
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/nmf-base.jl
Original file line number Diff line number Diff line change
Expand Up @@ -190,10 +190,10 @@ function fit_kl!(nmf::NMFBase, X;

# 3. Check convergence
if i == 1
cost = kl_div(max.(nmf.W, eps(eltype(WH))), max.(nmf.H, eps(eltype(WH))), X)
cost = kl_div(max.(nmf.W, eps(eltype(WH))), max.(nmf.H, eps(eltype(WH))), max.(X, eps(eltype(X))))
else
cost_prev = cost
cost = kl_div(max.(nmf.W, eps(eltype(WH))), max.(nmf.H, eps(eltype(WH))), X)
cost = kl_div(max.(nmf.W, eps(eltype(WH))), max.(nmf.H, eps(eltype(WH))), max.(X, eps(eltype(X))))
# cost = kl_div(nmf.W, nmf.H, X)

diff= abs(cost - cost_prev)/min(abs(cost), abs(cost_prev))
Expand Down

0 comments on commit 070d4d9

Please sign in to comment.