From 807ca422194eded7afaa6ca4381cd4882800627b Mon Sep 17 00:00:00 2001
From: Yannick DAYER <yannick.dayer@idiap.ch>
Date: Tue, 7 Dec 2021 17:38:11 +0100
Subject: [PATCH] Remove divide by zero for later ignored value.

Prevents an "invalid value" warning.
---
 bob/learn/em/mixture/gmm.py | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/bob/learn/em/mixture/gmm.py b/bob/learn/em/mixture/gmm.py
index 65c8137..0be5a17 100644
--- a/bob/learn/em/mixture/gmm.py
+++ b/bob/learn/em/mixture/gmm.py
@@ -862,10 +862,20 @@ def map_gmm_m_step(
     #   Equation 12 of Reynolds et al., "Speaker Verification Using Adapted
     #   Gaussian Mixture Models", Digital Signal Processing, 2000
     if update_means:
+        # Apply threshold to prevent divide by zero below
+        n_threshold = np.where(
+            statistics.n < mean_var_update_threshold,
+            mean_var_update_threshold,
+            statistics.n,
+        )
+        # n_threshold = np.full(statistics.n.shape, fill_value=mean_var_update_threshold)
+        # n_threshold[statistics.n > mean_var_update_threshold] = statistics.n[
+        #     statistics.n > mean_var_update_threshold
+        # ]
         new_means = (
             np.multiply(
                 alpha[:, None],
-                (statistics.sum_px / statistics.n[:, None]),
+                (statistics.sum_px / n_threshold[:, None]),
             )
             + np.multiply((1 - alpha[:, None]), machine.ubm.means)
         )
-- 
GitLab