Skip to main content

total_variation

Function total_variation 

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

Compute the total variation of a signal on a graph.

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

The L1 analog of Dirichlet energy, less sensitive to outlier edges.

§Examples

use rust_igraph::{Graph, total_variation};

let g = Graph::from_edges(&[(0,1),(1,2)], false, Some(3)).unwrap();
let tv = total_variation(&g, &[0.0, 1.0, 3.0], None).unwrap();
assert!((tv - 3.0).abs() < 1e-10); // |0-1| + |1-3| = 1 + 2