Skip to content

Commit

Permalink
Update fkmns.py
Browse files Browse the repository at this point in the history
  • Loading branch information
chenxinye committed Dec 28, 2023
1 parent 6205e44 commit 735af05
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions fABBA/jabba/fkmns.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ def uniform_sample(X, size=100, random_state=42):




def calculate_cluster_centers(data, labels):
"""Calculate the mean centers of clusters from given data."""
classes = np.unique(labels)
Expand All @@ -155,17 +154,18 @@ def calculate_cluster_centers(data, labels):
class sampledKMeansInter(KMeans):
def __init__(self,
n_clusters=1,
r=0.5,
r=0.1,
init='k-means++',
max_iter=300,
random_state=4022,
tol=1e-4, n_init=1):
random_state=42,
tol=1e-4):

super().__init__(n_clusters=n_clusters,
init=init,
max_iter=max_iter,
random_state=random_state,
tol=tol, n_init=n_init)
n_init=1, # consistent to the default setting of sklearn k-means
tol=tol)
self.r = r
self.size = None

Expand All @@ -177,10 +177,10 @@ def sampled_fit(self, X):
if self.n_clusters >= self.size:
self.size = self.n_clusters

core_pts = uniform_sample(X, self.size, self.random_state)
self.core_pts = uniform_sample(X, self.size, self.random_state)
labels_ = np.zeros(X.shape[0], dtype=int)
index = np.zeros(X.shape[0], dtype=bool)
index[core_pts] = True
index[self.core_pts] = True
labels_[index] = self.fit_predict(X[index])
inverse_labels = ~index
if np.any(inverse_labels):
Expand Down

0 comments on commit 735af05

Please sign in to comment.