optora.dro.kl_dro¶
KL-divergence-constrained ambiguity set (KL-DRO).
KLAmbiguitySet
¶
Bases: TiltedAmbiguitySet
KL-divergence-constrained ambiguity set for KL-DRO.
Bounds every candidate distribution q by
\(D_{\mathrm{KL}}(q \,\|\, \mathrm{nominal}) \le \mathrm{radius}\). The
KKT conditions of
make the maximizer an exponential (Gibbs) tilt of the nominal (Hu and Hong 2013; Ben-Tal et al. 2013),
whose divergence \(D_{\mathrm{KL}}(q_\beta \,\|\, \mathrm{nominal})\) rises monotonically in \(\beta\) from \(0\) to \(-\log P^\star\), the divergence of the nominal restricted to the highest-loss scenarios, where \(P^\star\) is the nominal mass those scenarios carry. The radius constraint is therefore tight at the optimum below that threshold and slack at or above it, and either way the tilt is pinned by one monotone scalar root solve rather than by an unconstrained minimization of the convex dual
See optora.core.dro_base.TiltedAmbiguitySet for the bracketed
bisection that runs the root solve, and docs/formulations.md for the
equivalence between the two. Unlike the Wasserstein and Sinkhorn
sets, this formulation needs no ground cost and no optimal-transport
solve.
Attributes:
| Name | Type | Description |
|---|---|---|
nominal |
Tensor
|
Reference distribution the ambiguity set is centered on. |
divergence |
|
|
radius |
float | Tensor
|
Nonnegative bound on the KL divergence of any distribution
inside the ambiguity set from |
eps |
Small positive constant passed through to the underlying
|
|
log_nominal |
Tensor
|
Elementwise logarithm of |
__init__(nominal, radius, eps=1e-12, validate=False)
¶
Initialize the KL-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 |
radius
|
float | Tensor
|
Nonnegative bound on the KL divergence of any
distribution inside the ambiguity set from |
required |
eps
|
float
|
Small positive constant passed through to the underlying
|
1e-12
|
validate
|
bool
|
Whether to check that |
False
|
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
|
|
worst_case_expectation(loss)
¶
Compute the worst-case expected loss at the tilt pinned by radius.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
loss
|
Tensor
|
Per-scenario loss values of shape |
required |
Returns:
| Type | Description |
|---|---|
Tensor
|
A tensor of shape |
Tensor
|
When |
Tensor
|
the start of the tilt path ( |
Tensor
|
|
Tensor
|
expectation of |
Tensor
|
the search returned, which equals the largest reachable loss |
Tensor
|
once the radius saturates the set. |
Tensor
|
The expectation is accumulated as a correction to |
Tensor
|
rather than directly. Every term of |
Tensor
|
|
Tensor
|
never round to above |
Tensor
|
spread around a large offset keeps the precision of its spread |
Tensor
|
instead of losing it to the offset. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |