From 198dc4722e9ceb3cf49daa198e25fe501317d480 Mon Sep 17 00:00:00 2001
From: lucas_miranda <lucasmiranda42@gmail.com>
Date: Sat, 13 Mar 2021 15:55:46 +0100
Subject: [PATCH] Modified cluster purity computation. Instead of KNN, we now
 look at neighborhoods of a predefined radius

---
 deepof/model_utils.py | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/deepof/model_utils.py b/deepof/model_utils.py
index b0a019cd..32c6352c 100644
--- a/deepof/model_utils.py
+++ b/deepof/model_utils.py
@@ -266,11 +266,11 @@ class neighbor_cluster_purity(tf.keras.callbacks.Callback):
             for i, sample in enumerate(random_idxs):
 
                 neighborhood = pdist[sample] < self.r
+                z = groups[neighborhood]
+                neigh_entropy = K.sum(tf.multiply(z + 1e-5, tf.math.log(z) + 1e-5), axis=self.axis)
 
                 purity_vector[i] = (
-                    np.sum(hard_groups[neighborhood] == hard_groups[sample])
-                    / np.sum(neighborhood)
-                    * np.max(groups[sample])
+                    neigh_entropy / np.sum(neighborhood)
                 )
 
             writer = tf.summary.create_file_writer(self.log_dir)
-- 
GitLab