simrank#
- graph_tool.structure.simrank(g, c=0.8, max_iter=100, epsilon=1e-06, vertex_pairs=None, sim_map=None)[git][source]#
Return the SimRank similarity between pairs of vertices.
- Parameters:
- g
Graph Graph to be used.
- c
float(optional, default:0.8) Decay factor, in the interval \((0, 1)\).
- max_iter
int(optional, default:100) Maximum number of iterations.
- epsilon
float(optional, default:1e-6) The iterations stop when no similarity changes by more than this value.
- vertex_pairsiterable of pairs of integers (optional, default:
None) Pairs of vertices to compute the similarity. If omitted, all pairs will be considered.
- sim_map
VertexPropertyMap(optional, default:None) If provided, and
vertex_pairs is None, the vertex similarities will be stored in this vector-valued property. Otherwise, a new one will be created.
- g
- Returns:
- similarities
numpy.ndarrayorVertexPropertyMap If
vertex_pairswas supplied, this will be anumpy.ndarraywith the corresponding similarities, otherwise it will be a vector-valued vertexVertexPropertyMap, with the similarities to all other vertices.
- similarities
See also
vertex_similarityLocal similarity indices of pairs of vertices
panther_similarityApproximate most similar vertices
Notes
SimRank [jeh-simrank-2002] considers two vertices similar if their in-neighbors (all neighbors, for undirected graphs) are similar, and is defined for \(u \ne v\) by
\[s(u, v) = \frac{c}{k_u k_v}\sum_{a\in\Gamma(u)}\sum_{b\in\Gamma(v)} s(a, b),\]where \(\Gamma(u)\) is the multiset of in-neighbors of \(u\) (with one entry per edge), \(k_u = |\Gamma(u)|\) its in-degree, and \(c\) the decay factor, with \(s(u, u) = 1\), and \(s(u, v) = 0\) if \(u\) or \(v\) have no in-neighbors. It is computed by iterating the equation from \(s(u, v) = \delta_{uv}\), until
max_iteriterations are made or the largest change of a value is smaller thanepsilon, in time \(O(VE)\) per iteration and memory \(O(V^2)\), even if only some pairs are requested, so that it is feasible only for moderately sized graphs.Parallel implementation.
If enabled during compilation, this algorithm will run in parallel using OpenMP. See the parallel algorithms section for information about how to control several aspects of parallelization.
References
[jeh-simrank-2002]Glen Jeh and Jennifer Widom, “SimRank: a measure of structural-context similarity”, Proceedings of the 8th ACM SIGKDD International Conference on Knowledge Discovery and Data Mining, 538-543 (2002), DOI: 10.1145/775047.775126 [sci-hub, @tor]
Examples
>>> g = gt.collection.data["karate"] >>> s = gt.simrank(g, vertex_pairs=[(0, 33), (5, 6)]) >>> print(s) [0.1177797... 0.2540040...]