optora.dro.wasserstein_dro¶
Wasserstein-distance-constrained ambiguity set (Wasserstein-DRO).
WassersteinAmbiguitySet
¶
Bases: AmbiguitySet
Wasserstein-distance-constrained ambiguity set for Wasserstein-DRO.
Bounds every candidate distribution q, sharing nominal's finite
support with pairwise ground cost cost, by the optimal-transport cost
\(W_c(q, \mathrm{nominal}) \le \mathrm{radius}\) of moving nominal to
q under cost. For a metric cost this is the type-1 Wasserstein
distance. The worst-case expected loss over this set admits an exact
strong-duality reformulation (Mohajerin Esfahani and Kuhn 2018;
Blanchet and Murthy 2019; Gao and Kleywegt 2022), which on a finite
shared support reads
This follows from LP duality on the transportation polytope. The primal is
(the column marginal, which defines the candidate q, is left free).
Dualizing the budget constraint with multiplier \(\gamma \ge 0\) and the
row constraints with free multipliers, and maximizing out \(\pi\)
pointwise, yields the one-dimensional convex dual above.
This dual is not handed to a first-order solver, as
optora.dro.PhiAmbiguitySet does when it is given a dual_solver. It
is a nonnegative combination of maxima of affine functions of the
scalar \(\gamma\), hence convex and piecewise linear. Its derivative
is piecewise constant and jumps at the minimizer, so a fixed-step
gradient method oscillates around the kink and never satisfies a
gradient-norm stopping test. The derivative is, however,
nondecreasing,
where \(j^\star(i, \gamma)\) is the maximizing column of row \(i\), so the minimizer is located by bisecting that derivative's sign change. The search starts from the exact bracket \([0, \Gamma]\), where
with \(j_0(i)\) the highest-loss column attaining \(m_i\). Beyond \(\Gamma\)
every row is maximized at a cheapest column, the derivative is frozen
at \(\mathrm{radius} - \sum_i \mathrm{nominal}_i m_i \ge 0\), and the
minimizer cannot lie further right. Bisection therefore reaches the
dual optimum to working precision in a fixed, dtype-determined number
of steps, with no step size, iteration budget, or tolerance to tune.
optora.dro.TotalVariationAmbiguitySet likewise solves its inner
problem exactly with nothing to tune. The bracket also removes the
need to reparameterize \(\gamma\). The constraint \(\gamma \ge 0\) is the
left end of the bracket, and the optimum is attained at \(\gamma = 0\)
once radius is large enough to move all nominal mass onto the single
highest-loss support point.
The bracket assumes the ambiguity set is nonempty, that is \(\mathrm{radius} \ge \sum_i \mathrm{nominal}_i m_i\), the smallest transport cost at which any candidate distribution can be reached. That holds automatically for a ground cost with a zero diagonal, the standard choice, for which \(m_i = 0\).
A zero radius is solved by the same bisection and is not short-circuited to the nominal expectation. The ball \(W_c(q, \mathrm{nominal}) \le 0\) reduces to \(\{\mathrm{nominal}\}\) only for a metric cost, with \(\mathrm{cost}_{ij} > 0\) for \(i \ne j\). A pseudometric cost, such as one with duplicated support points, moves mass between zero-cost pairs for free, so the zero-radius worst case is \(\sum_i \mathrm{nominal}_i \max_{j:\, \mathrm{cost}_{ij} = m_i} \mathrm{loss}_j\), which the bisection recovers and the nominal expectation underestimates.
Because \(\gamma^\star\) is a kink, the worst-case expectation is then
read off the primal solution rather than the dual value. At a kink
several columns tie for a row's inner maximum, and re-evaluating the
dual objective there would differentiate through that tie with
arbitrary weights, giving a transport plan that does not spend the
radius exactly and therefore a wrong gradient with respect to loss.
The two ends of the final bracket instead give the two extreme
tie-breaks. The plan optimal just below \(\gamma^\star\) overspends the
radius, the plan optimal just above it underspends, and the unique
convex combination of the two that spends exactly radius is the
worst-case distribution \(q^\star\). Complementary slackness then makes
\(\mathbb{E}_{q^\star}[\mathrm{loss}]\) equal to the dual minimum, and
since \(q^\star\) carries no autograd graph, differentiating that
expectation gives exactly the envelope-theorem gradient with respect to
loss. A minimizer at \(\gamma^\star = 0\) is the degenerate case where
both ends agree and \(q^\star\) moves all mass to the highest-loss
support point.
divergence is fixed to a SinkhornDivergence over cost, so
contains(...) checks the debiased Sinkhorn divergence as a
differentiable approximation of exact Wasserstein-ball membership.
worst_case_expectation does not depend on this approximation. It
solves the exact, unregularized dual above directly from cost, since
that dual is a one-dimensional convex problem and needs no entropic
relaxation to be tractable.
Attributes:
| Name | Type | Description |
|---|---|---|
nominal |
Tensor
|
Reference distribution the ambiguity set is centered on. |
divergence |
|
|
radius |
float | Tensor
|
Nonnegative bound on the Wasserstein distance of any
distribution inside the ambiguity set from |
cost |
Tensor
|
Square, nonnegative pairwise ground cost matrix between the
shared support points of |
cost
property
¶
Ground cost matrix, aliasing divergence.cost (no separate buffer).
__init__(nominal, cost, radius, epsilon=0.1, sinkhorn_max_iter=100, sinkhorn_tol=1e-06, eps=None, validate=False)
¶
Initialize the Wasserstein-DRO ambiguity set.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
nominal
|
Tensor
|
Reference distribution the ambiguity set is centered on, a nonnegative tensor that sums to one along its last dimension. |
required |
cost
|
Tensor
|
Square, nonnegative pairwise ground cost matrix between
the shared support points of |
required |
radius
|
float | Tensor
|
Nonnegative bound on the Wasserstein distance of any
distribution inside the ambiguity set from |
required |
epsilon
|
float
|
Positive entropic regularization strength for the
|
0.1
|
sinkhorn_max_iter
|
int
|
Maximum number of Sinkhorn scaling
iterations, passed through to |
100
|
sinkhorn_tol
|
float
|
Tolerance on the L1 marginal violation of the
Sinkhorn plan, passed through to |
1e-06
|
eps
|
float | None
|
Deprecated and ignored, as in |
None
|
validate
|
bool
|
Whether to check that |
False
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
worst_case_expectation(loss)
¶
Compute the worst-case expected loss over the Wasserstein ambiguity set.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
loss
|
Tensor
|
Per-scenario loss values of shape |
required |
Returns:
| Type | Description |
|---|---|
Tensor
|
A tensor of shape |
Tensor
|
under the worst-case distribution recovered from the dual |
Tensor
|
optimum. For a zero radius and a metric |
Tensor
|
|
Tensor
|
or infinite entry is |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
contains(candidate)
¶
Check whether a candidate distribution lies inside the ambiguity set.
The answer is returned as a boolean tensor on candidate's device
rather than as a Python bool, so membership can be used as a mask
or composed with further tensor work without forcing a
device-to-host synchronization. Call bool(...) on the result only
where a host-side branch is genuinely needed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
candidate
|
Tensor
|
Candidate distribution with the same shape as
|
required |
Returns:
| Type | Description |
|---|---|
Tensor
|
A boolean tensor that is |
Tensor
|
|