Skip to main content

Module normal

Module normal 

Source
Expand description

Normal (Gaussian) maximum-likelihood numerics, for the NormalLikelihood.

The two-parameter model θ = [μ, σ] (σ the standard deviation) has the log-likelihood ℓ(μ, σ; x) = −n/2·ln(2π) − n·ln σ − Σ(xᵢ − μ)²/(2σ²), matching scipy.stats.norm.logpdf(x, μ, σ).sum(). Its maximum-likelihood estimate is closed form: μ̂ is the sample mean and σ̂ the biased (population) standard deviation √(Σ(xᵢ − μ̂)²/n), so NormalLikelihood::fit returns an exact MleFit without invoking the numerical optimizer.

§Examples

use stats_claw::likelihood::NormalLikelihood;

let model = NormalLikelihood::default();
let fit = model.fit(&[2.0, 4.0, 4.0, 4.0, 5.0, 5.0, 7.0, 9.0])?;
// Closed-form MLE: sample mean 5, biased std 2.
assert!((fit.params()[0] - 5.0).abs() < 1e-12, "mu_hat was {}", fit.params()[0]);
assert!((fit.params()[1] - 2.0).abs() < 1e-12, "sigma_hat was {}", fit.params()[1]);