Skip to content
Edit this page View source of this page

optora.core.divergence_base

Shared contract for divergences used to define DRO ambiguity sets.

Divergence

Bases: Module, ABC

Nonnegative discrepancy between two probability distributions.

Subclasses implement a specific divergence (for example Kullback-Leibler, a general phi-divergence, or an entropy-regularized Wasserstein discrepancy) that optora.dro ambiguity sets use to bound how far a candidate distribution may lie from a nominal distribution.

Inherits from torch.nn.Module (rather than a plain ABC) so that any divergence holding tensor state (for example SinkhornDivergence's ground-cost matrix) can register it as a buffer. That state then moves with .to(device)/.cuda() and is included in state_dict(). Call an instance directly, as divergence(p, q), and nn.Module.__call__ dispatches to forward.

forward(p, q) abstractmethod

Compute the divergence of p from q.

Parameters:

Name Type Description Default
p Tensor

Candidate distribution of shape (..., n), nonnegative and summing to one along its last dimension.

required
q Tensor

Reference distribution of shape (..., n), broadcasting against p.

required

Returns:

Type Description
Tensor

The divergence over the broadcast batch, of shape (...), with

Tensor

one value per pair of distributions. Only the last dimension is

Tensor

reduced, so an unbatched (n,) pair gives a scalar.

Tensor

Implementations must return a nonnegative value that vanishes

Tensor

at the divergence's centre. For every divergence except an

Tensor

entropic transport cost the centre is p == q. For

Tensor

optora.divergences.EntropicTransportDivergence it is the

Tensor

kernel-smoothed reference, as documented there.