Skip to content

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 automatically with .to(device)/.cuda() and is included in state_dict(), consistent with the rest of optora staying GPU-first. Call an instance directly (divergence(p, q)); 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, a nonnegative tensor that sums to one along its last dimension.

required
q Tensor

Reference distribution with the same shape as p.

required

Returns:

Type Description
Tensor

A scalar tensor holding the divergence value. Implementations

Tensor

must return zero when p equals q and a nonnegative value

Tensor

otherwise.