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: f64Mean μ
std_dev: f64Standard deviation σ (must be > 0)
Implementations§
Source§impl Normal
impl Normal
Sourcepub fn new(mean: f64, std_dev: f64) -> StatsResult<Self>
pub fn new(mean: f64, std_dev: f64) -> StatsResult<Self>
Creates a Normal distribution with validation.
Sourcepub fn fit(data: &[f64]) -> StatsResult<Self>
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 Distribution for Normal
impl Distribution for Normal
Source§fn log_likelihood_fast(&self, data: &[f64]) -> f64
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
type X = f64
The support type:
f64 for continuous distributions, u64 for
discrete distributions.Source§fn num_params(&self) -> usize
fn num_params(&self) -> usize
Number of free parameters — used for AIC / BIC.
Source§fn pdf(&self, x: f64) -> StatsResult<f64>
fn pdf(&self, x: f64) -> StatsResult<f64>
Probability density (continuous) or probability mass (discrete) at
x.Source§fn logpdf(&self, x: f64) -> StatsResult<f64>
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 inverse_cdf(&self, p: f64) -> StatsResult<f64>
fn inverse_cdf(&self, p: f64) -> StatsResult<f64>
Quantile / inverse CDF: smallest
x such that F(x) ≥ p.Source§fn pmf(&self, x: Self::X) -> StatsResult<f64>
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 log_likelihood(&self, data: &[Self::X]) -> StatsResult<f64>
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.impl Copy for Normal
Auto Trait Implementations§
impl Freeze for Normal
impl RefUnwindSafe for Normal
impl Send for Normal
impl Sync for Normal
impl Unpin for Normal
impl UnsafeUnpin for Normal
impl UnwindSafe for Normal
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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