Divergence API¶
Top-level divergence helpers are documented under Top-level API. This
page documents estimator configuration classes from gmm_divergence.divergence.
gmm_divergence.divergence
¶
Public divergence API.
estimate_divergence
¶
estimate_divergence(
p: GaussianLike, q: GaussianLike, /, *, divergence: DivergenceSpec = "kl"
) -> DivergenceResult
Estimate a supported divergence between two Gaussian-family distributions.
This is the general divergence dispatch API. It currently routes to the already-supported KL, symmetric KL, and Jensen-Shannon helpers; it does not introduce new divergence estimators.
Parameters:
-
p(Gaussian or GaussianMixture) –The two Gaussian-family distributions to compare.
-
q(Gaussian or GaussianMixture) –The two Gaussian-family distributions to compare.
-
divergence(str or divergence configuration, default:"kl") –Divergence family to estimate. Supported string values are
"kl","symmetric_kl", and"jensen_shannon". Configuration objects such asdivergence.KLDivergence(...)can carry the KL estimation method.
Returns:
-
DivergenceResult–Result object containing the estimated divergence and metadata about the computation.
Source code in src/gmm_divergence/divergence/_api.py
KLDivergence
dataclass
¶
Configuration for the directed Kullback-Leibler divergence.
SymmetricKLDivergence
dataclass
¶
Configuration for the symmetric Kullback-Leibler divergence.
JensenShannonDivergence
dataclass
¶
Configuration for the Jensen-Shannon divergence.
MonteCarlo
dataclass
¶
Monte Carlo KL estimator configuration.
Estimates the KL divergence with samples from the reference distribution \(p\):
This is the most general estimator: it can be used whenever p can be
sampled and both p and q can evaluate log densities.
Sampling is configured explicitly with sampling.Draw(...),
sampling.Samples(...), or sampling.Stratified(...). Adaptive standard-error
control requires sampling.Draw(...) because it must draw additional
batches.
Source code in src/gmm_divergence/divergence/_options.py
Unscented
dataclass
¶
Unscented-transform KL estimator configuration.
Estimates the KL divergence by replacing random samples from \(p\) with deterministic sigma points generated from the Gaussian components of \(p\). For each component, the sigma points are chosen to capture its mean and covariance structure, then the estimator averages
over those points. This can be useful when deterministic, low-sample-count estimates are preferred over Monte Carlo sampling.
MomentMatchedGaussian
dataclass
¶
Moment-matched Gaussian KL estimator configuration.
Approximates one or both inputs with Gaussian summaries and then computes a Gaussian KL surrogate for
This is a fast heuristic rather than an exact Gaussian-mixture KL computation. It is mainly useful as a rough baseline or when a cheap approximation is preferable to a sampled estimate.
The "moment_matching" strategy replaces each Gaussian mixture by a single
Gaussian with the same mean and covariance, then computes the closed-form
Gaussian KL divergence between those summaries. This preserves global first
and second moments but discards multimodality.
The "nearest" strategy computes pairwise closed-form KL divergences
between Gaussian components and returns the smallest component-level value.
This captures the closest local match between the mixtures but ignores
mixture weights and the full mixture shape.
approximation
class-attribute
instance-attribute
¶
Gaussian approximation strategy to use.
ClosedForm
dataclass
¶
Closed-form Gaussian KL configuration.
Computes the exact KL divergence between two Gaussian distributions:
This method is only valid when both inputs are single Gaussian distributions.