Skip to main content

similarity_dice_pairs

Function similarity_dice_pairs 

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

Computes Dice similarity coefficients for given vertex pairs.

The Dice similarity of two vertices is: 2 * |N(u) ∩ N(v)| / (|N(u)| + |N(v)|)

This is related to Jaccard by: Dice = 2*J / (1+J).

§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_dice_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_dice_pairs(&g, &[(0, 1)]).unwrap();
// N(0)={2,3}, N(1)={2,3,4}, |intersection|=2, |N(0)|+|N(1)|=5
// Dice = 2*2/5 = 0.8
assert!((sim[0] - 0.8).abs() < 1e-10);