Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

xmeans does not agree to paper? #692

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions pyclustering/cluster/xmeans.py
Original file line number Diff line number Diff line change
Expand Up @@ -602,37 +602,37 @@ def __bayesian_information_criterion(self, clusters, centers):
dimension = len(self.__pointer_data[0])

# estimation of the noise variance in the data set
sigma_sqrt = 0.0
sigma_sq = 0.0
K = len(clusters)
N = 0.0

for index_cluster in range(0, len(clusters), 1):
for index_object in clusters[index_cluster]:
sigma_sqrt += self.__metric(self.__pointer_data[index_object], centers[index_cluster])
sigma_sq += self.__metric(self.__pointer_data[index_object], centers[index_cluster])

N += len(clusters[index_cluster])

if N - K > 0:
sigma_sqrt /= (N - K)
sigma_sq /= (N - K)
p = (K - 1) + dimension * K + 1

# in case of the same points, sigma_sqrt can be zero (issue: #407)
sigma_multiplier = 0.0
if sigma_sqrt <= 0.0:
if sigma_sq <= 0.0:
sigma_multiplier = float('-inf')
else:
sigma_multiplier = dimension * 0.5 * log(sigma_sqrt)
sigma_multiplier = dimension * 0.5 * log(sigma_sq)

# splitting criterion
for index_cluster in range(0, len(clusters), 1):
n = len(clusters[index_cluster])

L = n * log(n) - n * log(N) - n * 0.5 * log(2.0 * numpy.pi) - n * sigma_multiplier - (n - K) * 0.5

# BIC calculation
scores[index_cluster] = L - p * 0.5 * log(N)
scores[index_cluster] = L

return sum(scores)
# BIC calculation
return sum(scores) - p * 0.5 * log(N)


def __verify_arguments(self):
Expand Down