in graspologic/cluster/divisive_cluster.py [0:0]
def _cluster_and_decide(self, X: np.ndarray) -> np.ndarray:
if self.is_root:
min_components = self.min_components
else:
min_components = 1
if self.cluster_method == "gmm":
cluster = AutoGMMCluster(
min_components=min_components,
max_components=self.max_components,
**self.cluster_kws
)
cluster.fit(X)
model = cluster.model_
criter = cluster.criter_
k = cluster.n_components_
pred = cluster.predict(X)
if self.delta_criter > 0:
single_cluster = AutoGMMCluster(
min_components=1, max_components=1, **self.cluster_kws
)
single_cluster.fit(X)
criter_single_cluster = single_cluster.criter_
if k > 1:
# check whether the difference between the criterion
# of "split" and "not split" is greater than
# the threshold, delta_criter
if criter_single_cluster - criter < self.delta_criter:
pred = np.zeros((len(X), 1), dtype=int)
elif self.cluster_method == "kmeans":
cluster = KMeansCluster(
max_clusters=self.max_components, **self.cluster_kws
)
cluster.fit(X)
model = cluster.model_
pred = cluster.predict(X)
self.model_ = model
return pred