Skip to main content

Normal

Struct Normal 

Source
pub struct Normal {
    pub mean: f64,
    pub std_dev: f64,
}
Expand description

Normal (Gaussian) distribution N(μ, σ²) as a typed struct.

Implements Distribution for use with fit_all / fit_best.

§Examples

use rs_stats::distributions::normal_distribution::Normal;
use rs_stats::distributions::traits::Distribution;

let n = Normal::new(0.0, 1.0).unwrap();
assert!((n.mean() - 0.0).abs() < 1e-10);
assert!((n.pdf(0.0).unwrap() - 0.398_942_280_401_4).abs() < 1e-10);

Fields§

§mean: f64

Mean μ

§std_dev: f64

Standard deviation σ (must be > 0)

Implementations§

Source§

impl Normal

Source

pub fn new(mean: f64, std_dev: f64) -> StatsResult<Self>

Creates a Normal distribution with validation.

Source

pub fn fit(data: &[f64]) -> StatsResult<Self>

Maximum-likelihood estimate from data.

MLE: μ = mean(data), σ = population std-dev. Single-pass online (Welford) — never walks data twice and never allocates.

Trait Implementations§

Source§

impl Clone for Normal

Source§

fn clone(&self) -> Normal

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Normal

Source§

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

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

impl Distribution for Normal

Source§

fn log_likelihood_fast(&self, data: &[f64]) -> f64

Closed-form bulk log-likelihood. Lets LLVM autovectorise the Σ z_i² reduction (no per-point Result-returning closure).

Σ ln f(xᵢ) = −½ · Σ ((xᵢ−μ)/σ)² − n·(ln σ + ½·ln 2π)

Source§

type X = f64

The support type: f64 for continuous distributions, u64 for discrete distributions.
Source§

fn name(&self) -> &str

Human-readable distribution name, e.g. "Normal".
Source§

fn num_params(&self) -> usize

Number of free parameters — used for AIC / BIC.
Source§

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

Probability density (continuous) or probability mass (discrete) at x.
Source§

fn logpdf(&self, x: f64) -> StatsResult<f64>

ln pdf(x). Default: pdf(x).ln(). Override for stability when pdf underflows (e.g. extreme tails of LogNormal).
Source§

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

Cumulative distribution function F(x) = P(X ≤ x).
Source§

fn inverse_cdf(&self, p: f64) -> StatsResult<f64>

Quantile / inverse CDF: smallest x such that F(x) ≥ p.
Source§

fn mean(&self) -> f64

Mean (expected value) μ.
Source§

fn variance(&self) -> f64

Variance σ².
Source§

fn pmf(&self, x: Self::X) -> StatsResult<f64>

Probability mass — alias for pdf, kept for natural reading on discrete distributions and v2.x source-compatibility.
Source§

fn logpmf(&self, x: Self::X) -> StatsResult<f64>

Log-PMF — alias for logpdf.
Source§

fn std_dev(&self) -> f64

Standard deviation σ = √(variance).
Source§

fn log_likelihood(&self, data: &[Self::X]) -> StatsResult<f64>

Sum of log-likelihoods Σ ln pdf(xᵢ). Falls back to StatsError if any point is out of support.
Source§

fn aic(&self, data: &[Self::X]) -> StatsResult<f64>

Akaike Information Criterion: 2k − 2·ln(L̂).
Source§

fn bic(&self, data: &[Self::X]) -> StatsResult<f64>

Bayesian Information Criterion: k·ln(n) − 2·ln(L̂).
Source§

impl Copy for Normal

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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.