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: boolWhether the mean is parameterized.
variance_parameterized: boolWhether the variance is parameterized.
function_name: StringUnique name identifying a likelihood function.
description: StringFree-text description.
formula: StringMathematical formula.
Implementations§
Source§impl NormalLikelihood
impl NormalLikelihood
Sourcepub fn fit(&self, data: &[f64]) -> Result<MleFit>
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::InsufficientDataifdatahas fewer than two points (with a single pointσ̂ = 0, which the density cannot represent).Error::DegenerateInputif 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
impl Clone for NormalLikelihood
Source§fn clone(&self) -> NormalLikelihood
fn clone(&self) -> NormalLikelihood
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for NormalLikelihood
impl Debug for NormalLikelihood
Source§impl Default for NormalLikelihood
impl Default for NormalLikelihood
Source§fn default() -> NormalLikelihood
fn default() -> NormalLikelihood
Source§impl LogLikelihood for NormalLikelihood
impl LogLikelihood for NormalLikelihood
Source§fn n_params(&self) -> usize
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
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.