within_inter_cluster(G, ebunch=None, delta=0.001, community='community')
For two nodes u
and :None:None:`v`
, if a common neighbor :None:None:`w`
belongs to the same community as them, :None:None:`w`
is considered as within-cluster common neighbor of u
and :None:None:`v`
. Otherwise, it is considered as inter-cluster common neighbor of u
and :None:None:`v`
. The ratio between the size of the set of within- and inter-cluster common neighbors is defined as the WIC measure.
A NetworkX undirected graph.
The WIC measure will be computed for each pair of nodes given in the iterable. The pairs must be given as 2-tuples (u, v) where u and v are nodes in the graph. If ebunch is None then all non-existent edges in the graph will be used. Default value: None.
Value to prevent division by zero in case there is no inter-cluster common neighbor between two nodes. See for details. Default value: 0.001.
Nodes attribute name containing the community information. G[u][community] identifies which community u belongs to. Each node belongs to at most one community. Default value: 'community'.
An iterator of 3-tuples in the form (u, v, p) where (u, v) is a pair of nodes and p is their WIC measure.
Compute the ratio of within- and inter-cluster common neighbors of all node pairs in ebunch.
>>> G = nx.Graph()
... G.add_edges_from([(0, 1), (0, 2), (0, 3), (1, 4), (2, 4), (3, 4)])
... G.nodes[0]["community"] = 0
... G.nodes[1]["community"] = 1
... G.nodes[2]["community"] = 0
... G.nodes[3]["community"] = 0
... G.nodes[4]["community"] = 0
... preds = nx.within_inter_cluster(G, [(0, 4)])
... for u, v, p in preds:
... print(f"({u}, {v}) -> {p:.8f}") (0, 4) -> 1.99800200
>>> preds = nx.within_inter_cluster(G, [(0, 4)], delta=0.5)See :
... for u, v, p in preds:
... print(f"({u}, {v}) -> {p:.8f}") (0, 4) -> 1.33333333
The following pages refer to to this document either explicitly or contain code examples using this.
networkx.algorithms.link_prediction.within_inter_cluster
Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.
Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)
SVG is more flexible but power hungry; and does not scale well to 50 + nodes.
All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them