pub fn preference_game(
nodes: u32,
types: u32,
type_dist: Option<&[f64]>,
fixed_sizes: bool,
pref_matrix: &[Vec<f64>],
directed: bool,
loops: bool,
seed: u64,
) -> IgraphResult<(Graph, Vec<u32>)>Expand description
Generate a random graph from a type-aware preference (block) model.
Each vertex is assigned to one of types types (uniformly, by
type_dist, or pinned by fixed_sizes); each ordered/unordered
vertex pair (u, v) is then connected with probability
pref_matrix[type(u)][type(v)].
nodes— number of vertices in the graph.types— number of vertex types (≥ 1).type_dist— categorical weights over types;None⇒ uniform.fixed_sizes— whentrue, types are assigned by deterministic block-by-position rather than sampled. Withtype_dist = Some(td)the block sizes aretd[i](must be integer and sum tonodes). Withtype_dist = Nonethe function tries to make groups of equal size.pref_matrix—types × typesconnection probabilities in[0, 1]. Must be symmetric whendirected = false.directed— generate a directed graph.loops— allow self-loop edges.seed— initialises an internalSplitMix64PRNG.
§Returns
(graph, node_types) where node_types[i] is the type of vertex
i in 0..types.
§Errors
Returns IgraphError::InvalidArgument when:
types < 1,type_distlength disagrees withtypes, contains NaN or a negative value,pref_matrixis non-square or has the wrong dimensions,- any pref entry is NaN or outside
[0, 1], pref_matrixis not symmetric when!directed,fixed_sizesandtype_distare both supplied but the entries are not integer or do not sum tonodes,nodesexceeds the2^53f64-exact ceiling.
§Examples
use rust_igraph::preference_game;
// Three types, equal mixture; dense within types, sparse between.
let pref = vec![
vec![0.20, 0.02, 0.02],
vec![0.02, 0.20, 0.02],
vec![0.02, 0.02, 0.20],
];
let (g, types) = preference_game(60, 3, None, false, &pref, false, false, 42).unwrap();
assert_eq!(g.vcount(), 60);
assert_eq!(types.len(), 60);
assert!(types.iter().all(|&t| t < 3));