mapequation / infomap

Multi-level network clustering based on the Map Equation
https://mapequation.org/infomap
GNU General Public License v3.0
425 stars 88 forks source link

Does infomap not work with points that are too long, such as bank card numbers of similar length? #355

Closed zhangke-zhangke closed 5 months ago

zhangke-zhangke commented 5 months ago

Building Infomap network from a NetworkX graph... node : (320015954360525044901, 320015963360525029312) type : <class 'int'> <class 'int'>

error : Traceback (most recent call last): File "D:/Gitlab/CommunityDetection/Infomap.py", line 225, in a.printCom(graph) File "D:/Gitlab/CommunityDetection/Infomap.py", line 70, in printCom self.findCommunities(G) File "D:/Gitlab/CommunityDetection/Infomap.py", line 46, in findCommunities network.addLink(e) File "D:\Anaconda3\envs\graph\lib\site-packages\infomap.py", line 2414, in addLink return _infomap.StateNetwork_addLink(self, args) TypeError: Wrong number or type of arguments for overloaded function 'StateNetwork_addLink'. Possible C/C++ prototypes are: infomap::StateNetwork::addLink(unsigned int,unsigned int,double) infomap::StateNetwork::addLink(unsigned int,unsigned int) infomap::StateNetwork::addLink(unsigned int,unsigned int,unsigned long)

zhangke-zhangke commented 5 months ago

After adjusting the length of the point, it can run successfully.

Building Infomap network from a NetworkX graph... node : (32001595, 32001596) type : <class 'int'> <class 'int'>

Find communities with Infomap...

Infomap v2.7.1 starts at 2024-03-14 11:57:54 -> Input network: -> No file output!

-> Ordinary network input, using the Map Equation for first order network flows Calculating global network flow using flow model 'undirected'... -> Using undirected links. => Sum node flow: 1, sum link flow: 1 Build internal network with 2 nodes and 1 links... -> One-level codelength: 1

================================================ Trial 1/1 starting at 2024-03-14 11:57:54

Two-level compression: 0% Partitioned to codelength 0 + 1 = 1 in 1 (0 non-trivial) modules.

=> Trial 1/1 finished in 7.14e-05s with codelength 1

================================================ Summary after 1 trial

Best end modular solution in 2 levels: Per level number of modules: [ 1, 0] (sum: 1) Per level number of leaf nodes: [ 0, 2] (sum: 2) Per level average child degree: [ 1, 2] (average: 1.66667) Per level codelength for modules: [0.000000000, 0.000000000] (sum: 0.000000000) Per level codelength for leaf nodes: [0.000000000, 1.000000000] (sum: 1.000000000) Per level codelength total: [0.000000000, 1.000000000] (sum: 1.000000000)

=================================================== Infomap ends at 2024-03-14 11:57:54 (Elapsed time: 0.0002452s)

Found 1 modules with codelength: 1.000000 社区1,成员[32001595, 32001596] 0.25

danieledler commented 5 months ago

Hi. As you may see we use unsigned integers for node ids, which in C++ are 32 bits long covering the range 0 to 4294967295. This should be enough to uniquely identify all nodes for all practical purposes. If you have larger integers to identify nodes, such as bank card numbers, you have to map those to lower integers. In NetworkX you can simply run convert_node_labels_to_integers to do that.

If you want to include such long ids in Infomap, you have to convert them to strings and use as node names instead of ids. If you already have or convert the ids to strings in NetworkX and add the graph to Infomap with add_networkx_graph, it will automatically run the above function and store the string ids as node names.