Skip to main content

knnk

Function knnk 

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

Per-degree average nearest-neighbour degree, k_nn(k).

Counterpart of igraph_avg_nearest_neighbor_degree(_, _, _, _, NULL, &knnk, NULL). The output has length maxdeg(graph); entry result[k-1] is the mean of knn[v] over all vertices with degree k. Returns None for degrees that no vertex has (matches upstream’s IGRAPH_NAN).

§Examples

use rust_igraph::{Graph, knnk};

// Star K_{1,3}: leaves (deg 1) all have knn=3, centre (deg 3) has knn=1.
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 r = knnk(&g).unwrap();
assert_eq!(r, vec![Some(3.0), None, Some(1.0)]);