Skip to main content

similarity_dice

Function similarity_dice 

Source
pub fn similarity_dice(graph: &Graph) -> IgraphResult<Vec<f64>>
Expand description

Compute the full Dice similarity matrix for all vertex pairs.

Returns a flat vector of length n * n in row-major order. Dice(u, v) = 2 * |N(u) ∩ N(v)| / (|N(u)| + |N(v)|). The diagonal is 1.0. For pairs of isolated vertices, similarity is 0.0.

Counterpart of igraph_similarity_dice(_, _, vss_all(), IGRAPH_ALL, loops=false)

§Examples

use rust_igraph::{Graph, similarity_dice};

let mut g = Graph::with_vertices(4);
g.add_edge(0, 2).unwrap();
g.add_edge(0, 3).unwrap();
g.add_edge(1, 2).unwrap();
g.add_edge(1, 3).unwrap();
let sim = similarity_dice(&g).unwrap();
// N(0)={2,3}, N(1)={2,3}, |intersect|=2, deg_sum=4 → Dice=4/4=1.0
assert!((sim[0 * 4 + 1] - 1.0).abs() < 1e-10);