Wasserstein DRO¶
- class dro.linear_model.wasserstein_dro.WassersteinDRO(input_dim, model_type='svm', fit_intercept=True, solver='CLARABEL', kernel='linear')¶
Bases:
BaseLinearDROWasserstein Distributionally Robust Optimization (WDRO) model
This model minimizes a Wasserstein-robust loss function for both regression and classification.
The Wasserstein distance is defined as the minimum probability coupling of two distributions. For LAD regression, the ground cost is
\[d((X_1, Y_1), (X_2, Y_2)) = \|\Sigma^{1/2} (X_1 - X_2)\|_p + \kappa |Y_1 - Y_2|.\]For OLS regression, target changes are prohibited and the feature cost is quadratic:
\[\begin{split}d((X_1, Y_1), (X_2, Y_2)) = \begin{cases} \|\Sigma^{1/2} (X_1 - X_2)\|_p^2, & Y_1=Y_2,\\ +\infty, & Y_1\ne Y_2. \end{cases}\end{split}\]For binary classification, the label term is instead \(\kappa\mathbf{1}_{\{Y_1\ne Y_2\}}\), so a label flip costs exactly \(\kappa\).
where parameters are:
\(\Sigma\): symmetric positive-definite cost matrix;
\(\kappa\);
\(p\);
Reference:
[2] LAD / SVM / Logistic: <https://jmlr.org/papers/volume20/17-633/17-633.pdf>
Initialize Mahalanobis-Wasserstein DRO model.
- Parameters:
input_dim (int) – Dimension of feature space. Must satisfy :math:` ext{input_dim} geq 1`
model_type (str) –
Base model architecture. Supported:
'svm': Hinge loss (classification)'logistic': Logistic loss (classification)'ols': Least squares (regression)'lad': Least absolute deviation (regression)
fit_intercept (bool) – Whether to learn intercept term \(b\). Set to
Falsefor pre-centered data. Defaults to True.solver (str) –
Convex optimization solver. Valid options:
'CLARABEL'(open source, default)'MOSEK'(optional; requires a license)
kernel (str) – the kernel type to be used in the optimization model, default = ‘linear’
- Raises:
If input_dim < 1
If unsupported solver is selected
- Example:
>>> model = WassersteinDRO( ... input_dim=5, ... model_type='svm', ... solver='CLARABEL' ... ) >>> model.cost_matrix.shape # (5, 5)
Note
Changing
cost_matrixafter initialization requires callingupdate()
- update(config)¶
Update Wasserstein-DRO model parameters dynamically.
- Parameters:
Configuration dictionary with keys:
'cost_matrix': Mahalanobis metric matrix \(\Sigma \succ 0\)Shape: (input_dim, input_dim)
Type: numpy.ndarray
'eps': Wasserstein radius \(\epsilon \geq 0\)'p': Wasserstein order \(p \geq 1\) or'inf''kappa': Y-ambiguity radius \(\kappa \geq 0\) or'inf'. LAD requires \(\kappa > 0\) because free target transport makes the robust absolute loss unbounded. OLS requires'inf'because its reformulation keeps targets fixed.
- Raises:
If cost_matrix is not positive definite
If eps < 0
If p < 1 and p ≠ ‘inf’
If kappa < 0 and kappa ≠ ‘inf’
If cost_matrix is not numpy array
If numeric parameters are not float/int
- Return type:
- Example:
>>> model = WassersteinDRO(input_dim=3) >>> new_config = { ... 'eps': 0.5, ... 'p': 2, ... 'cost_matrix': np.diag([1, 2, 3]) ... } >>> model.update(new_config) >>> model.p # 2.0
- fit(X, y)¶
Fit the model using CVXPY to solve the WDRO problem.
- Parameters:
X (numpy.ndarray) – Training feature matrix of shape (n_samples, n_features). Must satisfy n_features == self.input_dim.
Y (numpy.ndarray) –
Target values of shape (n_samples,). Format requirements:
Classification: ±1 labels
Regression: Continuous values
y (ndarray)
- Returns:
Dictionary containing trained parameters:
theta: Weight vector. Its length isn_featuresfor a linear kernel,n_samplesfor a full nonlinear kernel, andn_componentsfor a Nyström approximation.b
- Return type:
Dict[str, Any]
.raises: WassersteinDROError: If the optimization problem fails to solve.
- worst_distribution(X, y, *, asymptotic_options=None)¶
Construct and certify a worst-case distribution.
OLS uses an exact, finite, label-preserving construction. Linear SVM, logistic, and LAD use an asymptotic construction whose numerical controls are grouped in
asymptotic_options.- Parameters:
X (
ndarray) – Training features with shape(n_samples, input_dim).y (
ndarray) – Binary-1/+1labels or continuous regression targets.asymptotic_options (
Optional[Dict[str,Any]]) – Options used only by SVM, logistic, and LAD:gamma,objective_atol,objective_rtol,feasibility_tol,max_iter, andgamma_decay. Omit this dictionary for OLS.
- Return type:
- Returns:
The atoms and weights together with
source_index,expected_loss,target_objective,optimality_gap,transport_cost,gamma_used, andcertifiedmetadata.
Note
For OLS,
target_objectiveis the robust expected squared loss and therefore equalsrobust_obj**2. For the other models, a positive-radius result is a certified finite member of an asymptotically optimal sequence.- References:
Blanchet, Kang, and Murthy (2019), Shafieezadeh-Abadeh et al. (2019), Shafiee et al. (2026).
- class dro.linear_model.wasserstein_dro.WassersteinDROsatisficing(input_dim, model_type='svm', fit_intercept=True, solver='CLARABEL', kernel='linear')¶
Bases:
BaseLinearDRORobust satisficing version of Wasserstein DRO
This model minimizes the subject to (approximated version) of the robust satisficing constraint of Wasserstein DRO. The Wasserstein Distance is defined as the minimum probability coupling of two distributions for the distance metric:
\[d((X_1, Y_1), (X_2, Y_2)) = (\|\Sigma^{1/2} (X_1 - X_2)\|_p)^{square} + \kappa |Y_1 - Y_2|,\]Reference: <https://pubsonline.informs.org/doi/10.1287/opre.2021.2238>
Initialize Robust satisficing version of Wasserstein DRO.
- Parameters:
input_dim (int) – Feature space dimension. Must satisfy \(d \geq 1\)
model_type (str) –
Base model architecture. Supported:
'svm''logistic''ols''lad'
fit_intercept (bool) – Whether to learn intercept \(b\). Disable for standardized data. Defaults to True.
solver (str) –
Convex optimization solver. Options:
'CLARABEL'(open source, default)'MOSEK'(optional; requires a license)
kernel (str) – the kernel type to be used in the optimization model, default = ‘linear’
- Raises:
If input_dim < 1
If invalid solver selected
- Initialization Defaults:
Cost matrix initialized as identity \(I_d\)
Target ratio :math:` au = 1/0.8` (20% performance margin)
Wasserstein order \(p=1\) (earth mover’s distance)
- Example:
>>> model = WassersteinDROsatisficing( ... input_dim=5, ... model_type='svm', ... solver='CLARABEL' ... ) >>> model.cost_matrix.shape # (5, 5)
- update(config)¶
Update model parameters based on configuration.
- fit(X, y)¶
Fit model to data by solving an optimization problem.
- Parameters:
X (
numpy.ndarray) – input covariatesy (
numpy.ndarray) – input labels
- Return type:
- fit_oracle(X, y, design_matrix=None)¶
Depreciated, find the optimal that given the ambiguity constraint.
- Args:
X (np.ndarray): Input feature matrix with shape (n_samples, n_features).
y (np.ndarray): Target vector with shape (n_samples,).
- Returns:
float: robust objective value
- worst_distribution(X, y)¶