community_link_prediction#
- graph_tool.structure.community_link_prediction(g, vertex_pairs, community, method='cn', delta=0.001)[git][source]#
Return link prediction scores of pairs of vertices that use the community structure.
- Parameters:
- g
Graph Graph to be used. Edge directions are ignored.
- vertex_pairsiterable of pairs of
int The pairs of vertices.
- community
VertexPropertyMap Community label of every vertex.
- method
str(optional, default:"cn") Score to compute:
"cn"(common neighbors),"ra"(resource allocation), both in the variant of Soundarajan and Hopcroft, or"wic"(within-inter-cluster).- delta
float(optional, default:1e-3) Positive constant added to the denominator of
"wic".
- g
- Returns:
- scores
numpy.ndarray The score of every pair.
- scores
See also
vertex_similarityLocal similarity indices of pairs of vertices
common_neighbor_centralityCCPA scores of pairs of vertices
graph_tool.inference.BlockStateStochastic block model
Notes
With \(\Gamma(u)\) the set of distinct neighbors of \(u\) other than itself (ignoring the edge directions), \(c(u)\) its community, and \(\Gamma_c(u, v)\) the set of common neighbors \(w \in \Gamma(u)\cap\Gamma(v)\) with \(c(w) = c(u) = c(v)\) (which is empty if \(c(u) \ne c(v)\)), the scores of Soundarajan and Hopcroft [soundarajan-using-2012] are
\[s^{\text{cn}}_{uv} = |\Gamma(u)\cap\Gamma(v)| + |\Gamma_c(u, v)|, \qquad s^{\text{ra}}_{uv} = \sum_{w\in\Gamma_c(u, v)}\frac{1}{k_w},\]where \(k_w = |\Gamma(w)|\) is the number of distinct neighbors of \(w\), and the within-inter-cluster score [valverde-rebaza-link-2012] is
\[s^{\text{wic}}_{uv} = \frac{|\Gamma_c(u,v)|}{|\Gamma(u)\cap\Gamma(v)| - |\Gamma_c(u,v)| + \delta}\]if \(c(u) = c(v)\), and zero otherwise. The common neighbors of every pair are found by merging the sorted lists of neighbors of the two vertices, in time \(O(k_u + k_v)\) per pair, after the lists are sorted in time \(O(E\log k_{\max})\). The scores without the community structure are given by
vertex_similarity().References
[soundarajan-using-2012]Sucheta Soundarajan and John Hopcroft, “Using community information to improve the precision of link prediction methods”, Proceedings of the 21st International Conference on World Wide Web, 607-608 (2012), DOI: 10.1145/2187980.2188150 [sci-hub, @tor]
[valverde-rebaza-link-2012]Jorge Carlos Valverde-Rebaza and Alneu de Andrade Lopes, “Link prediction in complex networks based on cluster information”, Advances in Artificial Intelligence - SBIA 2012, Lecture Notes in Computer Science 7589, 92-101 (2012), DOI: 10.1007/978-3-642-34459-6_10 [sci-hub, @tor]
Examples
>>> g = gt.collection.data["football"] >>> s = gt.community_link_prediction(g, [(0, 1), (0, 4)], g.vp.value) >>> print(s) [ 1. 12.]