Skip to content

Commit

Permalink
Merge pull request #232 from Praveer1981/wip/praveer/masterLouvainChange
Browse files Browse the repository at this point in the history
pass partition as 2nd input parameter to the Louvain
  • Loading branch information
GiulioRossetti authored May 13, 2024
2 parents ab461b7 + d110f38 commit d46a542
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions cdlib/algorithms/crisp_partition.py
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,7 @@ def agdl(g_original: object, number_communities: int, kc: int) -> NodeClustering

def louvain(
g_original: object,
partition: None,
weight: str = "weight",
resolution: float = 1.0,
randomize: int = None,
Expand All @@ -512,10 +513,12 @@ def louvain(
========== ======== ========
Undirected Directed Weighted
========== ======== ========
Yes No No
Yes No Yes
========== ======== ========
:param g_original: a networkx/igraph object
:param partition : dict, optional the algorithm will start using this partition of the nodes.
It's a dictionary where keys are their nodes and values the communities
:param weight: str, optional the key in graph to use as weight. Default to 'weight'
:param resolution: double, optional Will change the size of the communities, default to 1.
:param randomize: int, RandomState instance or None, optional (default=None). If int, random_state is the seed used by the random number generator; If RandomState instance, random_state is the random number generator; If None, the random number generator is the RandomState instance used by `np.random`.
Expand All @@ -539,7 +542,7 @@ def louvain(
g = convert_graph_formats(g_original, nx.Graph)

coms = community_louvain.best_partition(
g, weight=weight, resolution=resolution, randomize=randomize
g, partition=partition, weight=weight, resolution=resolution, randomize=randomize
)

# Reshaping the results
Expand Down Expand Up @@ -576,7 +579,7 @@ def leiden(
========== ======== ========
Undirected Directed Weighted
========== ======== ========
Yes No No
Yes No Yes
========== ======== ========
:param g_original: a networkx/igraph object
Expand Down

0 comments on commit d46a542

Please sign in to comment.