Skip to main content

get_laplacian

Function get_laplacian 

Source
pub fn get_laplacian(
    graph: &Graph,
    mode: DegreeMode,
    normalization: LaplacianNormalization,
    weights: Option<&[f64]>,
) -> IgraphResult<Vec<Vec<f64>>>
Expand description

Compute the Laplacian matrix of a graph.

Returns an n×n matrix stored in row-major order as Vec<Vec<f64>>.

  • mode: degree mode (Out/In/All). For undirected graphs, forced to All.
  • normalization: normalization method.
  • weights: optional edge weights. If None, unweighted.

§Examples

use rust_igraph::{Graph, DegreeMode, get_laplacian, LaplacianNormalization};

// Path 0-1-2: unnormalized Laplacian
let mut g = Graph::with_vertices(3);
g.add_edge(0, 1).unwrap();
g.add_edge(1, 2).unwrap();
let lap = get_laplacian(&g, DegreeMode::All, LaplacianNormalization::Unnormalized, None).unwrap();
assert!((lap[0][0] - 1.0).abs() < 1e-10);  // deg(0) = 1
assert!((lap[1][1] - 2.0).abs() < 1e-10);  // deg(1) = 2
assert!((lap[0][1] + 1.0).abs() < 1e-10);  // -A[0][1] = -1