Skip to content

Commit 2a29ffc

Browse files
committed
Move the constraint operation before refinement to reduce the computational cost of auto-tune.
1 parent ac6d7a6 commit 2a29ffc

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

spectralcluster/spectral_clusterer.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,6 @@ def _compute_eigenvectors_ncluster(self, affinity, constraint_matrix=None):
8989
n_clusters: number of clusters as an integer
9090
max_delta_norm: normalized maximum eigen gap
9191
"""
92-
if (self.constraint_options and
93-
self.constraint_options.apply_before_refinement):
94-
# Perform the constraint operation before refinement
95-
affinity = self.constraint_options.constraint_operator.adjust_affinity(
96-
affinity, constraint_matrix)
97-
9892
# Perform refinement operations on the affinity matrix.
9993
for refinement_name in self.refinement_options.refinement_sequence:
10094
refinement_operator = self.refinement_options.get_refinement_operator(
@@ -156,6 +150,12 @@ def predict(self, embeddings, constraint_matrix=None):
156150
# Compute affinity matrix.
157151
affinity = self.affinity_function(embeddings)
158152

153+
if (self.constraint_options and
154+
self.constraint_options.apply_before_refinement):
155+
# Perform the constraint operation before refinement
156+
affinity = self.constraint_options.constraint_operator.adjust_affinity(
157+
affinity, constraint_matrix)
158+
159159
if self.autotune:
160160
# Use Auto-tuning method to find a good p_percentile.
161161
if (RefinementName.RowWiseThreshold

0 commit comments

Comments
 (0)