Skip to content Skip to sidebar Skip to footer

How To Get The Details Of Triads In R/python?

I am currently using igraph to get the traid census of a given directed graph usingtriad_census(g). This returns the count of triads in each of the 16 classes. e.g., 16 3 0 10 1

Solution 1:

There doesn't seem to be a builtin method to accomplish what you want with Networkx. However, you can manually go through each triad and define which class it belongs to:

from itertools importcombinationstriad_class= {}
for nodes in combinations(G.nodes, 3):
    triad_class[nodes] = [k for k, v in nx.triads.triadic_census(G.subgraph(nodes)).items() if v][0]

If you'd rather have a dictionary with the classes as the keys, you can try something like this:

from itertools importcombinationstriad_class= {}
for nodes in combinations(G.nodes, 3):
    tc = [k for k, v in nx.triads.triadic_census(G.subgraph(nodes)).items() if v][0]
    triad_class.setdefault(tc, []).append(nodes)

Post a Comment for "How To Get The Details Of Triads In R/python?"