panther_similarity#
- graph_tool.structure.panther_similarity(g, source, k=5, path_length=5, c=0.5, delta=0.1, eps=None, weight=None, vector=False, D=10)[git][source]#
Return the vertices most similar to a given one according to the Panther algorithm.
- Parameters:
- g
Graph Graph to be used.
- source
Vertexorint Vertex whose similar vertices are returned.
- k
int(optional, default:5) Number of vertices returned.
- path_length
int(optional, default:5) Number of steps of the random paths.
- c
float(optional, default:0.5) Constant of the sample size.
- delta
float(optional, default:0.1) Probability that the error exceeds
eps.- eps
float(optional, default:None) Error bound; if not given, \(\sqrt{1/E}\).
- weight
EdgePropertyMap(optional, default:None) Edge weights, used as transition weights.
- vector
bool(optional, default:False) If
True, the Panther++ similarity is used (see below).- D
int(optional, default:10) Dimension of the feature vectors of Panther++.
- g
- Returns:
- vertices
numpy.ndarray The
kmost similar vertices, in decreasing similarity.- similarity
numpy.ndarray Their similarities.
- vertices
See also
simrankSimRank similarity of pairs of vertices
vertex_similarityLocal similarity indices of pairs of vertices
Notes
The Panther similarity [zhang-panther-2015] of two vertices is the fraction of \(R\) random paths that contain both, where the paths of
path_lengthsteps start at uniformly chosen vertices, and \(R = \frac{c}{\epsilon^2}(\log_2\binom{T}{2} + 1 + \ln\frac{1}{\delta})\) with \(T\) =path_lengthguarantees an error below \(\epsilon\) with probability \(1 - \delta\). The walks are sampled as withrandom_walk(), in time \(O(RT)\).With
vector == True, every vertex is described by the vector of itsDlargest Panther similarities (to any vertex, itself included), and the similarity of two vertices is the inverse Euclidean distance between their vectors, normalized by the largest one among those returned (Panther++ [zhang-panther-2015]). The vectors are obtained from the co-occurrences of the vertices in the walks, in time \(O(RT^2)\), and the nearest ones by comparing the vector of the source with all others, in time \(O(VD\log V)\).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
[zhang-panther-2015] (1,2)Jing Zhang, Jie Tang, Cong Ma, Hanghang Tong, Yu Jing and Juanzi Li, “Panther: Fast top-k similarity search on large networks”, Proceedings of the 21th ACM SIGKDD International Conference on Knowledge Discovery and Data Mining, 1445-1454 (2015), DOI: 10.1145/2783258.2783267 [sci-hub, @tor]
Examples
>>> g = gt.collection.data["karate"] >>> vs, s = gt.panther_similarity(g, 0, k=3) >>> print(vs) [2 1 3]