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.

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 name(&self) -> &str

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

fn num_params(&self) -> usize

Number of free parameters (used when computing AIC / BIC).
Source§

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

Probability density function f(x).
Source§

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

Natural logarithm of the PDF: ln f(x). Read more
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): find x such that F(x) = p.
Source§

fn mean(&self) -> f64

Mean (expected value) μ.
Source§

fn variance(&self) -> f64

Variance σ².
Source§

fn std_dev(&self) -> f64

Standard deviation σ = √(variance).
Source§

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

Sum of log-likelihoods: Σ ln f(xᵢ).
Source§

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

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

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

Bayesian Information Criterion: BIC = 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> 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.