When I was using community_walktrap, there was a big difference between directed graph and undirected graph. I want to see the implementation code. Where can I see it?
I think this piece of python code
calls this C++ code:
Those links point to the latest releases, so it could be your version is different.
If you give us more information, maybe we can help you better, like what your expectations and outcomes were.
community_walktrap()
is supposed to ignore edge directions. If you have an example where this is not the case, please minimize it and post it here, so we can look at it.
Note that there are several way to convert a directed graph to undirected. Consider this graph:
If you simply ignore edge directions, you get:
This is what community_walktrap()
effectively does, and this is what you get with the each
mode of the as_undirected()
method. However, the default mode used by as_undirected()
is collapse
, which gives us a very different graph:
This may be the reason why you are getting different results.
Note that community_walktrap()
effectively adds up the weights of parallel edges, so in an unweighted directed graph reciprocal directed edges end up interpreted as edges with weight 2.
I will read it carefully. Thank you very much for your help.
Thank you very much for your answer.
I use the same set of data, like [1, 2], [2, 3]… There may also be duplicate edges, but I’m not going to worry about weights for now.
The graph was constructed using nx.Digraph()
and nx.graph()
respectively,
G = nx.DiGraph(); G.add_edge(1, 2); G.add_edge(2, 3); ...
G = nx.Graph(); G.add_edge(1, 2); G.add_edge(2, 3); ...
converted to a “.gml” file and run community_walktrap(steps=6)
, so my directed graph should look like Fig. 3, but my undirected graph looks like Fig. 3 and the result is quite different.
In addition, when I was testing the data set nx.les_lesables_graph ()
, converting it to a bidirectional graph and run community_walktrap(steps=6)
is very different from the undirected graph.
G = nx.DiGraph(); G.add_edge(1, 2); ...
G = nx.Graph(); G.add_edge(1, 2); G.add_edge(2, 1); ...
Looking forward to your prompt reply.
Once again, if you have an example where community_walktrap()
produces a different result for a directed graph than the equivalent undirected one (created using .as_undirected('each')
), please show it. Follow the guide here and make sure that the example is complete and minimal, i.e. remove all aspects of the code that are not necessary for demonstrating the issue (e.g. do not use NetworkX, construct the graph directly in igraph).
Alternatively, construct the graph in NetworkX, save it in a format that can be read by igraph, and then post us the igraph-related code only, along with the input file. This way we can reproduce the issue without getting NetworkX involved (which is crucial to confirm that any issues that we find are on igraph’s side).
I see, the default is just to get rid of the direction and the number of reserved edges, I made a mistake.
Thank you very much!