panther_similarity

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:
gGraph

Graph to be used.

sourceVertex or int

Vertex whose similar vertices are returned.

kint (optional, default: 5)

Number of vertices returned.

path_lengthint (optional, default: 5)

Number of steps of the random paths.

cfloat (optional, default: 0.5)

Constant of the sample size.

deltafloat (optional, default: 0.1)

Probability that the error exceeds eps.

epsfloat (optional, default: None)

Error bound; if not given, \(\sqrt{1/E}\).

weightEdgePropertyMap (optional, default: None)

Edge weights, used as transition weights.

vectorbool (optional, default: False)

If True, the Panther++ similarity is used (see below).

Dint (optional, default: 10)

Dimension of the feature vectors of Panther++.

Returns:
verticesnumpy.ndarray

The k most similar vertices, in decreasing similarity.

similaritynumpy.ndarray

Their similarities.

See also

simrank

SimRank similarity of pairs of vertices

vertex_similarity

Local 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_length steps start at uniformly chosen vertices, and \(R = \frac{c}{\epsilon^2}(\log_2\binom{T}{2} + 1 + \ln\frac{1}{\delta})\) with \(T\) = path_length guarantees an error below \(\epsilon\) with probability \(1 - \delta\). The walks are sampled as with random_walk(), in time \(O(RT)\).

With vector == True, every vertex is described by the vector of its D largest 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]