Skip to main content

edge_degree_cosine

Function edge_degree_cosine 

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

Compute the cosine similarity of degree vectors across edges.

cos = Σ d(u)·d(v) / √(Σ d(u)² · Σ d(v)²)

where the sums run over all edges. Treats each edge endpoint as a component of two vectors. Returns 0.0 for the empty graph. Self-loops are skipped.

§Examples

use rust_igraph::{Graph, edge_degree_cosine};

// K_3: all (2,2) → cos = 3·4 / √(3·4 · 3·4) = 12/12 = 1.0
let g = Graph::from_edges(&[(0,1),(1,2),(0,2)], false, Some(3)).unwrap();
assert!((edge_degree_cosine(&g).unwrap() - 1.0).abs() < 1e-10);