Skip to main content

normix

JAX package for Generalized Hyperbolic distributions as exponential families.

Built on Equinox with Float64 precision throughout.

Installation

pip install normix

Install optional plotting helpers with:

pip install "normix[plotting]"

For local development:

uv sync

Quick Start

import jax
import jax.numpy as jnp

jax.config.update("jax_enable_x64", True)

from normix import GeneralizedHyperbolic
from normix.fitting.em import BatchEMFitter

# Fit GH distribution to data via EM
key = jax.random.PRNGKey(0)
X = jax.random.normal(key, (1000, 3))

model = GeneralizedHyperbolic.from_classical(
    mu=jnp.zeros(3), gamma=jnp.zeros(3),
    sigma=jnp.eye(3), p=-0.5, a=2.0, b=1.0,
)
result = BatchEMFitter(max_iter=100).fit(model, X)

# Evaluate log-density (batched via vmap)
log_p = jax.vmap(result.model.log_prob)(X)   # shape (1000,)

Distributions

Univariate (exponential family)

Class Parameters Description
Gamma alpha, beta Shape α > 0, rate β > 0
InverseGamma alpha, beta Shape α > 0, rate β > 0
InverseGaussian mu, lam Mean μ > 0, shape λ > 0
GIG / GeneralizedInverseGaussian p, a, b Generalized Inverse Gaussian

Multivariate

Class Parameters Description
MultivariateNormal mu, L_Sigma Mean μ, Cholesky L_Sigma of Σ

Normal Variance-Mean Mixtures (marginal)

Class Subordinator Parameters
VarianceGamma Gamma mu, gamma, L_Sigma, alpha, beta
NormalInverseGamma InverseGamma mu, gamma, L_Sigma, alpha, beta
NormalInverseGaussian InverseGaussian mu, gamma, L_Sigma, mu_ig, lam
GeneralizedHyperbolic GIG mu, gamma, L_Sigma, p, a, b

Univariate marginals ($d=1$)

Scalar scipy-style API with cdf/ppf (same parameters as the multivariate marginals above, with scalar mu/gamma/L_Sigma):

Class Subordinator
UnivariateVarianceGamma Gamma
UnivariateNormalInverseGamma InverseGamma
UnivariateNormalInverseGaussian InverseGaussian
UnivariateGeneralizedHyperbolic GIG

Factor-analysis mixtures

Low-rank-plus-diagonal dispersion $\Sigma = FF^\top + \mathrm{diag}(D)$:

Class Subordinator
FactorVarianceGamma Gamma
FactorNormalInverseGamma InverseGamma
FactorNormalInverseGaussian InverseGaussian
FactorGeneralizedHyperbolic GIG

Joint distributions

The Joint* classes (e.g. JointGeneralizedHyperbolic) model the full joint $f(x,y)$ where Y is the mixing variable. They are public exponential families used for analysis, simulation, complete-data likelihood, and the EM E-step; from_natural is implemented (VG/NInvG/NIG validate that $\theta$ lies on the constrained subfamily).

Exponential Family API

All univariate and joint distributions subclass ExponentialFamily(eqx.Module):

import jax
import jax.numpy as jnp

jax.config.update("jax_enable_x64", True)

from normix import Gamma

X = jnp.array([1.0, 1.5, 2.0, 2.5])
dist = Gamma(alpha=jnp.array(2.0), beta=jnp.array(1.0))

# Log-density (single observation)
dist.log_prob(jnp.array(1.5))

# Three parametrizations
theta = dist.natural_params()       # natural parameters θ
eta   = dist.expectation_params()   # expectation parameters η = E[t(X)]
I     = dist.fisher_information()   # Fisher information I(θ) = ∇²ψ(θ)

# Constructors
dist2 = Gamma.from_natural(theta)
dist3 = Gamma.from_expectation(eta)
dist4 = Gamma.fit_mle(X)           # η̂ = mean t(xᵢ)

EM Algorithm

import jax
import jax.numpy as jnp

jax.config.update("jax_enable_x64", True)

from normix import GeneralizedHyperbolic
from normix.fitting.em import BatchEMFitter

d = 3
X = ...  # (n, d) data array

# Initialise from classical parameters
model = GeneralizedHyperbolic.from_classical(
    mu=jnp.zeros(d), gamma=jnp.zeros(d), sigma=jnp.eye(d),
    p=-0.5, a=2.0, b=1.0,
)

# Fit with hybrid CPU/JAX backend for maximum speed
fitter = BatchEMFitter(max_iter=200, tol=1e-6,
                       e_step_backend='cpu', m_step_backend='cpu')
result = fitter.fit(model, X)
fitted = result.model

Bessel Functions

import jax

jax.config.update("jax_enable_x64", True)

from normix import log_kv        # or: from normix.utils.bessel import log_kv

# JIT-able, differentiable (backend='jax', default)
log_kv(v=0.5, z=2.0)

# Fast CPU path for EM hot path (not JIT-able)
log_kv(v=0.5, z=2.0, backend='cpu')

Package Layout

normix/
├── exponential_family.py         # ExponentialFamily base class
├── distributions/                # All distribution implementations
│   ├── gamma.py
│   ├── inverse_gamma.py
│   ├── inverse_gaussian.py
│   ├── generalized_inverse_gaussian.py
│   ├── normal.py
│   ├── variance_gamma.py
│   ├── normal_inverse_gamma.py
│   ├── normal_inverse_gaussian.py
│   └── generalized_hyperbolic.py
├── mixtures/                     # Joint and marginal base classes
├── fitting/em.py                 # BatchEMFitter, EMResult
└── utils/
    ├── bessel.py                 # log_kv with custom JVP
    ├── constants.py              # Shared numerical constants
    ├── plotting.py               # Notebook helpers
    └── validation.py             # EM validation helpers

Development

uv run pytest tests/              # fast default suite
uv run jupyter lab                # notebooks
make -C docs html                 # build docs

Test Suites

The default pytest configuration excludes tests marked slow, stress, integration, or gpu:

uv run pytest tests/

Use marker expressions to run targeted suites:

uv run pytest tests/ -m "smoke or contract"
uv run pytest tests/ -m "slow or stress or integration"
uv run pytest tests/ -m gpu
uv run pytest tests/ -m "not gpu"

Useful profiling recipes:

uv run pytest tests/ --durations=50
JAX_LOG_COMPILES=1 uv run pytest tests/ --durations=50
XLA_PYTHON_CLIENT_PREALLOCATE=false uv run pytest tests/ --durations=50

Distribution log_prob and pdf methods are single-observation APIs. Batch them explicitly with jax.vmap, for example jax.vmap(dist.pdf)(xs). This keeps vector-valued observations, such as multivariate normal-mixture samples, unambiguous while still giving JAX a stable batched computation.

References

  • Barndorff-Nielsen, O. E. (1977). Exponentially decreasing distributions for the logarithm of particle size.
  • Eberlein, E., & Keller, U. (1995). Hyperbolic distributions in finance.

License

MIT — see LICENSE.

Metadata

Release files for normix 0.4.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for normix 0.4.1
File Size Uploaded Provenance
normix-0.4.1.tar.gz 142.8 kB With provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for normix 0.4.1
File Interpreter ABI Platform
normix-0.4.1-py3-none-any.whl Python 3 none any Details

Total release size: 312.0 kB

Release files / normix-0.4.1.tar.gz

Download URL normix-0.4.1.tar.gz
Size 142.8 kB
Tags Source
SHA-256 checksum
How to use checksums
bb4fb35cdb1d03868b338d658ed979d18bb32ff3e34ac3ada1da959f168c9cfa
BLAKE2b-256 checksum
How to use checksums
a8b969f9182b6549a16efa489fb9c69a8dd5fd4d075efc47786569cba753e51a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 18, 2026.

Transparency log

Release files / normix-0.4.1-py3-none-any.whl

Download URL normix-0.4.1-py3-none-any.whl
Size 169.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e5a8498de42e33e4f11524d3a7de9b337ddc57aa966e3c70c8ff0322b4b18d6c
BLAKE2b-256 checksum
How to use checksums
293ec50540c5875e972c066b7993580264a639e535b47cd36d00b23e2eff7812
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 18, 2026.

Transparency log

Security for normix 0.4.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for normix-0.4.1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 18, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page