Skip to main content

similarity_dice_es

Function similarity_dice_es 

Source
pub fn similarity_dice_es(graph: &Graph, eids: &[u32]) -> IgraphResult<Vec<f64>>
Expand description

Computes Dice similarity coefficients for pairs of vertices connected by the given edges.

For each edge ID in eids, this retrieves the endpoint pair (u, v) and computes the Dice similarity between u and v.

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

Counterpart of igraph_similarity_dice_es().

§Examples

use rust_igraph::{Graph, similarity_dice_es};

let mut g = Graph::with_vertices(5);
g.add_edge(0, 2).unwrap(); // edge 0
g.add_edge(0, 3).unwrap(); // edge 1
g.add_edge(1, 2).unwrap(); // edge 2
g.add_edge(1, 3).unwrap(); // edge 3
g.add_edge(1, 4).unwrap(); // edge 4
g.add_edge(0, 1).unwrap(); // edge 5

// Dice of edge 5 endpoints (0,1):
// N(0)={1,2,3}, N(1)={0,2,3,4}, |intersection|=2, |N(0)|+|N(1)|=7
// Dice = 2*2/7 ≈ 0.5714
let sim = similarity_dice_es(&g, &[5]).unwrap();
assert!((sim[0] - 4.0 / 7.0).abs() < 1e-10);