Skip to main content

joint_degree_distribution

Function joint_degree_distribution 

Source
pub fn joint_degree_distribution(
    graph: &Graph,
    from_mode: DegreeMode,
    to_mode: DegreeMode,
    directed_neighbors: bool,
    normalized: bool,
    max_from_degree: Option<u32>,
    max_to_degree: Option<u32>,
) -> IgraphResult<Vec<Vec<f64>>>
Expand description

Compute the joint degree distribution matrix.

Returns a matrix P where P[i][j] counts (or gives the probability of) a randomly chosen ordered pair of connected vertices having degrees i and j.

For undirected graphs, from_mode and to_mode are forced to DegreeMode::All and each edge contributes to both P[d(u)][d(v)] and P[d(v)][d(u)].

For directed graphs with directed_neighbors = true, only u → v arcs are counted (incrementing P[deg_from(u)][deg_to(v)]). With directed_neighbors = false, each edge also contributes in reverse.

§Parameters

  • graph — the input graph.
  • from_mode — degree mode for sources (Out/In/All). Ignored for undirected graphs.
  • to_mode — degree mode for targets. Ignored for undirected graphs.
  • directed_neighbors — whether to treat connections as directed. Ignored for undirected graphs.
  • normalized — if true, scale matrix so entries sum to 1.0.
  • max_from_degree — if Some(k), clip row count to k+1.
  • max_to_degree — if Some(k), clip column count to k+1.

§Examples

use rust_igraph::{Graph, joint_degree_distribution, DegreeMode};

let mut g = Graph::with_vertices(4);
g.add_edge(0, 1).unwrap();
g.add_edge(1, 2).unwrap();
g.add_edge(2, 3).unwrap();
// Path graph: degrees are [1, 2, 2, 1]
let p = joint_degree_distribution(
    &g, DegreeMode::All, DegreeMode::All, false, false, None, None,
).unwrap();
// P[1][2] counts edges connecting degree-1 and degree-2 vertices
assert!(p[1][2] > 0.0);