get_loss#

mlquantify.losses.get_loss(loss='hellinger', normalize=True, **kwargs)[source]#

Instantiate a loss object from a string identifier or return a callable.

Provides a unified entry point for retrieving optimization loss objects used in distribution-matching quantifiers. If loss is already callable it is returned unchanged.

Parameters:
lossstr or callable, default=’hellinger’

Loss identifier. Accepted string values:

A callable is returned as-is.

normalizebool, default=True

Passed to distance and surrogate losses to control whether inputs are normalized to valid probability vectors before evaluation.

**kwargs

Additional keyword arguments forwarded to the chosen loss class constructor.

Returns:
loss_fnBaseLoss or callable

The configured loss object.

Raises:
ValueError

If loss is a string not matching any recognised identifier.

Examples

>>> from mlquantify.losses import get_loss
>>> loss = get_loss("hellinger")
>>> loss([0.4, 0.6], [0.5, 0.5])   
0.076...
>>> loss = get_loss("least_squares")
>>> loss([0.4, 0.6], [0.5, 0.5])
0.02