Skip to content
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion sknetwork/clustering/leiden.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ def _optimize_refine(self, labels, adjacency, out_weights, in_weights):
labels_refined = np.arange(len(labels)).astype(np.int32)
return optimize_refine_core(labels, labels_refined, indices, indptr, data, out_weights, in_weights,
out_cluster_weights, in_cluster_weights, cluster_weights, self_loops,
self.resolution)
self.resolution, self.tol_optimization)

@staticmethod
def _aggregate_refine(labels, labels_refined, adjacency, out_weights, in_weights):
Expand Down
7 changes: 5 additions & 2 deletions sknetwork/clustering/leiden_core.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ ctypedef fused int_or_long:
@cython.wraparound(False)
def optimize_refine_core(int_or_long[:] labels, int_or_long[:] labels_refined, int_or_long[:] indices,
int_or_long[:] indptr, float[:] data, float[:] out_weights, float[:] in_weights, float[:] out_cluster_weights,
float[:] in_cluster_weights, float[:] cluster_weights, float[:] self_loops, float resolution): # pragma: no cover
float[:] in_cluster_weights, float[:] cluster_weights, float[:] self_loops, float resolution,
float tol_optimization): # pragma: no cover
"""Refine clusters while maximizing modularity.

Parameters
Expand Down Expand Up @@ -42,6 +43,8 @@ def optimize_refine_core(int_or_long[:] labels, int_or_long[:] labels_refined, i
Weights of self loops.
resolution :
Resolution parameter (positive).
tol_optimization :
Minimum increase in modularity to enter a new optimization pass.

Returns
-------
Expand Down Expand Up @@ -102,7 +105,7 @@ def optimize_refine_core(int_or_long[:] labels, int_or_long[:] labels_refined, i
delta_local -= resolution * out_weight * in_cluster_weights[label_target]
delta_local -= resolution * in_weight * out_cluster_weights[label_target]
delta_local -= delta
if delta_local > 0:
if delta_local > tol_optimization:
label_target_set.insert(label_target)
cluster_weights[label_target] = 0

Expand Down