From 001306a10944a44c8ca445965f5feb6a9fc17cb9 Mon Sep 17 00:00:00 2001 From: seoanezonjic Date: Tue, 3 Sep 2024 13:23:30 +0200 Subject: [PATCH] Minor fix when a cluster has only two nodes --- cdlib/algorithms/internal/HLC.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/cdlib/algorithms/internal/HLC.py b/cdlib/algorithms/internal/HLC.py index 5851b19..b4dfdb9 100644 --- a/cdlib/algorithms/internal/HLC.py +++ b/cdlib/algorithms/internal/HLC.py @@ -493,9 +493,13 @@ def get_nodesNedges_per_cluster(self, members, edge_list): def get_cluster_partial_partition_density(self, edges, nodes): n = len(nodes) # node number - m = len(edges) # link number - # return (m-(n-1))/(n*(n-1)/(2-(n-1))) #Ahn - return (m * (m - n + 1)) / ((n - 2) * (n - 1)) # kalinka + if n == 2: + partial_partition_density = 0 + else: + m = len(edges) # link number + # partial_partition_density = (m-(n-1))/(n*(n-1)/(2-(n-1))) #Ahn + partial_partition_density = (m * (m - n + 1)) / ((n - 2) * (n - 1)) # kalinka + return partial_partition_density def get_pden(self, last_cluster_pool, partial_partition_densities, constant): partition_den_sum = sum(