Skip to main content

hsbm_game

Function hsbm_game 

Source
pub fn hsbm_game(
    n: u32,
    m: u32,
    rho: &[f64],
    c: &[Vec<f64>],
    p: f64,
    seed: u64,
) -> IgraphResult<Graph>
Expand description

Generate a graph from the uniform Hierarchical Stochastic Block Model: every macro-block is the same size m and shares the same internal preference matrix.

  • n — total vertex count. Must satisfy n >= 1 and n % m == 0.
  • m — micro-vertex count per macro-block. Must satisfy m >= 1. The number of macro-blocks is n / m.
  • rho — micro-block proportions inside each macro-block. Length k, entries in [0, 1], sum equal to 1 within √DBL_EPSILON. Each rho[j] * m must also be (within tolerance) an integer.
  • ck × k symmetric Bernoulli pref matrix on the micro-blocks, entries in [0, 1].
  • p — Bernoulli rate for every edge crossing two distinct macro-blocks. Must lie in [0, 1].
  • seed — initialises an internal SplitMix64 PRNG.

The returned graph is always undirected, simple (no loops, no multi-edges). Vertex ordering follows macro-block then micro-block: macro b occupies the range [b*m, (b+1)*m), and inside it micro-block j occupies [b*m + offset_j, b*m + offset_{j+1}).

§Errors

Returns IgraphError::InvalidArgument when any of the constraints above is violated.

§Examples

use rust_igraph::hsbm_game;

// 2 macro-blocks of size 10, each with 2 micro-blocks of 5,
// strong within-cluster ties and a 1 % between-macro rate.
let rho = vec![0.5, 0.5];
let c = vec![vec![0.8, 0.05], vec![0.05, 0.8]];
let g = hsbm_game(20, 10, &rho, &c, 0.01, 42).unwrap();
assert_eq!(g.vcount(), 20);
assert!(!g.is_directed());