pub fn sample_exponential_batch<F>(
n: usize,
rate: F,
seed: Option<u64>,
) -> StatsResult<Array1<F>>Expand description
Generate n independent samples from Exp(rate) using a SIMD-accelerated
inverse-CDF transform.
The CDF of Exp(λ) is F(x) = 1 − e^(−λx), so the inverse is:
x = −ln(u) / λwhere u ~ U(0, 1). The vectorised ln from scirs2_core is applied to
the entire batch at once.
§Arguments
n— Number of samples.rate— Rate parameter λ (must be positive; mean = 1/λ).seed— Optional RNG seed.
§Errors
Returns StatsError::InvalidArgument when n == 0 or rate <= 0.
§Examples
use scirs2_stats::sample_exponential_batch;
let rate = 2.0_f64;
let samples = sample_exponential_batch::<f64>(1_000, rate, Some(99))
.expect("sampling failed");
assert_eq!(samples.len(), 1_000);
// Empirical mean should be near 1/rate = 0.5
let mean: f64 = samples.sum() / samples.len() as f64;
assert!((mean - 0.5).abs() < 0.08);