Skip to main content

callaway_traits_game

Function callaway_traits_game 

Source
pub fn callaway_traits_game(
    nodes: u32,
    types: u32,
    edges_per_step: u32,
    type_dist: Option<&[f64]>,
    pref_matrix: &[Vec<f64>],
    directed: bool,
    seed: u64,
) -> IgraphResult<(Graph, Vec<u32>)>
Expand description

Generates a random graph with vertex types via the Callaway et al. (2001) growing model.

At each step i ∈ [1, nodes), edges_per_step candidate edges are generated by picking two vertices uniformly at random from [0, i] (inclusive of i — the vertex just added) and accepting the edge with probability pref_matrix[type1][type2].

  • nodes — number of vertices.
  • types ≥ 1 — number of vertex types.
  • edges_per_step — number of candidate edges per step.
  • type_dist — categorical weights over types; None means uniform. Must be the same length as types, all entries non-negative, total mass strictly positive.
  • pref_matrixtypes × types matrix of acceptance probabilities in [0, 1]. When directed = false it must be symmetric.
  • directed — generate a directed graph.
  • seedSplitMix64 seed.

Returns the generated Graph and the per-vertex type vector.

§Self-loops & multi-edges

The output is not simple by construction: candidate edges allow node1 == node2 (self-loop) and the same vertex pair may be drawn multiple times (multi-edge).

§Errors

Returns IgraphError::InvalidArgument when the preference matrix or type distribution is malformed (wrong size, NaN, out-of-range probability, asymmetric for an undirected graph) or when the type distribution is non-positive everywhere.

§Example

use rust_igraph::callaway_traits_game;

// Two types, only-cross prefs ⇒ bipartite-flavoured directed graph.
let pref = vec![vec![0.0, 1.0], vec![1.0, 0.0]];
let (g, types) =
    callaway_traits_game(20, 2, 3, Some(&[1.0, 1.0]), &pref, true, 42).unwrap();
assert_eq!(g.vcount(), 20);
assert_eq!(types.len(), 20);
assert!(types.iter().all(|&t| t < 2));