Skip to main content

assortativity_degree_weighted

Function assortativity_degree_weighted 

Source
pub fn assortativity_degree_weighted(
    graph: &Graph,
    weights: &[f64],
) -> IgraphResult<Option<f64>>
Expand description

Weighted degree assortativity coefficient.

weights[e] must be non-negative and finite; weights.len() must equal graph.ecount(). Returns None when the metric is undefined (no edges, zero total weight, or all-equal strength → zero variance). Directed graphs return IgraphError::Unsupported.

§Examples

use rust_igraph::{Graph, assortativity_degree_weighted};

// Path 0-1-2 with unit weights → strengths [1, 2, 1]; r = -1.0
// (matches the unweighted PR-006 result on the same graph).
let mut g = Graph::with_vertices(3);
g.add_edge(0, 1).unwrap();
g.add_edge(1, 2).unwrap();
let r = assortativity_degree_weighted(&g, &[1.0, 1.0]).unwrap();
assert!((r.unwrap() - (-1.0_f64)).abs() < 1e-12);