HellingerSurrogateLoss#

class mlquantify.losses.HellingerSurrogateLoss(normalize=True)[source]#

Optimization surrogate for the squared Hellinger distance.

Minimizing \(-\sum_i \sqrt{p_i \cdot q_i}\) is equivalent to minimizing the squared Hellinger distance \(H^2(p,q) = 1 - \sum_i \sqrt{p_i q_i}\) and is numerically better behaved for gradient-free solvers.

Parameters:
normalizebool, default=True

If True, both mixture and target are normalized to valid probability vectors before the surrogate is computed.

Attributes:
normalizebool

Whether inputs are normalized before computing the surrogate.

Examples

>>> from mlquantify.losses import get_loss
>>> loss = get_loss("hellinger_surrogate")
>>> loss([0.4, 0.6], [0.5, 0.5])
-0.9899...
__call__(mixture, target, M=None)[source]#

Compute the Hellinger surrogate loss.

Parameters:
mixturearray-like of shape (n_classes,)

Estimated prevalence vector.

targetarray-like of shape (n_components,)

Target representation vector.

Marray-like of shape (n_components, n_classes) or None, default=None

Optional mixing matrix applied as M @ mixture before computing the surrogate.

Returns:
lossfloat

Negative sum of geometric means; lower (more negative) is better.

Examples

>>> from mlquantify.losses import get_loss
>>> loss = get_loss("hd_surrogate")
>>> round(loss([0.3, 0.7], [0.5, 0.5]), 4)
-0.9747