Skip to main content

link_pred_jaccard

Function link_pred_jaccard 

Source
pub fn link_pred_jaccard(
    graph: &Graph,
    pairs: &[(VertexId, VertexId)],
) -> IgraphResult<Vec<f64>>
Expand description

Compute Jaccard Coefficient for given vertex pairs.

For each pair (u, v), returns |N(u) ∩ N(v)| / |N(u) ∪ N(v)|. Returns 0.0 if both vertices have no neighbors.

§Examples

use rust_igraph::{Graph, link_pred_jaccard};

let g = Graph::from_edges(
    &[(0,1),(0,2),(1,2),(1,3),(2,3)], false, Some(4)
).unwrap();
let scores = link_pred_jaccard(&g, &[(0, 3)]).unwrap();
// N(0)={1,2}, N(3)={1,2}. Intersection={1,2}, Union={1,2}
// Jaccard = 2/2 = 1.0
assert!((scores[0] - 1.0).abs() < 1e-10);