-
Thank so much for this product. As novice user of communities a simple question comes to my mind. Thanks in advance for your answers! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 15 replies
-
Hi @JohannHM and thanks for your question! Disconnected nodes usually end up in singleton modules (one module for each disconnected node). They should not be removed by Infomap at any stage, so can you please provide an example of what you get? |
Beta Was this translation helpful? Give feedback.
-
Hi @danieledler thank for your opinion. import networkx as nx
import math
g = nx.karate_club_graph() # karate-club network
k1 = dict(g.degree()) # taking its degree k1
percentage = 10 # percentage of nodes to remove
n_nodes = math.floor(percentage*len(k1)/100) # num of nodes to remove
nodes_2_remove = list(k1.keys())[:n_nodes] # nodes to remove
G = g.copy() # taking a copy of graph to attack it
G.remove_nodes_from(nodes_2_remove) # attaking the graph
k2 = dict(G.degree()) # taking degree k2 of attaked graph
nodes_degree_zero = [n for n, k in k2.items() if k == 0] # look for nodes with degree = 0
from cdlib import algorithms # importing the infomap
p = algorithms.infomap(G).communities # applying infomap
recovering_nodes = [] # recovering nodes from infomap communities
for community in p:
recovering_nodes.extend(community)
recovering_nodes = sorted(recovering_nodes)
# comparing nodes before applying infomap with those after infomap method
missing_nodes = sorted(list(set(G.nodes()) - set(recovering_nodes)))
# infomap does not take into disconnected ndoes as singleton communities
print(missing_nodes == nodes_degree_zero) when I testes with the web https://www.mapequation.org/infomap/ thanks |
Beta Was this translation helpful? Give feedback.
Hi @danieledler thank for your opinion.
Im working with cdlib library that uses exactly the same code here. In fact this python example was tested on your web of infomap with the same results. The idea is attacking a network by removing some hubs, thus some disconnected nodes appear, and then applying infomap. Recovering the nodes after infomap with those before applying it. Look at this: