Skip to main content

similarity_jaccard

Function similarity_jaccard 

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

Compute the full Jaccard similarity matrix for all vertex pairs.

Returns a flat vector of length n * n in row-major order, where result[u * n + v] is the Jaccard similarity between vertices u and v. The diagonal is 1.0 (a vertex is perfectly similar to itself). For pairs of isolated vertices, the similarity is 0.0.

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

ยงExamples

use rust_igraph::{Graph, similarity_jaccard};

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_jaccard(&g).unwrap();
// N(0)={2,3}, N(1)={2,3} โ†’ Jaccard(0,1)=1.0
assert!((sim[0 * 4 + 1] - 1.0).abs() < 1e-10);
// N(0)={2,3}, N(2)={0,1} โ†’ intersection empty, union={0,1,2,3}โ†’0
assert!(sim[0 * 4 + 2].abs() < 1e-10);