Skip to content

Commit

Permalink
Fix Louvain embedding
Browse files Browse the repository at this point in the history
  • Loading branch information
tbonald committed Mar 27, 2024
1 parent 7821e10 commit 6c1b1f9
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions sknetwork/embedding/louvain_hierarchy.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ def __init__(self, n_components: int = 2, scale: float = .1, resolution: float =
random_state: Optional[Union[np.random.RandomState, int]] = None, verbose: bool = False):
super(LouvainNE, self).__init__()

self.embedding_ = None
self.n_components = n_components
self.scale = scale
self._clustering_method = Louvain(resolution=resolution, tol_optimization=tol_optimization,
Expand All @@ -93,11 +94,10 @@ def _recursive_louvain(self, adjacency: Union[sparse.csr_matrix, np.ndarray], de
if nodes is None:
nodes = np.arange(n)

if adjacency.nnz:
if depth and adjacency.nnz:
labels = self._clustering_method.fit_transform(adjacency)
else:
labels = np.zeros(n)

labels = np.zeros(n, dtype=int)
clusters = np.unique(labels)

if len(clusters) != 1:
Expand Down Expand Up @@ -135,7 +135,7 @@ def fit(self, input_matrix: Union[sparse.csr_matrix, np.ndarray], force_bipartit

# embedding
self.embedding_ = np.zeros((n, self.n_components))
self._recursive_louvain(adjacency, 0)
self._recursive_louvain(adjacency, self.n_components)

if self.bipartite:
self._split_vars(input_matrix.shape)
Expand Down

0 comments on commit 6c1b1f9

Please sign in to comment.