Skip to main content

correlated_game

Function correlated_game 

Source
pub fn correlated_game(
    old_graph: &Graph,
    corr: f64,
    p: f64,
    permutation: Option<&[VertexId]>,
    seed: u64,
) -> IgraphResult<Graph>
Expand description

Generate a random graph whose adjacency vector is Pearson-correlated to that of old_graph at level corr.

  • old_graph — input. Must be simple (no self-loops, no multi-edges). Vertex count n and directed are inherited.
  • corr — target correlation, in [0, 1]. 0 is independent (sampled from ER(n, p)); 1 is a relabeled copy of old_graph.
  • p — marginal edge probability, in the open (0, 1). Usually matches the empirical density of old_graph.
  • permutation — optional vertex relabeling. perm[i] names the vertex in old_graph that becomes vertex i in the new graph. Must be a bijection of [0, n).
  • seed — drives the internal SplitMix64 PRNG.

§Errors

  • corr not in [0, 1], p not in (0, 1), either is NaN/∞;
  • permutation.len() != old_graph.vcount();
  • permutation is not a bijection of [0, n);
  • old_graph is not simple.

§Examples

use rust_igraph::{Graph, correlated_game, erdos_renyi_gnp};
let old = erdos_renyi_gnp(20, 0.3, false, false, 11).unwrap();
// Strong correlation: most of old's edges survive.
let new_g = correlated_game(&old, 0.9, 0.3, None, 17).unwrap();
assert_eq!(new_g.vcount(), 20);
assert_eq!(new_g.is_directed(), false);