pub fn similarity_jaccard_pairs(
graph: &Graph,
pairs: &[(VertexId, VertexId)],
) -> IgraphResult<Vec<f64>>Expand description
Computes Jaccard similarity coefficients for given vertex pairs.
The Jaccard similarity of two vertices is:
|N(u) ∩ N(v)| / |N(u) ∪ N(v)|
where N(v) is the neighbor set of v. If both vertices are isolated
(no neighbors), the similarity is 0.
§Arguments
graph— the input graph (treated as undirected for neighbor lookup).pairs— slice of(u, v)vertex pairs to compute similarity for.
§Examples
use rust_igraph::{Graph, similarity_jaccard_pairs};
let mut g = Graph::with_vertices(5);
g.add_edge(0, 2).unwrap();
g.add_edge(0, 3).unwrap();
g.add_edge(1, 2).unwrap();
g.add_edge(1, 3).unwrap();
g.add_edge(1, 4).unwrap();
let sim = similarity_jaccard_pairs(&g, &[(0, 1)]).unwrap();
// N(0) = {2,3}, N(1) = {2,3,4}, intersection = {2,3}, union = {2,3,4}
// Jaccard = 2/3
assert!((sim[0] - 2.0 / 3.0).abs() < 1e-10);