Skip to content

feat: add FDistribution and InverseGammaDistribution — Gamma/Beta family delegation wrappers #56

Description

@OldCrow

Summary

Add two continuous distributions that delegate to existing BetaDistribution and GammaDistribution via parameter transforms, requiring no new mathematical primitives.

FDistribution (Snedecor's F)

Parametrisation: degrees of freedom d₁ > 0, d₂ > 0. Scipy: f.

If X ~ Beta(d₁/2, d₂/2), then F = (X/(1-X)) · (d₂/d₁) ~ F(d₁, d₂).

CDF_F(x; d₁, d₂) = CDF_Beta(d₁·x / (d₁·x + d₂); d₁/2, d₂/2)
PDF_F(x; d₁, d₂) = PDF_Beta(d₁·x/(d₁·x+d₂); ...) · d₁·d₂ / (d₁·x+d₂)²

Batch operations: transform the input array (scalar arithmetic) then call BetaDistribution batch methods.

  • Mean = d₂/(d₂-2) for d₂ > 2; Variance = 2d₂²(d₁+d₂-2) / (d₁(d₂-2)²(d₂-4)) for d₂ > 4
  • MLE: no closed form; typically d₁/d₂ are fixed by experimental design
  • Use cases: ANOVA F-test, regression model comparison, ratio of variances, F-distribution critical values
  • Note: this is the single most commonly used test-statistic distribution absent from libstats

InverseGammaDistribution

Parametrisation: shape α > 0, scale β > 0. If X ~ Gamma(α, 1/β), then 1/X ~ InvGamma(α, β). Scipy: invgamma.

CDF_InvGamma(x; α, β) = 1 - CDF_Gamma(1/x; α, 1/β)  [upper incomplete gamma]
PDF_InvGamma(x; α, β) = PDF_Gamma(1/x; α, 1/β) / x²

Batch operations: compute 1/x for each element (scalar reciprocal — no transcendental needed), then call GammaDistribution batch methods.

  • Mean = β/(α-1) for α > 1; Variance = β²/((α-1)²(α-2)) for α > 2
  • MLE: same structure as Gamma MLE with x → 1/x substitution
  • Use cases: conjugate prior for Gaussian variance in Bayesian models, prior for scale parameters, reliability (inverse-Gamma lifetime distributions)

Implementation notes

  • Both follow the full 6-step registration checklist in include/core/distribution_meta.h
  • Dispatch thresholds: copy from Beta (F distribution) and Gamma (InvGamma) respectively
  • is_delegation_wrapper = true for both
  • The x → 1/x transform for InvGamma is element-wise division — one pass over the input before delegating; no new SIMD primitive needed
  • FDistribution should validate d₁ > 0, d₂ > 0; degenerate moments (d₂ ≤ 2 for mean, d₂ ≤ 4 for variance) should return NaN with documentation

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions