Skip to main content

avg_nearest_neighbor_degree

Function avg_nearest_neighbor_degree 

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

Average nearest-neighbour degree, per vertex.

result[v] = Some(d) where d is the mean degree over v’s neighbours; None if v has no neighbours. Self-loops are counted under upstream’s IGRAPH_LOOPS convention (each loop counts twice for undirected degree).

§Examples

use rust_igraph::{Graph, avg_nearest_neighbor_degree};

// Star with centre 0 and leaves 1-2-3:
// Centre's neighbours have degree 1 each → knn[0] = 1.
// Leaves' single neighbour (centre) has degree 3 → knn[leaf] = 3.
let mut g = Graph::with_vertices(4);
g.add_edge(0, 1).unwrap();
g.add_edge(0, 2).unwrap();
g.add_edge(0, 3).unwrap();
let knn = avg_nearest_neighbor_degree(&g).unwrap();
assert_eq!(knn, vec![Some(1.0), Some(3.0), Some(3.0), Some(3.0)]);