Skip to main content

NormalDistribution

Struct NormalDistribution 

Source
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: f64

Mean μ; the centre of the distribution.

§standard_deviation: f64

Standard deviation σ; must be > 0.

§variance: f64

Variance σ²; a convenience field, not required by the numerics.

§parameterization: String

Optional parameterization label; unused by the numerics, defaults to empty.

§distribution_name: String

Optional human-readable name; unused by the numerics, defaults to empty.

§description: String

Optional human-readable description; unused by the numerics, defaults to empty.

Implementations§

Source§

impl NormalDistribution

Source

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 as xs. If the lengths differ, only the leading min(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);
Source

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 as Self::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);
Source

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

Source§

fn cdf(&self, x: f64) -> f64

Evaluates the cumulative distribution function at x. Read more
Source§

impl Clone for NormalDistribution

Source§

fn clone(&self) -> NormalDistribution

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for NormalDistribution

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for NormalDistribution

Source§

fn default() -> NormalDistribution

Returns the “default value” for a type. Read more
Source§

impl LogCdf for NormalDistribution

Source§

fn logsf(&self, x: f64) -> f64

Evaluates the natural log of the survival function, ln P(X > x). Read more
Source§

fn logcdf(&self, x: f64) -> f64

Evaluates the natural log of the CDF, ln P(X ≤ x). Read more
Source§

impl Moments for NormalDistribution

Source§

fn mean(&self) -> Option<f64>

Returns the theoretical mean, or None if it is undefined.
Source§

fn variance(&self) -> Option<f64>

Returns the theoretical variance, or None if it is undefined.
Source§

impl Pdf for NormalDistribution

Source§

fn pdf(&self, x: f64) -> f64

Evaluates the probability density function at x. Read more
Source§

impl Quantile for NormalDistribution

Source§

fn quantile(&self, p: f64) -> f64

Evaluates the quantile (inverse CDF) at probability p. Read more
Source§

impl Sample for NormalDistribution

Source§

fn sample(&self, rng: &mut SplitMix64) -> f64

Draws one variate, advancing rng. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.