File tree Expand file tree Collapse file tree 2 files changed +22
-0
lines changed Expand file tree Collapse file tree 2 files changed +22
-0
lines changed Original file line number Diff line number Diff line change 2
2
# coding: utf-8
3
3
4
4
import copy
5
+ import networkx as nx
5
6
6
7
from itertools import permutations
7
8
from itertools import combinations
8
9
from collections import defaultdict
9
10
10
11
class Louvain (object ):
12
+
13
+ @classmethod
14
+ def convertIGraphToNxGraph (cls , igraph ):
15
+ node_names = igraph .vs ["names" ]
16
+ edge_list = igraph .get_edgelist ()
17
+ weight_list = igraph .es ["weight" ]
18
+ node_dict = defaultdict (str )
19
+
20
+ for idx , node in enumerate (igraph .vs ):
21
+ node_dict [node .index ] = node_names [idx ]
22
+
23
+ convert_list = []
24
+ for idx in range (len (edge_list )):
25
+ edge = edge_list [idx ]
26
+ new_edge = (node_dict [edge [0 ]], node_dict [edge [1 ]], weight_list )
27
+ convert_list .append (new_edge )
28
+
29
+ convert_graph = nx .Graph ()
30
+ convert_graph .add_weighted_edges_from (convert_list )
31
+ return convert_graph
11
32
12
33
@classmethod
13
34
def getBestPartition (cls , graph ):
Original file line number Diff line number Diff line change 7
7
description = "A implementation of louvain method on python" ,
8
8
author = "shogo-ma" ,
9
9
packages = ["louvain" ],
10
+ install_requires = ["networkx" ],
10
11
)
You can’t perform that action at this time.
0 commit comments