Skip to main content

ppr_diffuse

Function ppr_diffuse 

Source
pub fn ppr_diffuse(
    graph: &Graph,
    signal: &[f64],
    alpha: f64,
    max_iter: usize,
    tol: f64,
) -> IgraphResult<Vec<f64>>
Expand description

Diffuse a signal using Personalized PageRank propagation.

Computes the APPNP-style propagation: output = α·signal + (1-α)·D⁻¹A·output (solved by power iteration).

This converges to α·(I - (1-α)·D⁻¹A)⁻¹·signal, the Personalized PageRank vector with signal as the teleportation distribution.

§Parameters

  • graph — Undirected graph.
  • signal — Input signal of length vcount.
  • alpha — Teleportation probability (0 < alpha ≤ 1). Typical: 0.1–0.2.
  • max_iter — Maximum power iterations (default: 50).
  • tol — Convergence tolerance on L∞ change (default: 1e-6).

§Returns

The diffused signal as Vec<f64> of length vcount.

§Examples

use rust_igraph::{Graph, ppr_diffuse};

// Complete graph: PPR with uniform signal stays uniform
let g = Graph::from_edges(
    &[(0,1),(0,2),(0,3),(1,2),(1,3),(2,3)], false, Some(4)
).unwrap();
let signal = vec![0.25, 0.25, 0.25, 0.25];
let diffused = ppr_diffuse(&g, &signal, 0.15, 50, 1e-6).unwrap();
for &v in &diffused {
    assert!((v - 0.25).abs() < 1e-6);
}