Skip to main content

katz_centrality

Function katz_centrality 

Source
pub fn katz_centrality(
    graph: &Graph,
    alpha: f64,
    beta: f64,
    max_iter: Option<u32>,
    tol: Option<f64>,
) -> IgraphResult<Vec<f64>>
Expand description

Compute Katz centrality for all vertices using power iteration.

alpha is the attenuation factor — must satisfy 0 < alpha < 1/lambda_max where lambda_max is the largest eigenvalue of the adjacency matrix. A safe default for most graphs is 0.1.

beta is the baseline centrality for each node (typically 1.0).

max_iter caps the number of iterations (default: 1000 if None).

tol is the convergence tolerance on the L2-norm change (default: 1e-6 if None).

For directed graphs, centrality counts walks arriving at each node (i.e. uses in-neighbors).

§Errors

Returns an error if alpha <= 0, max_iter is 0, or if the iteration does not converge within max_iter steps.

§Examples

use rust_igraph::{Graph, katz_centrality};

let g = Graph::from_edges(&[(0,1),(1,2),(2,3),(3,0)], false, None).unwrap();
let c = katz_centrality(&g, 0.1, 1.0, None, None).unwrap();
// Symmetric graph → all centralities equal
let diff = c[0] - c[2];
assert!(diff.abs() < 1e-6);