Mathematical formulations and design¶
This page collects the mathematical background and the design rationale of
the distributionally robust optimization (DRO) core in optora. It states
the problem optora solves, the convex duals behind each ambiguity set,
and the design principles the public API follows. The root README.md is
kept short and code-first on purpose, so the derivations live here. The
Tutorials walk through the runnable scripts under
tutorials/ in the repository, which exercise this math end to end with
plots, and the Examples show each component on its
own in a short script. The
paper reproductions rerun published
experiments with the chi-square, total-variation and Wasserstein sets.
Every figure on this page is rendered from the library when the site is
built.
Why distributionally robust optimization¶
Empirical risk minimization (ERM) minimizes the average loss over the training data, which assumes that the empirical distribution is a faithful picture of the distribution we care about. That assumption often fails. The sample may be small, the population may shift after the data are collected, or an adversary may perturb the inputs. DRO replaces the expectation under the nominal distribution by the largest expectation over a neighbourhood of it,
The neighbourhood, called the ambiguity set, contains every candidate distribution \(q\) whose divergence \(D\) from the nominal (reference) distribution is at most a chosen radius,
The architecture of Optora follows this formula directly. A Divergence is
\(D\), an AmbiguitySet bundles a Divergence with a nominal distribution
and a radius, and a Solver carries out the numerical work, either
finding the worst case or, one level up, solving the full minimax problem
over the decision and the distribution.
The shape of the neighbourhood is the main modelling decision. On a three-scenario simplex, each ambiguity set in Optora is a different region around the same nominal distribution, and each sends the adversary to a different worst case for the same loss.
Core abstractions¶
| Contract | Location | Responsibility |
|---|---|---|
Divergence |
optora.core.divergence_base |
Callable forward(p, q) -> Tensor that computes a nonnegative discrepancy between two distributions and vanishes at its centre. The centre is p == q for every divergence except EntropicTransportDivergence, whose centre is the kernel-smoothed reference. |
AmbiguitySet |
optora.core.dro_base |
Holds a nominal distribution, a Divergence, and a radius, and requires subclasses to implement worst_case_expectation(loss) -> Tensor. |
Solver[ProblemT, ResultT] |
optora.core.solver_base |
Generic numerical method with a single solve(problem) -> result method. Each problem class, such as unconstrained minimization, has its own problem and result dataclasses instead of one signature shared by every algorithm. |
The pieces compose in one direction. A divergence gives an ambiguity set
its geometry. The ambiguity set turns a per-scenario loss into a worst-case
expectation, which a solver, a torch.optim optimizer or MinimaxSolver
then minimizes over the decision.
flowchart LR
D["Divergence<br/><small>KL, φ, χ², TV, max,<br/>Sinkhorn, MMD</small>"] --> A
N["nominal, radius"] --> A
A["AmbiguitySet<br/><small>worst_case_expectation(loss)</small>"] --> V["worst-case expected loss<br/><small>differentiable in loss,<br/>nominal and radius</small>"]
L["loss_fn(x)"] --> A
V --> M["MinimaxSolver<br/><small>outer Solver over x</small>"]
V --> T["nn.Module + torch.optim<br/><small>training loop</small>"]
C["calibration<br/><small>confidence, n → radius</small>"] -.-> N
B["minibatch estimators<br/><small>MLMC, stochastic dual</small>"] -.-> V
Formulations implemented today¶
Every ambiguity set below reduces the inner supremum over candidate distributions \(q\) to a tractable problem, namely a scalar search along a maximizer of known shape, a closed form, or, for MMD, a second-order cone program. None of them searches the full space of candidate distributions. The animation below grows every ball from the nominal to its saturation radius and shows how each geometry spends the budget.
KLAmbiguitySet¶
The KL ball. The inner supremum has a classical one-dimensional convex dual (Hu and Hong, 2013; Ben-Tal et al., 2013).
Optora evaluates it from the primal side instead. The KKT conditions of the primal problem make the maximizer an exponential (Gibbs) tilt of the nominal,
so the problem reduces to choosing one scalar. A float radius of zero
returns \(\mathbb{E}_{\mathrm{nominal}}[\mathrm{loss}]\) exactly and skips the
search.
Tilt-solved sets and the bracketed scalar search¶
KLAmbiguitySet and ChiSquareAmbiguitySet share one mechanism,
implemented once in optora.core.dro_base.TiltedAmbiguitySet, which the
exact path of PhiAmbiguitySet and SinkhornAmbiguitySet below also use.
For both sets the maximizer has a known shape, a one-parameter tilt \(q_t\)
of the nominal that starts at the nominal itself. Along the tilt, the
divergence \(D(q_t \,\|\, \mathrm{nominal})\) increases monotonically up to
the divergence of the distribution concentrated on the highest-loss
scenarios. Choosing the tilt is therefore a monotone scalar root-finding
problem, which optora solves by bisection. The chi-square root also has a
closed form, given with ChiSquareAmbiguitySet further down, which that
set uses in place of the bisection. The bracket, saturation and gradients
described here apply to it unchanged.
The bracket is valid by construction. The tilt is parameterized by \(t \in [0,1)\) and mapped to the unbounded natural parameter by \(t \mapsto t/(1-t)\). The interval \([0, 1]\) then brackets the solution for every loss and every radius. Direct minimization of the dual has no such guarantee, because its minimizer diverges, \(\eta \to \infty\), as the radius vanishes, and does not exist once the radius saturates the set.
The result is feasible. Each step keeps the largest tilt that satisfied
the radius constraint, so the reported value is
\(\mathbb{E}_{q^\star}[\mathrm{loss}]\) at a distribution inside the set. It
never exceeds \(\max\ell\) and is never nan, whatever the support size or
the loss scale.
The number of steps is fixed and the solve never synchronizes. The resolution is read off the dtype (52 bits in float64, 23 in float32), so a solve is a fixed sequence of device-side kernels with no convergence flag to read back and no tolerance to tune. A small problem, whose cost is dominated by kernel launches rather than arithmetic, tests up to 15 evenly spaced tilts per step in one batched call and so needs a quarter of the steps. A large problem bisects. Size here means the bytes of one tilt evaluation, so a Sinkhorn set, whose tilt reweights all \(n\) kernel rows, counts \(n^2\) entries per batch element rather than \(n\). A GPU kernel launch costs more than a CPU call relative to the work it can absorb, so the budget is 2 MiB on a GPU and 128 KiB on the CPU. On an RTX 3050, a batch of 400 float32 losses over 100 scenarios then takes 8 steps of 7 tilts instead of 23 bisection steps.
Saturation needs no special case. Once the radius reaches \(-\log P^\star\) (KL) or \(1/P^\star - 1\) (chi-square), where \(P^\star\) is the nominal mass on the highest-loss scenarios, every tilt is feasible and the bisection drives \(t\) to the top of the bracket. The tilted distribution \(q_t\) is then the nominal restricted to those scenarios and renormalized, the value is exactly \(\max\ell\), and the gradient is that distribution.
Here and below, \(\max\ell\) and \(\min\ell\) range over the support of the nominal only. Both divergences are infinite off the support, and every tilt reweights the nominal, so a scenario with zero nominal mass is unreachable however large its loss or the radius.
The tilt is computed on a standardized loss. The set of candidate
distributions does not depend on loss, so for \(a > 0\)
An affine rescaling of the loss therefore leaves the maximizer unchanged. Optora computes the tilt from the standardized shortfall \((\max\ell - \ell)/(\max\ell - \min\ell) \in [0, 1]\) with a detached shift and scale, and minimizing the expected shortfall is the same as maximizing the expected loss. Values and gradients are unchanged, and only the numerical conditioning improves.
Gradients come from Danskin's theorem, not from the bisection
\(\sup_{q \in \mathcal{U}} \mathbb{E}_q[\ell]\) is the support function
of \(\mathcal{U}\) evaluated at \(\ell\), so its gradient is the maximizer
\(q^\star\), and a subgradient where the maximizer is not unique. Optora
reports the value as sum(q*.detach() * loss), so the backward pass is
exact and the bisection never enters the autograd graph.
PhiAmbiguitySet, ChiSquareAmbiguitySet, TotalVariationAmbiguitySet, CVaRAmbiguitySet¶
This section covers the general phi-divergence ball and three named
instances. PhiAmbiguitySet generalizes the KL dual above to any
phi-divergence (Ben-Tal et al., 2013; Duchi, Glynn, and Namkoong, 2021;
Duchi and Namkoong, 2021) by adding a second dual variable lam, which
gives
where \(\phi^*\) is the convex conjugate of \(\phi\). By the KKT conditions,
the maximizer is
\(q_i = \mathrm{nominal}_i \, (\phi^*)'(\mu - a\,\mathrm{gap}_i)\), where
\(\mathrm{gap}\) is the standardized shortfall defined above, \(a = 1/\eta\) is
a rate, and \(\mu\) is the level that normalizes \(q\). By Fenchel's equality,
the optimality condition of the dual in \(\eta\) reads
\(\mathbb{E}_{\mathrm{nominal}}[\phi(q / \mathrm{nominal})] =
\mathrm{radius}\). Without a dual_solver, PhiAmbiguitySet therefore
solves any generator exactly with the same bracketed bisection as the KL
and chi-square sets, with an outer search over the rate and an inner search
over the level. It needs only phi and phi_conjugate, which it
differentiates with autograd, and phi_conjugate must be finite on the
whole real line. The tests check the Cressie-Read family, for example,
against an independent minimization of the dual. The nested search is
slower than the dedicated sets, so prefer those for their own generators.
Passing a dual_solver minimizes the dual above instead, with that
solver's accuracy.
optora.dro.kl_conjugate, chi_square_conjugate
and cvar_conjugate.With a dual_solver, step sizes are relative to a unit-spread loss
The dual is minimized on the standardized loss, so a step size means the same thing at every loss scale. It is of order one (up to about 2) for a KL-like generator and smaller for a stiffer one, at most about 0.3 for chi-square. A step size tuned on a raw loss with spread \(S\) should be multiplied by roughly \(S\).
ChiSquareAmbiguitySet does not use that dual. Its KKT conditions give a
linear tilt truncated at a cut level \(c\),
When no scenario is truncated, this reproduces the familiar closed form \(\mathbb{E}_{\mathrm{nominal}}[\ell] + \sqrt{\mathrm{radius} \cdot \mathrm{Var}_{\mathrm{nominal}}(\ell)}\) (Duchi and Namkoong, 2021). Once scenarios are truncated to \(q_i = 0\), the same formula holds on the scenarios that keep positive weight, with the mass left out entering the radius. So the cut level needs no bisection. Optora sorts the scenarios by loss, finds the truncated ones by comparing the divergence at each breakpoint \(c = \ell_{(j)}\) with the radius, and then solves a quadratic for \(c\). The breakpoint divergences come from cumulative sums of nonnegative terms, so they keep full precision, and the whole solve is one sort plus a fixed number of vectorized operations. On a GPU this costs a small fraction of the 52 float64 bisection steps it replaces, which are bound by kernel launches rather than arithmetic. The root is exact up to rounding, so the divergence of the maximizer equals the radius to the precision of evaluating it, instead of being tested feasible step by step.
The conjugate of the total-variation generator is infinite above a finite
threshold, so neither path of PhiAmbiguitySet applies.
TotalVariationAmbiguitySet instead computes the worst case from the
closed-form combinatorial solution of the underlying linear program
(Ben-Tal et al., 2013). It sorts the scenarios by loss and moves
probability mass from the lowest-loss scenarios onto the single
highest-loss scenario until the moved mass reaches the radius.
Conditional value-at-risk at tail probability \(\alpha \in (0, 1]\), the mean of the upper \(\alpha\)-tail of the loss, is the worst case over distributions whose likelihood ratio to the nominal is at most \(1/\alpha\) (Artzner et al., 1999; Rockafellar and Uryasev, 2002).
This set is the phi-divergence ball of the indicator generator
\(\phi_\alpha(t) = 0\) on \([0, 1/\alpha]\) and \(+\infty\) elsewhere, whose
conjugate \(\phi_\alpha^*(s) = (s)_+/\alpha\) turns the general dual above
into the Rockafellar-Uryasev formula on the right. CVaRAmbiguitySet
takes alpha directly and represents the same set as the max-divergence
ball
so its radius is \(\log(1/\alpha)\) and its divergence is
MaxDivergence. Like total variation, it does not use the dual. It sorts
the scenarios by loss, gives each its full nominal mass from the top until
the cumulative mass reaches \(\alpha\), gives the boundary scenario the
remainder, and divides by \(\alpha\). At \(\alpha = 1\) the value is the
nominal expectation. The set also accepts \(\alpha = 0\), the limit in which
the value is the maximum loss on the support of the nominal.
PenalizedChiSquareDRO¶
Levy, Carmon, Duchi, and Sidford (2020, Eq. 4) also study a penalized form of chi-square DRO, in which the divergence is subtracted from the objective instead of being bounded,
This value is not a worst case over a fixed ball, so
PenalizedChiSquareDRO is a module of its own and not an AmbiguitySet.
Calling it returns \(V\), and penalty is \(\lambda\). Levy et al. write the
divergence with the generator \(\frac{1}{2}(t - 1)^2\), which is half of
ChiSquareDivergence, so their penalty \(\lambda_{\mathrm{Levy}}\) is
penalty \(= \lambda_{\mathrm{Levy}} / 2\) here.
The penalized value is the Lagrangian relaxation of the constrained one. For a radius \(\rho > 0\), Lagrangian duality gives \(\sup_{q:\, D_{\chi^2}(q \,\|\, p) \le \rho} \mathbb{E}_q[\ell] = \inf_{\lambda \ge 0} \lambda \rho + V_\lambda(\ell)\) (Boyd and Vandenberghe, 2004, Section 5.2). The penalized problem itself has the one-dimensional dual (Ben-Tal and Teboulle, 2007)
whose minimizer \(c^\star\) solves
\(\mathbb{E}_{\mathrm{nominal}}[(\mathrm{loss} - c^\star)_+] = 2\lambda\). The
maximizer is the same truncated linear tilt as for ChiSquareAmbiguitySet,
When no scenario is truncated, \(c^\star = \mathbb{E}_{\mathrm{nominal}}[\ell] - 2\lambda\), and substituting it into the dual gives
Gotoh, Kim, and Lim (2018) show that a smooth phi-divergence penalty acts like a variance penalty to leading order. For chi-square the identity is exact as long as no scenario is truncated, and minimizing \(\lambda \rho + \mathbb{E}[\ell] + \mathrm{Var}(\ell) / (4\lambda)\) over \(\lambda\) recovers the constrained value \(\mathbb{E}[\ell] + \sqrt{\rho \, \mathrm{Var}(\ell)}\) of the previous section. As \(\lambda \to \infty\) the value tends to the nominal mean, and as \(\lambda \to 0\) it tends to the largest loss on the support of the nominal.
The normalization condition is piecewise linear in the cut level, so the
solve sorts the scenarios by loss and reads the truncated ones off
cumulative sums of nonnegative terms, as for the constrained set. With that
active set held fixed, the cut level is an explicit function of the loss,
the nominal, and \(\lambda\), and the value is evaluated as the dual objective
in ordinary differentiable operations. Autograd then returns exact
derivatives of every order. The first derivatives are the maximizer
\(q^\star\) in the loss (Danskin's theorem), and \(-D_{\chi^2}(q^\star \,\|\,
\mathrm{nominal})\) in \(\lambda\) (the envelope theorem). Nothing in the
forward or backward pass reads a value back to the host, so both can be
captured in a CUDA graph. On minibatches the plug-in value is biased in the
same way as a plug-in worst case, and MultilevelMonteCarloEstimator
accepts a factory that returns this module, which is how Levy et al.
estimate its gradient.
WassersteinAmbiguitySet¶
The Wasserstein ball, for candidates on the same finite support as the nominal distribution with a given pairwise ground cost. This case also has a one-dimensional dual (Mohajerin Esfahani and Kuhn, 2018; Blanchet and Murthy, 2019; Gao and Kleywegt, 2022).
The optimal \(\gamma\) can lie exactly on the boundary \(\gamma = 0\), which
happens once the radius is large enough to move all the mass to the
highest-loss scenario. The dual is convex but piecewise linear in
\(\gamma\), so a fixed-step gradient method oscillates around its kink and
does not converge. Its derivative is monotone, so WassersteinAmbiguitySet
takes no dual solver. It bisects the sign change of that derivative inside
a closed-form bracket and reaches the exact minimizer in a fixed number of
steps set by the dtype. It uses a SinkhornDivergence internally only as
an approximate contains(...) membership check. The worst-case
expectation itself is solved exactly, without the entropic approximation.
The ground cost may carry leading batch dimensions, with shape
(..., n, n). Each batch element then has its own cost matrix, so
datasets with different support points are solved in one call. The
example Batched ground costs
checks this against one set per dataset.
radius.grad
returns.transport_map and squared_distance¶
Added in 0.5.0
Both functions need Optora 0.5.0 or later. Before 0.5.0 is on PyPI, install Optora from the repository to use them.
WassersteinAmbiguitySet moves probability mass between the support
points of the nominal distribution. Sinha, Namkoong and Duchi (2018)
instead let the adversary move each input \(z_0\) to any point \(z\) of the
input space at the cost \(c(z, z_0) = \lVert z - z_0 \rVert_2^2\), and they
penalize this cost rather than bound it. Their robust surrogate (Eq. 2b)
is
and by their Proposition 1 the worst case over a Wasserstein ball of radius \(\rho\) is
Training on \(\mathbb{E}_{P_0}[\phi_\gamma]\) at a fixed \(\gamma\) is the
Lagrangian relaxation of the constrained problem, the same relation that
links PenalizedChiSquareDRO to ChiSquareAmbiguitySet. The inner
supremum is over the inputs of a model, not over the weights of a finite
set of scenarios, so it is not an AmbiguitySet. It is the function
transport_map(loss, inputs, penalty) in optora.dro, which takes a
closure from a batch of inputs to the loss of each example.
If \(z \mapsto \ell(\theta; z)\) has \(L\)-Lipschitz gradients, the inner
objective is \((2\gamma - L)\)-strongly concave for \(\gamma > L / 2\), so it
has a unique maximizer \(T_\gamma(\theta; z_0)\), the transport map of
their Eq. (9). transport_map approximates it by the ascent of the
authors' wrm code. The objective is divided by \(2\gamma\),
for a fixed number of steps \(t = 1, \dots, T\), with \(T = 16\) by default.
The first step moves by \(\nabla_z \ell(\theta; z_0) / (2\gamma)\), which is
already the maximizer when the loss is linear in \(z\). All examples are
solved together by differentiating the sum of their losses, so the loss
of an example may depend only on its own input. By Danskin's theorem
(their Lemma 1), \(\nabla_\theta \phi_\gamma(\theta; z_0) =
\nabla_\theta \ell(\theta; T_\gamma(\theta; z_0))\), so the map is
returned detached and the model is trained on the loss at the moved
inputs. The trip count is fixed and nothing is read back to the host, so
the ascent can be captured in a CUDA graph, and inside a torch.func
transform it differentiates with torch.func.grad.
squared_distance(points, inputs) returns the cost of each example. Its
mean over a sample is the radius
\(\hat\rho_n = \mathbb{E}_{\hat P_n} \lVert T_\gamma(\theta; Z) - Z
\rVert_2^2\) of their Eq. (14). The moved inputs form a distribution in the
empirical ball of that radius, and the dual bound at the same \(\gamma\)
equals their mean loss, so the worst case over that ball is
\(\mathbb{E}_{\hat P_n}[\ell(\theta; T_\gamma(\theta; Z))]\). For an
approximate map, the mean loss of the moved inputs is a lower bound on
this worst case. For any other radius \(\rho\), weak duality bounds the
empirical worst case by
\(\gamma \rho + \mathbb{E}_{\hat P_n}[\phi_\gamma(\theta; Z)]\), and their
Theorem 3 extends the bound to the population worst case up to a
generalization term.
SinkhornAmbiguitySet¶
Sinkhorn DRO (Wang, Gao, and Xie, 2025) replaces the Wasserstein distance with its entropic regularization, taken relative to a reference measure \(\nu\) on the support (the counting measure by default). On a finite support the Sinkhorn ball is a mixture of KL balls with one shared budget, one ball around each Gibbs kernel row \(Q_i \propto \nu\, e^{-\mathrm{cost}(i, \cdot)/\epsilon}\), which gives
Every row's maximizer is an exponential tilt of \(Q_i\) at one shared temperature, so the bracketed bisection used for KL pins it exactly.
The ball is centred on the smoothed nominal
radius is the budget in excess of the entropic bias, so a radius of
zero gives the single distribution \(P^0 = \mathrm{nominal}^\top Q\), a
kernel smoothing of the nominal rather than the nominal itself. The
worst case can put mass anywhere \(\nu\) does, including scenarios with no
nominal mass. EntropicTransportDivergence, which contains uses,
vanishes at \(P^0\). It maximizes its semi-dual by Sinkhorn scaling and,
where Sinkhorn stalls at a sharp kernel (large \(\max C/\epsilon\)),
continues with a damped Newton method. It reports the semi-dual value,
which bounds the divergence from below with an error that is second
order in the remaining marginal violation.
With a zero cost every row is \(\nu\), and the set is the KL ball of radius \(\mathrm{radius}/\epsilon\) around \(\nu\). As \(\epsilon \to 0\) the dual tends to the Wasserstein-DRO dual (Wang, Gao, and Xie, 2025). Azizian, Iutzeler, and Malick (2023) also regularize the objective. That variant returns a penalized value rather than a worst-case expectation and is not implemented.
MMDAmbiguitySet¶
MMD DRO (Staib and Jegelka, 2019; Zhu et al., 2021) bounds the maximum mean discrepancy, the distance between kernel mean embeddings, for a positive semidefinite kernel with Gram matrix \(K\) on the support. The worst case is
Like the Wasserstein ball, and unlike a \(\varphi\)-divergence ball, it contains distributions that put mass where the nominal has none, at a price set by the geometry of the kernel.
A cone program, solved exactly
The constraint \(q \ge 0\) couples every scenario through \(K\), so no
scalar bracket pins the maximizer. The closed form
\(\mathrm{loss}^\top \mathrm{nominal} + \mathrm{radius}\,
\lVert \mathrm{loss} \rVert_{K^{-1}}\) of Staib and Jegelka (2019)
drops \(q \ge 0\) and is therefore only an upper bound on the worst case.
The set solves the second-order cone program itself with a batched
primal-dual interior-point method, using Nesterov-Todd scaling and
Mehrotra's predictor-corrector steps (Nesterov and Todd, 1997;
Mehrotra, 1992), to a relative duality gap of tol (\(10^{-10}\) by
default) on the loss standardized to unit spread. A few tens of
iterations suffice for supports into the thousands, and each iteration
factors one \(n \times n\) matrix per batch element.
The gradient in loss is the maximizer, and a zero-valued term from the
implicit function theorem on the optimality conditions makes the Hessian in
loss exact. Derivatives in nominal and radius are first order and
follow from the envelope theorem, with the radius derivative given by the
multiplier of the radius constraint. The Laplacian kernel
\(e^{-\lVert x - y \rVert}\) is a good default. The Gaussian kernel is also
characteristic, but its Gram matrix on clustered points is numerically
singular, and the ball then contains, at zero discrepancy, every
distribution that differs from the nominal along the null space of \(K\).
Group DRO with group_losses and OnlineGroupDRO¶
Group DRO (Sagawa et al., 2020) places the ambiguity on the mixture of \(G\)
known groups rather than on individual samples. Let
\(\hat R_g = \frac{1}{n_g} \sum_{i:\, g_i = g} \ell_i\) be the group losses
that group_losses computes and \(p_g = n_g / n\) the group proportions. If
every group has at least one sample, then
so group DRO needs no new ambiguity set. CVaRAmbiguitySet(p, alpha=0.0)
applied to the group losses gives the worst group exactly, and
\(\alpha = 1\) gives ERM, since \(\sum_g p_g \hat R_g\) is the sample mean. A
KL or \(\chi^2\) ball around \(p\) gives a softer worst case, which reaches the
worst group at radius \(\log(1/p_{g^\star})\) or \(1/p_{g^\star} - 1\)
respectively. Through group_losses, the gradient with respect to the loss
of sample \(i\) is \(q^\star_{g_i} / n_{g_i}\), so group DRO reweights samples
uniformly within each group.
On minibatches, OnlineGroupDRO keeps \(q\) as state and updates it by
exponentiated-gradient ascent, \(q_g \propto q_g\, e^{\eta \hat\ell_g}\),
with one step per minibatch, alternating with gradient descent on the
model. This is Algorithm 1 of Sagawa et al. (2020), a stochastic mirror
descent-ascent method. On fixed group losses, its \(T\)-th iterate is the
exponential tilt \(q_0 e^{T \eta \ell} / Z\), which is the worst case of the
KL ball around \(q_0\) of matching radius. The online weights therefore
follow the KL-DRO worst-case path toward the worst group.
MinimaxSolver¶
MinimaxSolver combines any of the ambiguity sets above with an outer
solver, such as GradientDescent, to solve the full DRO problem,
including the minimization over the decision variable,
Each ambiguity set above returns a worst-case expectation whose gradient
with respect to loss is the maximizer \(q^\star\), so MinimaxSolver only
has to minimize the ordinary scalar objective
x -> ambiguity_set.worst_case_expectation(loss_fn(x)). By the envelope
theorem, the gradient with respect to x is correct even though each set
solves its own inner problem without differentiating through the solve.
Every component above is covered by pytest tests that compare against known closed-form results, independent reference solvers and grid searches, convergence limits, and monotonicity properties. The whole package is type-checked under mypy's strict mode.
Design principles¶
- Component-oriented public API. There are no package-level
workflow dispatchers (
minimize(...),train(...)) that hide the method being studied, so researchers instantiate the exact algorithm they want. - Mathematical objects separated from numerical solvers. A divergence, an ambiguity set, and a solver are independent components, and each can be reused on its own.
- Every extension point is subclassable.
Divergence,AmbiguitySet, andSolverare abstract base classes, not a closed enumeration. Optora ships reference implementations and does not try to cover every method. - PyTorch-native and accelerator-friendly. Results keep the dtype and device of their inputs, and the numerical core avoids unnecessary host synchronizations and scalar round-trips, which keeps it suitable for GPU and batched workloads.
- Tested against known mathematics. Every solver and divergence is checked against closed-form solutions, convergence limits, or established monotonicity properties, in addition to smoke tests.
Roadmap and future horizon¶
The scope of Optora is deliberately narrow. It covers ambiguity sets, divergences, and the minimax solve that connects them, and that core is complete. Further extensions will be added when a concrete use case needs them.
- A dedicated risk-functional layer, once more than one risk measure (CVaR, entropic risk, and others) has to be built on the worst-case objective.
- Jointly learned ambiguity sets, once the current static ones (fixed
nominal, fixedradius) become limiting. - Causality-constrained DRO for sequential decision problems.
Further out, the roadmap includes stochastic and differentiable-backend solvers, optimal transport as a first-class object, and reinforcement learning under model uncertainty.