pub struct ExponentialLikelihood {
pub function_name: String,
pub description: String,
pub formula: String,
}Expand description
Likelihood for waiting-time data under an exponential model.
Fields§
§function_name: StringUnique name identifying a likelihood function.
description: StringFree-text description.
formula: StringMathematical formula.
Implementations§
Source§impl ExponentialLikelihood
impl ExponentialLikelihood
Sourcepub fn fit(&self, data: &[f64]) -> Result<MleFit>
pub fn fit(&self, data: &[f64]) -> Result<MleFit>
Fits this exponential model to data by its closed-form maximum-likelihood
estimate λ̂ = n / Σxᵢ.
The rate MLE is analytic, so the returned MleFit reports
converged = true and zero
iterations; its
log_likelihood is ℓ(λ̂; data) and the AIC/BIC
follow from k = 1 parameter and n = data.len().
§Arguments
data— the observed sample; every value must be≥ 0(the exponential support) and the sample must be non-empty with a strictly positive sum.
§Returns
An MleFit whose single parameter is the rate estimate λ̂.
§Errors
Error::InsufficientDataifdatais empty.Error::InvalidInputif any observation is negative (outside the exponential support) or non-finite.Error::DegenerateInputif every observation is zero (Σxᵢ = 0), which would makeλ̂ = n / 0infinite.
§Examples
use stats_claw::likelihood::ExponentialLikelihood;
let fit = ExponentialLikelihood::default().fit(&[1.0, 2.0, 3.0])?;
// λ̂ = 3 / 6 = 0.5.
assert!((fit.params()[0] - 0.5).abs() < 1e-12, "lambda_hat was {}", fit.params()[0]);
assert!(fit.converged());Trait Implementations§
Source§impl Clone for ExponentialLikelihood
impl Clone for ExponentialLikelihood
Source§fn clone(&self) -> ExponentialLikelihood
fn clone(&self) -> ExponentialLikelihood
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 ExponentialLikelihood
impl Debug for ExponentialLikelihood
Source§impl Default for ExponentialLikelihood
impl Default for ExponentialLikelihood
Source§fn default() -> ExponentialLikelihood
fn default() -> ExponentialLikelihood
Source§impl LogLikelihood for ExponentialLikelihood
impl LogLikelihood for ExponentialLikelihood
Source§fn n_params(&self) -> usize
fn n_params(&self) -> usize
Returns 1: the exponential rate model has the single parameter λ.
§Examples
use stats_claw::likelihood::ExponentialLikelihood;
use stats_claw::likelihood::LogLikelihood;
assert_eq!(ExponentialLikelihood::default().n_params(), 1);Source§fn log_likelihood(&self, params: &[f64], data: &[f64]) -> f64
fn log_likelihood(&self, params: &[f64], data: &[f64]) -> f64
Evaluates the total exponential log-likelihood ℓ(λ; data) = n·ln λ − λ·Σxᵢ.
§Arguments
params— the one-element rate vector[λ]; onlyparams[0]is read.data— the observed sample.
§Returns
The scalar log-likelihood, or f64::NEG_INFINITY when λ ≤ 0, or any
observation is negative or non-finite — all lie outside the model’s valid
domain. Per the LogLikelihood contract a non-finite observation (NaN
or ±∞) yields −∞ rather than propagating a NaN/incidental −∞.
§Examples
use stats_claw::likelihood::ExponentialLikelihood;
use stats_claw::likelihood::LogLikelihood;
let model = ExponentialLikelihood::default();
// ℓ(1; [1, 2]) = 2·ln 1 − 1·3 = −3.
assert!((model.log_likelihood(&[1.0], &[1.0, 2.0]) + 3.0).abs() < 1e-12);
// A non-positive rate is outside the domain.
assert_eq!(model.log_likelihood(&[0.0], &[1.0]), f64::NEG_INFINITY);