Skip to main content

frontier_sampling

Function frontier_sampling 

Source
pub fn frontier_sampling(
    adjacency: &[Vec<usize>],
    n_nodes: usize,
    sample_size: usize,
    rng_seed: u64,
) -> Result<Vec<usize>>
Expand description

Frontier-based graph sampling.

Maintains a frontier set of nodes and at each step:

  1. Picks a random frontier node u.
  2. Picks a random neighbour v of u.
  3. If v is not yet sampled, adds it to the sample and the frontier; if v already sampled, reinserts u into the frontier (Frontier Sampling per Stumpf et al. / Leskovec & Faloutsos 2006).

Frontier sampling preserves degree distribution better than naive random node or random edge sampling.

§Parameters

  • adjacency – unweighted adjacency list.
  • n_nodes – total number of nodes (= adjacency.len()).
  • sample_size – desired number of nodes in the sample.
  • rng_seed – PRNG seed.

§Returns

Sorted Vec<usize> of sampled node indices (length ≤ sample_size).

§Errors

Returns GraphError::InvalidParameter if n_nodes is 0 or sample_size > n_nodes.