From 070d4d96b2eb09a2371f9508ad9bae446297700f Mon Sep 17 00:00:00 2001 From: John Waczak Date: Sun, 7 Jul 2024 09:00:10 -0500 Subject: [PATCH] handling zeros in kl-divergence from X --- src/nmf-base.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/nmf-base.jl b/src/nmf-base.jl index c08b3a0..17c1bda 100644 --- a/src/nmf-base.jl +++ b/src/nmf-base.jl @@ -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))