Skip to content

Commit 3f64a30

Browse files
committed
fixed DB index
1 parent 9a356a5 commit 3f64a30

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

pycvi/cvi_func.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -974,7 +974,7 @@ def davies_bouldin(
974974
:type clusters: List[List[int]]
975975
:param dist_kwargs: kwargs for the distance function, defaults to {}
976976
:type dist_kwargs: dict, optional
977-
:return: TheDavies-Bouldin (DB) index
977+
:return: The Davies-Bouldin (DB) index
978978
:rtype: float
979979
"""
980980
k = len(clusters)
@@ -1001,15 +1001,28 @@ def davies_bouldin(
10011001
X, clusters, all=True, dist_kwargs=dist_kwargs
10021002
)
10031003

1004-
DB_aux = [
1005-
np.amax([
1004+
# Compute R_ijs even when i=j
1005+
R_ijs = [
1006+
[
10061007
(S_is[i] + S_is[j]) / dist_between_centroids[i][j]
10071008
if dist_between_centroids[i][j] != 0 else np.inf
10081009
for j in range(k)
1009-
]) for i in range(k)
1010+
] for i in range(k)
1011+
]
1012+
1013+
# Remove the case i == j as described in the paper
1014+
R_ijs = [
1015+
[
1016+
R_ijs[i][j] for j in range(k) if i != j
1017+
] for i in range(k)
1018+
]
1019+
1020+
# Compute R_is = max_j of R_ijs when i != j
1021+
R_is = [
1022+
np.amax(R_ijs) for i in range(k)
10101023
]
10111024

1012-
DB = (1/k) * np.sum(DB_aux)
1025+
DB = (1/k) * np.sum(R_is)
10131026
DB = float(DB)
10141027

10151028
return DB

0 commit comments

Comments
 (0)