@@ -24,7 +24,9 @@ def _community_fastgreedy(graph, weights=None):
2424 """
2525 merges , qs = GraphBase .community_fastgreedy (graph , weights )
2626 optimal_count = _optimal_cluster_count_from_merges_and_modularity (graph , merges , qs )
27- return VertexDendrogram (graph , merges , optimal_count , modularity_params = {"weights" : weights })
27+ return VertexDendrogram (
28+ graph , merges , optimal_count , modularity_params = {"weights" : weights }
29+ )
2830
2931
3032def _community_infomap (graph , edge_weights = None , vertex_weights = None , trials = 10 ):
@@ -51,7 +53,9 @@ def _community_infomap(graph, edge_weights=None, vertex_weights=None, trials=10)
5153 called C{codelength} that stores the code length determined by the
5254 algorithm.
5355 """
54- membership , codelength = GraphBase .community_infomap (graph , edge_weights , vertex_weights , trials )
56+ membership , codelength = GraphBase .community_infomap (
57+ graph , edge_weights , vertex_weights , trials
58+ )
5559 return VertexClustering (
5660 graph ,
5761 membership ,
@@ -60,7 +64,9 @@ def _community_infomap(graph, edge_weights=None, vertex_weights=None, trials=10)
6064 )
6165
6266
63- def _community_leading_eigenvector (graph , clusters = None , weights = None , arpack_options = None ):
67+ def _community_leading_eigenvector (
68+ graph , clusters = None , weights = None , arpack_options = None
69+ ):
6470 """Newman's leading eigenvector method for detecting community structure.
6571
6672 This is the proper implementation of the recursive, divisive algorithm:
@@ -179,13 +185,21 @@ def _community_multilevel(graph, weights=None, return_levels=False, resolution=1
179185
180186 modularity_params = {"weights" : weights , "resolution" : resolution }
181187 if return_levels :
182- levels , qs = GraphBase .community_multilevel (graph , weights , return_levels = True , resolution = resolution )
188+ levels , qs = GraphBase .community_multilevel (
189+ graph , weights , return_levels = True , resolution = resolution
190+ )
183191 result = []
184192 for level , q in zip (levels , qs ):
185- result .append (VertexClustering (graph , level , q , modularity_params = modularity_params ))
193+ result .append (
194+ VertexClustering (graph , level , q , modularity_params = modularity_params )
195+ )
186196 else :
187- membership = GraphBase .community_multilevel (graph , weights , return_levels = False , resolution = resolution )
188- result = VertexClustering (graph , membership , modularity_params = modularity_params )
197+ membership = GraphBase .community_multilevel (
198+ graph , weights , return_levels = False , resolution = resolution
199+ )
200+ result = VertexClustering (
201+ graph , membership , modularity_params = modularity_params
202+ )
189203
190204 return result
191205
@@ -203,7 +217,9 @@ def _community_optimal_modularity(graph, *args, **kwds):
203217
204218 @return: the calculated membership vector and the corresponding
205219 modularity in a tuple."""
206- membership , modularity = GraphBase .community_optimal_modularity (graph , * args , ** kwds )
220+ membership , modularity = GraphBase .community_optimal_modularity (
221+ graph , * args , ** kwds
222+ )
207223 return VertexClustering (graph , membership , modularity )
208224
209225
@@ -236,11 +252,15 @@ def _community_edge_betweenness(graph, clusters=None, directed=True, weights=Non
236252 merges , qs = GraphBase .community_edge_betweenness (graph , directed , weights )
237253 if clusters is None :
238254 if qs is not None :
239- clusters = _optimal_cluster_count_from_merges_and_modularity (graph , merges , qs )
255+ clusters = _optimal_cluster_count_from_merges_and_modularity (
256+ graph , merges , qs
257+ )
240258 else :
241259 clusters = 1
242260
243- return VertexDendrogram (graph , merges , clusters , modularity_params = {"weights" : weights })
261+ return VertexDendrogram (
262+ graph , merges , clusters , modularity_params = {"weights" : weights }
263+ )
244264
245265
246266def _community_spinglass (graph , * args , ** kwds ):
@@ -320,7 +340,9 @@ def _community_walktrap(graph, weights=None, steps=4):
320340 """
321341 merges , qs = GraphBase .community_walktrap (graph , weights , steps )
322342 optimal_count = _optimal_cluster_count_from_merges_and_modularity (graph , merges , qs )
323- return VertexDendrogram (graph , merges , optimal_count , modularity_params = {"weights" : weights })
343+ return VertexDendrogram (
344+ graph , merges , optimal_count , modularity_params = {"weights" : weights }
345+ )
324346
325347
326348def _k_core (graph , * args ):
@@ -370,7 +392,7 @@ def _community_leiden(
370392 initial_membership = None ,
371393 n_iterations = 2 ,
372394 node_weights = None ,
373- ** kwds ,
395+ ** kwds
374396):
375397 """Finds the community structure of the graph using the Leiden
376398 algorithm of Traag, van Eck & Waltman.
@@ -408,7 +430,10 @@ def _community_leiden(
408430 raise ValueError ('objective_function must be "CPM" or "modularity".' )
409431
410432 if "resolution_parameter" in kwds :
411- deprecated ("resolution_parameter keyword argument is deprecated, use " "resolution=... instead" )
433+ deprecated (
434+ "resolution_parameter keyword argument is deprecated, use "
435+ "resolution=... instead"
436+ )
412437 resolution = kwds .pop ("resolution_parameter" )
413438
414439 if kwds :
@@ -431,7 +456,9 @@ def _community_leiden(
431456 if weights is not None :
432457 modularity_params ["weights" ] = weights
433458
434- return VertexClustering (graph , membership , params = params , modularity_params = modularity_params )
459+ return VertexClustering (
460+ graph , membership , params = params , modularity_params = modularity_params
461+ )
435462
436463
437464def _community_voronoi (graph , lengths = None , weights = None , mode = "all" , radius = None ):
@@ -492,7 +519,7 @@ def _community_voronoi(graph, lengths=None, weights=None, mode="all", radius=Non
492519
493520 clustering .generators = generators
494521 return clustering
495-
522+
496523
497524def _modularity (self , membership , weights = None , resolution = 1 , directed = True ):
498525 """Calculates the modularity score of the graph with respect to a given
@@ -532,7 +559,9 @@ def _modularity(self, membership, weights=None, resolution=1, directed=True):
532559 if isinstance (membership , VertexClustering ):
533560 if membership .graph != self :
534561 raise ValueError ("clustering object belongs to another graph" )
535- return GraphBase .modularity (self , membership .membership , weights , resolution , directed )
562+ return GraphBase .modularity (
563+ self , membership .membership , weights , resolution , directed
564+ )
536565 else :
537566 return GraphBase .modularity (self , membership , weights , resolution , directed )
538567
0 commit comments