Skip to content

feat: add WaldDistribution (Inverse Gaussian) — erfc-based CDF, first-passage time model #61

Description

@OldCrow

Summary

Add the Wald (Inverse Gaussian) distribution. The CDF requires two erfc evaluations with shifted arguments — the most complex erfc-based implementation in the planned distribution set.

Parametrisation

Mean μ > 0, shape parameter λ > 0. Support: x > 0. Scipy: invgauss (parameterises with μ/λ as a single shape parameter; see below).

PDF(x; μ, λ) = √(λ/(2πx³)) · exp(-λ(x-μ)² / (2μ²x))

log PDF = 0.5·(log(λ) - log(2π) - 3·log(x)) - λ(x-μ)² / (2μ²x)

CDF(x; μ, λ) = Φ(√(λ/x)·(x/μ - 1)) + exp(2λ/μ)·Φ(-√(λ/x)·(x/μ + 1))

where Φ is the standard normal CDF (i.e., erfc calls). The two erfc arguments are √(λ/x)·(x/μ - 1) and -√(λ/x)·(x/μ + 1) — computable with sqrt, scalar_add, and scalar arithmetic.

Properties

  • Mean = μ, Variance = μ³/λ
  • Skewness = 3√(μ/λ), Kurtosis = 15μ/λ
  • MLE: μ̂ = x̄; λ̂ = n / Σ(1/xᵢ - 1/x̄)
  • Relationship: as λ → ∞, Wald → Normal(μ, μ³/λ)
  • Use cases: reaction time distributions (neuroscience), Brownian first-passage times, reliability (inverse-Gaussian lifetime models), financial modelling

Implementation notes

  • CDF batch path: The two erfc arguments require sqrt(λ/x) (element-wise), then two scalar_add passes and two vector_erf calls. The exp(2λ/μ) factor is a scalar constant precomputed at construction time.
  • The exp(2λ/μ) term can overflow for large λ/μ; implement using the log-erfc trick for numerical stability in the tail.
  • Batch log_pdf uses vector_log(x) and scalar arithmetic — no erfc needed for log_pdf, so log_pdf will be faster than CDF.
  • Scipy parameterises Wald as invgauss(mu, scale) where μ_scipy = μ/λ; document the parameterisation difference.
  • MLE is fully closed-form — no Newton–Raphson required, unlike Negative Binomial.
  • Dispatch thresholds: NEVER initially. Calibrate after implementation; expect similar to StudentT CDF given the two erfc calls.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions