pub struct NormalDistribution {
pub mean: f64,
pub standard_deviation: f64,
pub variance: f64,
pub parameterization: String,
pub distribution_name: String,
pub description: String,
}Expand description
Parameters of a Normal (Gaussian) distribution.
The canonical bell-curve, fully specified by its mean and
standard_deviation; variance is carried as a convenience field.
Fields§
§mean: f64Mean μ; the centre of the distribution.
standard_deviation: f64Standard deviation σ; must be > 0.
variance: f64Variance σ²; a convenience field, not required by the numerics.
parameterization: StringOptional parameterization label; unused by the numerics, defaults to empty.
distribution_name: StringOptional human-readable name; unused by the numerics, defaults to empty.
description: StringOptional human-readable description; unused by the numerics, defaults to empty.
Implementations§
Source§impl NormalDistribution
impl NormalDistribution
Sourcepub fn pdf_batch(&self, xs: &[f64], out: &mut [f64])
pub fn pdf_batch(&self, xs: &[f64], out: &mut [f64])
Evaluates the density at every point of xs, writing the results into
out, using the fastest available native-SIMD path (NEON / AVX2 / scalar).
This is the dense batch hot path for evaluating many densities at once. It
is numerically identical to calling Pdf::pdf per
element (the SIMD exp agrees with the scalar exp to ≤ 1e-12 relative),
so callers needing a single value should still use Pdf::pdf.
§Arguments
xs— the evaluation grid.out— the output buffer; should have the same length asxs. If the lengths differ, only the leadingmin(xs.len(), out.len())entries are written.
§Examples
use stats_claw::distributions::Pdf;
use stats_claw::distributions::NormalDistribution;
let n = NormalDistribution { mean: 0.0, standard_deviation: 1.0, ..Default::default() };
let xs = [-1.0, 0.0, 1.0];
let mut out = [0.0; 3];
n.pdf_batch(&xs, &mut out);
assert!((out[1] - n.pdf(0.0)).abs() < 1e-12);Sourcepub fn cdf_batch(&self, xs: &[f64], out: &mut [f64])
pub fn cdf_batch(&self, xs: &[f64], out: &mut [f64])
Evaluates the CDF at every point of xs, writing the results into out.
Numerically identical to calling Cdf::cdf per element; provided as the
batch-layout counterpart of Self::pdf_batch. The erf evaluation stays
scalar (Cody rational), so this is a convenience over the dense grid rather
than a vectorized kernel.
§Arguments
xs— the evaluation grid.out— the output buffer; same-length contract asSelf::pdf_batch.
§Examples
use stats_claw::distributions::Cdf;
use stats_claw::distributions::NormalDistribution;
let n = NormalDistribution { mean: 0.0, standard_deviation: 1.0, ..Default::default() };
let xs = [0.0];
let mut out = [0.0; 1];
n.cdf_batch(&xs, &mut out);
assert!((out[0] - 0.5).abs() < 1e-12);Sourcepub fn sample_batch(&self, rng: &mut SplitMix64, out: &mut [f64])
pub fn sample_batch(&self, rng: &mut SplitMix64, out: &mut [f64])
Draws out.len() variates into out using the native-SIMD batch ziggurat
(NEON / AVX2 / scalar), the dense batch sampling hot path.
This is the batch counterpart of Sample::sample. Where sample draws one
variate by cached Box–Muller (and is the path the equivalence/GoF fixtures
pin), sample_batch fills a whole buffer by the Marsaglia–Tsang ziggurat,
vectorized per CPU — the workload that races numpy’s norm.rvs. Both are
statistically N(mean, σ²); they do not produce the same stream for a given
seed (different algorithms consume the RNG differently), but each is itself
reproducible for a fixed seed and CPU path.
§Arguments
rng— the deterministic generator; advanced in a fixed per-path order so a fixed seed yields a reproducible buffer on a given CPU.out— the output buffer; every element is overwritten with a draw.
§Examples
use stats_claw::distributions::NormalDistribution;
use stats_claw::rng::SplitMix64;
let n = NormalDistribution { mean: 0.0, standard_deviation: 1.0, ..Default::default() };
let mut rng = SplitMix64::new(7);
let mut out = [0.0; 4];
n.sample_batch(&mut rng, &mut out);
// Same seed, same CPU path → identical buffer.
let mut rng2 = SplitMix64::new(7);
let mut out2 = [0.0; 4];
n.sample_batch(&mut rng2, &mut out2);
assert_eq!(out, out2);Trait Implementations§
Source§impl Cdf for NormalDistribution
impl Cdf for NormalDistribution
Source§impl Clone for NormalDistribution
impl Clone for NormalDistribution
Source§fn clone(&self) -> NormalDistribution
fn clone(&self) -> NormalDistribution
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more