Liking cljdoc? Tell your friends :D

criterium.stats.mle

Maximum Likelihood Estimation for statistical distributions.

Provides MLE fitting functions that return both parameter estimates and log-likelihood values for model comparison via AIC/BIC.

Distributions supported:

  • Gamma: Minka's fast fixed-point approximation for shape
  • Log-normal: Closed-form MLE
  • Inverse Gaussian: Closed-form MLE
  • Weibull: Newton-Raphson iteration for shape

All functions return maps with :params and :log-likelihood keys. All functions require typed arrays (DoubleArray, LongArray).

Maximum Likelihood Estimation for statistical distributions.

Provides MLE fitting functions that return both parameter estimates
and log-likelihood values for model comparison via AIC/BIC.

Distributions supported:
- Gamma: Minka's fast fixed-point approximation for shape
- Log-normal: Closed-form MLE
- Inverse Gaussian: Closed-form MLE
- Weibull: Newton-Raphson iteration for shape

All functions return maps with :params and :log-likelihood keys.
All functions require typed arrays (DoubleArray, LongArray).
raw docstring

gamma-mleclj

(gamma-mle samples)
(gamma-mle samples
           {:keys [max-iter tol init-shape] :or {max-iter 100 tol 1.0E-10}})

Maximum likelihood estimation for the gamma distribution.

Uses Minka's fast fixed-point iteration for shape parameter: k_new = k_old × (log(k_old) - ψ(k_old) + log(mean(x)) - mean(log(x)))⁻¹ × (log(k_old) - ψ(k_old))

Simplified form (Newton-like): k_new = k_old + (log(mean) - mean(log) - log(k) + ψ(k)) / (1/k - ψ'(k))

Scale is then: θ = mean(x) / k

Requires a typed array (DoubleArray, LongArray).

Parameters: samples - typed array of positive sample values opts - optional map with: :max-iter - maximum iterations (default 100) :tol - convergence tolerance (default 1e-10) :init-shape - initial shape estimate (default: method of moments)

Returns map with: :params {:shape k, :scale θ} :log-likelihood - the maximized log-likelihood value :iterations - number of iterations used

Throws if any sample is non-positive.

Reference: Minka (2002), Estimating a Gamma distribution

Maximum likelihood estimation for the gamma distribution.

Uses Minka's fast fixed-point iteration for shape parameter:
  k_new = k_old × (log(k_old) - ψ(k_old) + log(mean(x)) - mean(log(x)))⁻¹ × (log(k_old) - ψ(k_old))

Simplified form (Newton-like):
  k_new = k_old + (log(mean) - mean(log) - log(k) + ψ(k)) / (1/k - ψ'(k))

Scale is then: θ = mean(x) / k

Requires a typed array (DoubleArray, LongArray).

Parameters:
  samples - typed array of positive sample values
  opts - optional map with:
    :max-iter - maximum iterations (default 100)
    :tol - convergence tolerance (default 1e-10)
    :init-shape - initial shape estimate (default: method of moments)

Returns map with:
  :params {:shape k, :scale θ}
  :log-likelihood - the maximized log-likelihood value
  :iterations - number of iterations used

Throws if any sample is non-positive.

Reference: Minka (2002), Estimating a Gamma distribution
sourceraw docstring

inverse-gaussian-mleclj

(inverse-gaussian-mle samples)

Maximum likelihood estimation for the inverse Gaussian distribution.

The MLE for inverse Gaussian has a closed-form solution: μ = mean(x) λ = n / Σ(1/xᵢ - 1/μ)

Requires a typed array (DoubleArray, LongArray).

Parameters: samples - typed array of positive sample values

Returns map with: :params {:mu μ, :lambda λ} :log-likelihood - the maximized log-likelihood value

Throws if any sample is non-positive.

Maximum likelihood estimation for the inverse Gaussian distribution.

The MLE for inverse Gaussian has a closed-form solution:
  μ = mean(x)
  λ = n / Σ(1/xᵢ - 1/μ)

Requires a typed array (DoubleArray, LongArray).

Parameters:
  samples - typed array of positive sample values

Returns map with:
  :params {:mu μ, :lambda λ}
  :log-likelihood - the maximized log-likelihood value

Throws if any sample is non-positive.
sourceraw docstring

lognormal-mleclj

(lognormal-mle samples)

Maximum likelihood estimation for the log-normal distribution.

The MLE for log-normal has a closed-form solution: μ = mean(log(x)) σ = sqrt(variance(log(x))) ; using population variance (n denominator)

Requires a typed array (DoubleArray, LongArray).

Parameters: samples - typed array of positive sample values

Returns map with: :params {:mu μ, :sigma σ} :log-likelihood - the maximized log-likelihood value

Throws if any sample is non-positive.

Maximum likelihood estimation for the log-normal distribution.

The MLE for log-normal has a closed-form solution:
  μ = mean(log(x))
  σ = sqrt(variance(log(x)))  ; using population variance (n denominator)

Requires a typed array (DoubleArray, LongArray).

Parameters:
  samples - typed array of positive sample values

Returns map with:
  :params {:mu μ, :sigma σ}
  :log-likelihood - the maximized log-likelihood value

Throws if any sample is non-positive.
sourceraw docstring

weibull-mleclj

(weibull-mle samples)
(weibull-mle samples
             {:keys [max-iter tol init-shape] :or {max-iter 100 tol 1.0E-10}})

Maximum likelihood estimation for the Weibull distribution.

Uses Newton-Raphson iteration to find the shape parameter k that solves: 1/k + mean(log(x)) - (Σxᵏlog(x))/(Σxᵏ) = 0

Once k is found, scale is: λ = (Σxᵏ/n)^(1/k)

To avoid numerical overflow with large sample values, the algorithm normalizes samples by their geometric mean before fitting, then transforms the scale back. The shape parameter is invariant under this transformation.

Requires a typed array (DoubleArray, LongArray).

Parameters: samples - typed array of positive sample values opts - optional map with: :max-iter - maximum iterations (default 100) :tol - convergence tolerance (default 1e-10) :init-shape - initial shape estimate (default: method of moments)

Returns map with: :params {:shape k, :scale λ} :log-likelihood - the maximized log-likelihood value :iterations - number of iterations used

Throws if any sample is non-positive.

Reference: Cohen (1965), Maximum Likelihood Estimation in the Weibull Distribution

Maximum likelihood estimation for the Weibull distribution.

Uses Newton-Raphson iteration to find the shape parameter k that solves:
  1/k + mean(log(x)) - (Σxᵏlog(x))/(Σxᵏ) = 0

Once k is found, scale is: λ = (Σxᵏ/n)^(1/k)

To avoid numerical overflow with large sample values, the algorithm normalizes
samples by their geometric mean before fitting, then transforms the scale back.
The shape parameter is invariant under this transformation.

Requires a typed array (DoubleArray, LongArray).

Parameters:
  samples - typed array of positive sample values
  opts - optional map with:
    :max-iter - maximum iterations (default 100)
    :tol - convergence tolerance (default 1e-10)
    :init-shape - initial shape estimate (default: method of moments)

Returns map with:
  :params {:shape k, :scale λ}
  :log-likelihood - the maximized log-likelihood value
  :iterations - number of iterations used

Throws if any sample is non-positive.

Reference: Cohen (1965), Maximum Likelihood Estimation in the Weibull Distribution
sourceraw docstring

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
Move to previous article
Move to next article
Ctrl+/Jump to the search field
× close