Skip to main content

neighbor_sample_weighted

Function neighbor_sample_weighted 

Source
pub fn neighbor_sample_weighted(
    graph: &Graph,
    seeds: &[VertexId],
    fan_out: &[usize],
    weights: &[f64],
    seed: u64,
) -> IgraphResult<NeighborSampleResult>
Expand description

Sample k-hop neighborhoods with importance-weighted sampling.

Like neighbor_sample but samples neighbors proportional to edge weights. Higher-weight edges are more likely to be sampled.

§Examples

use rust_igraph::{Graph, neighbor_sample_weighted};

let g = Graph::from_edges(
    &[(0,1),(0,2),(0,3)], false, Some(4)
).unwrap();
let weights = vec![10.0, 1.0, 1.0]; // edge 0→1 has much higher weight

let result = neighbor_sample_weighted(&g, &[0], &[2], &weights, 42).unwrap();
assert_eq!(result.layers[0], vec![0]);
assert_eq!(result.layers[1].len(), 2);