Skip to main content

assortativity

Function assortativity 

Source
pub fn assortativity(
    graph: &Graph,
    values: &[f64],
    values_in: Option<&[f64]>,
    weights: Option<&[f64]>,
    directed: bool,
    normalized: bool,
) -> IgraphResult<Option<f64>>
Expand description

Value-based assortativity coefficient of graph.

  • values: numeric value for each vertex (length must equal the vertex count). For directed graphs these are the source values.
  • values_in: optional target values for directed graphs (length must equal the vertex count). When None, values is reused for both endpoints. Ignored for undirected graphs.
  • weights: optional per-edge weights (length must equal the edge count). When None, every edge contributes weight 1.
  • directed: respect edge orientation; only takes effect when the graph itself is directed.
  • normalized: when true, return the standard normalized (Pearson-style) coefficient in [-1, 1]; when false, return the unnormalized covariance-style value.

Returns None when the coefficient is undefined (no edges, zero total weight, or a vanishing variance denominator) — mirroring upstream’s IGRAPH_NAN.

§Errors

Returns IgraphError::InvalidArgument if any input vector length does not match the corresponding count.

§References

M. E. J. Newman: Mixing patterns in networks, Phys. Rev. E 67, 026126 (2003).

§Examples

use rust_igraph::{Graph, assortativity};

// Path 0-1-2 with values mirroring the degrees [1, 2, 1] reproduces
// the degree-assortativity result of -1.0 (perfectly disassortative).
let mut g = Graph::with_vertices(3);
g.add_edge(0, 1).unwrap();
g.add_edge(1, 2).unwrap();
let values = [1.0, 2.0, 1.0];
let r = assortativity(&g, &values, None, None, false, true).unwrap();
assert!((r.unwrap() - (-1.0)).abs() < 1e-12);