Skip to main content

NormalLikelihood

Struct NormalLikelihood 

Source
pub struct NormalLikelihood {
    pub mean_parameterized: bool,
    pub variance_parameterized: bool,
    pub function_name: String,
    pub description: String,
    pub formula: String,
}
Expand description

Likelihood for data under a normal model.

Fields§

§mean_parameterized: bool

Whether the mean is parameterized.

§variance_parameterized: bool

Whether the variance is parameterized.

§function_name: String

Unique name identifying a likelihood function.

§description: String

Free-text description.

§formula: String

Mathematical formula.

Implementations§

Source§

impl NormalLikelihood

Source

pub fn fit(&self, data: &[f64]) -> Result<MleFit>

Closed-form maximum-likelihood fit of θ = [μ, σ] to data.

The Gaussian MLE is analytic: μ̂ is the sample mean and σ̂ the biased (population) standard deviation √(Σ(xᵢ − μ̂)²/n) — matching numpy.std(data, ddof=0). The result is exact, so the returned MleFit reports converged() == true and iterations() == 0.

§Arguments
  • data — the observed sample; must contain at least two points with non-zero spread.
§Returns

An MleFit whose params() are [μ̂, σ̂], carrying the attained log-likelihood and the AIC/BIC (k = 2, n = data.len()).

§Errors
  • Error::InsufficientData if data has fewer than two points (with a single point σ̂ = 0, which the density cannot represent).
  • Error::DegenerateInput if every observation is identical, so the estimated σ̂ is zero and the log-likelihood is undefined.
§Examples
use stats_claw::likelihood::NormalLikelihood;

let fit = NormalLikelihood::default().fit(&[1.0, 2.0, 3.0])?;
assert!((fit.params()[0] - 2.0).abs() < 1e-12, "mu_hat was {}", fit.params()[0]);
assert!(fit.converged());

Trait Implementations§

Source§

impl Clone for NormalLikelihood

Source§

fn clone(&self) -> NormalLikelihood

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 NormalLikelihood

Source§

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

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

impl Default for NormalLikelihood

Source§

fn default() -> NormalLikelihood

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

impl LogLikelihood for NormalLikelihood

Source§

fn n_params(&self) -> usize

Returns 2 — the model’s free parameters are μ (mean) and σ (standard deviation), in that order.

Source§

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

Evaluates the Gaussian log-likelihood ℓ = −n/2·ln(2π) − n·ln σ − Σ(xᵢ − μ)²/(2σ²) with params = [μ, σ].

Returns f64::NEG_INFINITY for any θ outside the valid domain: a non-positive or non-finite σ, or a non-finite μ. Per the LogLikelihood contract, any non-finite observation (NaN or ±∞) also yields f64::NEG_INFINITY rather than letting (xᵢ − μ)² propagate a NaN (or an incidental −∞ for +∞). An empty data yields 0.0 (the empty product’s log-likelihood); callers wanting an error on empty input use NormalLikelihood::fit.

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.