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 |
required |
q
|
Tensor
|
Reference distribution of shape |
required |
Returns:
| Type | Description |
|---|---|
Tensor
|
The divergence over the broadcast batch, of shape |
Tensor
|
one value per pair of distributions. Only the last dimension is |
Tensor
|
reduced, so an unbatched |
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 |
Tensor
|
|
Tensor
|
kernel-smoothed reference, as documented there. |