Skip to main content

gmm-divergence

Tools for comparing Gaussian mixtures and fitting mixture weights, with support for categorical distributions.

This package is under development. APIs, estimators, and numerical behavior may change between early releases.

Read the documentation →

Current Scope

The package currently includes:

  • Typed Gaussian and Gaussian mixture representations with density evaluation, sampling, component responsibilities, and scikit-learn conversion
  • KL divergence estimators based on closed-form Gaussian KL, Monte Carlo sampling, unscented sigma points, Gaussian approximations, and variational bounds
  • Explicit sampling controls for drawn, reused, and stratified Monte Carlo samples
  • Symmetric KL, Jensen-Shannon divergence, categorical KL, and aligned-component joint KL with a weight/component decomposition
  • Gaussian-mixture weight fitting with forward, reverse, bidirectional, Jensen-Shannon, and moment-matching objectives; categorical-mixture weight fitting with forward KL
  • Softmax L-BFGS-B and simplex-constrained SLSQP optimizers, reusable Gaussian fitting objectives, and candidate selection
  • Responsibility-weighted empirical component statistics
  • Covariance regularization utilities for diagonal loading, shrinkage, eigenvalue clipping, and low-rank approximation

Installation

This project is not yet intended for stable production use. A pre-release is available from PyPI:

python -m pip install gmm-divergence

Quick Example

import gmm_divergence as gd

p = gd.GaussianMixture.from_components(
    [
        gd.Gaussian.univariate(mean=-1.0, variance=0.5),
        gd.Gaussian.univariate(mean=1.5, variance=1.0),
    ],
    weights=[0.4, 0.6],
)
q = gd.GaussianMixture.from_components([
    gd.Gaussian.univariate(mean=-0.8, variance=0.7),
    gd.Gaussian.univariate(mean=1.8, variance=1.2),
])

result = gd.kl_divergence(
    p, q, estimator=gd.divergence.MonteCarlo(sampling=gd.sampling.Draw(n_samples=50_000, rng=0))
)
print(result.value, result.monte_carlo.standard_error)

The top-level module keeps the common distribution classes and primary helper functions. Configuration objects are grouped by domain, for example gd.divergence.MonteCarlo, gd.sampling.Draw, gd.fitting.ForwardKL, and gd.covariance.DiagonalLoading.

Fitting Mixture Weights

candidates = [
    gd.Gaussian.univariate(mean=-1.0, variance=0.5),
    gd.Gaussian.univariate(mean=1.5, variance=1.0),
]

fit = gd.fit_gaussian_weights(
    p,
    candidates,
    optimizer=gd.fitting.SoftmaxLBFGSB(),
    objective=gd.fitting.MomentMatching(fit_second_moments=True),
)
print(fit.weights)

Fit a mixture of categorical distributions using the same optimizer options:

fit = gd.fitting.fit_categorical_weights(
    [0.4, 0.6], [[0.8, 0.2], [0.1, 0.9]], optimizer=gd.fitting.SimplexSLSQP()
)
print(fit.weights)

The public API uses explicit keyword-only estimator, objective, and optimizer configurations. Combined and fitted mixtures compose directly with divergence functions and retain component provenance. Distribution parameters and result arrays are owned and read-only. Categorical KL and forward-KL weight fitting are available at the root alongside their Gaussian counterparts. See the API reference for sampling records, directional scoring, and prepared-fit reuse.

Metadata

Release files for gmm-divergence 0.0.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 gmm-divergence 0.0.1
File Size Uploaded Provenance Actions
gmm_divergence-0.0.1.tar.gz 49.1 kB With provenance Details for gmm_divergence-0.0.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for gmm-divergence 0.0.1
File Interpreter ABI Platform Actions
gmm_divergence-0.0.1-py3-none-any.whl Python 3 none any Details for gmm_divergence-0.0.1-py3-none-any.whl

Total release size: 117.5 kB

Release files / gmm_divergence-0.0.1.tar.gz

Download URL gmm_divergence-0.0.1.tar.gz
Size 49.1 kB
Tags Source
SHA-256 checksum
How to use checksums
a00a531d77e21159ad41d8ee9b47a3ad9877e40b679849317881ef50d4bd955a
BLAKE2b-256 checksum
How to use checksums
728b1dd2a5e1a22179bfbc2047816c0c26c5751fc79ee1e966eb733d2741c358
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 11, 2026.

Transparency log

Release files / gmm_divergence-0.0.1-py3-none-any.whl

Download URL gmm_divergence-0.0.1-py3-none-any.whl
Size 68.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
801ef700767e57ff0e058da614458672953e7902b171aa3f7f24900122721a40
BLAKE2b-256 checksum
How to use checksums
c0a4fe6765939605f6879ffe290b2bd7466d1dc8b4dd60895bdb6e7f2801c910
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 11, 2026.

Transparency log

Security for gmm-divergence 0.0.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

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for gmm_divergence-0.0.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 11, 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.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.0.1 This release

2 release files Full provenance

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