Skip to main content

link_pred_common_neighbors

Function link_pred_common_neighbors 

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

Compute Common Neighbors score for given vertex pairs.

For each pair (u, v), returns |N(u) ∩ N(v)| — the number of shared neighbors.

§Examples

use rust_igraph::{Graph, link_pred_common_neighbors};

let g = Graph::from_edges(
    &[(0,1),(0,2),(1,2),(1,3),(2,3)], false, Some(4)
).unwrap();
let scores = link_pred_common_neighbors(&g, &[(0, 3)]).unwrap();
// Vertices 0 and 3 share neighbors 1 and 2
assert_eq!(scores[0], 2.0);