Skip to main content

dirichlet_energy

Function dirichlet_energy 

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

Compute the Dirichlet energy of a signal on a graph.

E_D(f) = Σ_{(u,v)∈E} w(u,v) · (f(u) - f(v))²

Measures the total squared variation of the signal across edges. A constant signal has Dirichlet energy zero; a signal that varies wildly across edges has high energy.

§Parameters

  • graph — The input graph (directed or undirected).
  • signal — Signal values, one per vertex.
  • weights — Optional edge weights. If None, each edge has weight 1.

§Examples

use rust_igraph::{Graph, dirichlet_energy};

let g = Graph::from_edges(&[(0,1),(1,2),(2,3)], false, Some(4)).unwrap();
// Constant signal → energy = 0
let e = dirichlet_energy(&g, &[5.0, 5.0, 5.0, 5.0], None).unwrap();
assert!(e.abs() < 1e-10);
// Step signal → energy > 0
let e2 = dirichlet_energy(&g, &[0.0, 0.0, 1.0, 1.0], None).unwrap();
assert!((e2 - 1.0).abs() < 1e-10);