pub fn sample_dirichlet(
n: usize,
alpha: &[f64],
seed: u64,
) -> IgraphResult<Vec<Vec<f64>>>Expand description
Sample points from a Dirichlet distribution.
Generates n vectors drawn from a Dirichlet distribution with
concentration parameters alpha. Each sample sums to 1.0. Uses
the Gamma-based method: draw independent Gamma(alpha_i, 1) values
and normalize.
Returns a Vec<Vec<f64>> where each inner Vec has alpha.len()
elements summing to 1.0.
§Errors
Returns InvalidArgument if:
alpha.len() < 2- Any element of
alphais non-positive.
§Examples
use rust_igraph::sample_dirichlet;
let alpha = [1.0, 2.0, 3.0];
let samples = sample_dirichlet(5, &alpha, 42).unwrap();
assert_eq!(samples.len(), 5);
for s in &samples {
assert_eq!(s.len(), 3);
let sum: f64 = s.iter().sum();
assert!((sum - 1.0).abs() < 1e-10);
for &v in s {
assert!(v >= 0.0);
}
}