From 4ae0fe2c6dc10709f55809dc8fdff4cc9076773a Mon Sep 17 00:00:00 2001
From: Amir MOHAMMADI <amir.mohammadi@idiap.ch>
Date: Mon, 11 Apr 2022 17:04:26 +0200
Subject: [PATCH] [gmm] in-place summation

---
 bob/learn/em/gmm.py | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/bob/learn/em/gmm.py b/bob/learn/em/gmm.py
index ae7bc39..831d3fc 100644
--- a/bob/learn/em/gmm.py
+++ b/bob/learn/em/gmm.py
@@ -135,16 +135,14 @@ def e_step(data, machine):
     # Count of samples [int]
     statistics.t += data.shape[0]
     # Responsibilities [array of shape (n_gaussians,)]
-    statistics.n = statistics.n + responsibility.sum(axis=-1)
+    statistics.n += responsibility.sum(axis=-1)
     for i in range(n_gaussians):
         # p * x [array of shape (n_gaussians, n_samples, n_features)]
         px = responsibility[i, :, None] * data
         # First order stats [array of shape (n_gaussians, n_features)]
-        statistics.sum_px[i] = statistics.sum_px[i] + np.sum(px, axis=0)
+        statistics.sum_px[i] += np.sum(px, axis=0)
         # Second order stats [array of shape (n_gaussians, n_features)]
-        statistics.sum_pxx[i] = statistics.sum_pxx[i] + np.sum(
-            px * data, axis=0
-        )
+        statistics.sum_pxx[i] += np.sum(px * data, axis=0)
 
     return statistics
 
-- 
GitLab