Skip to main content

neighbor_aggregate

Function neighbor_aggregate 

Source
pub fn neighbor_aggregate(
    graph: &Graph,
    signal: &[f64],
    mode: AggMode,
) -> IgraphResult<Vec<f64>>
Expand description

Aggregate a signal over each vertex’s neighborhood.

For each vertex v, computes an aggregate of signal[u] over all neighbors u ∈ N(v) using the specified mode. Isolated vertices receive 0.0 for Mean/Sum, f64::NEG_INFINITY for Max, and f64::INFINITY for Min.

§Parameters

  • graph — The input graph (undirected).
  • signal — Input signal of length vcount.
  • mode — Aggregation mode (Mean, Sum, Max, Min).

§Examples

use rust_igraph::{Graph, AggMode, neighbor_aggregate};

let g = Graph::from_edges(&[(0,1),(1,2),(0,2)], false, Some(3)).unwrap();
let signal = vec![1.0, 2.0, 3.0];
let mean_agg = neighbor_aggregate(&g, &signal, AggMode::Mean).unwrap();
// Vertex 0: neighbors {1,2}, mean = (2+3)/2 = 2.5
assert!((mean_agg[0] - 2.5).abs() < 1e-10);
let sum_agg = neighbor_aggregate(&g, &signal, AggMode::Sum).unwrap();
// Vertex 0: sum = 2+3 = 5
assert!((sum_agg[0] - 5.0).abs() < 1e-10);