Wasserstein DRO

class dro.linear_model.wasserstein_dro.WassersteinDRO(input_dim, model_type='svm', fit_intercept=True, solver='CLARABEL', kernel='linear')

Bases: BaseLinearDRO

Wasserstein 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:

[1] OLS: <https://www.cambridge.org/core/journals/journal-of-applied-probability/article/robust-wasserstein-profile-inference-and-applications-to-machine-learning/4024D05DE4681E67334E45D039295527>

[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 False for 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:

ValueError –

  • 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_matrix after initialization requires calling update()

update(config)

Update Wasserstein-DRO model parameters dynamically.

Parameters:

config (dict[str, Any]) –

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:
  • ValueError –

    • If cost_matrix is not positive definite

    • If eps < 0

    • If p < 1 and p ≠ ‘inf’

    • If kappa < 0 and kappa ≠ ‘inf’

  • TypeError –

    • If cost_matrix is not numpy array

    • If numeric parameters are not float/int

Return type:

None

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 is n_features for a linear kernel, n_samples for a full nonlinear kernel, and n_components for 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/+1 labels 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, and gamma_decay. Omit this dictionary for OLS.

Return type:

Dict[str, Any]

Returns:

The atoms and weights together with source_index, expected_loss, target_objective, optimality_gap, transport_cost, gamma_used, and certified metadata.

Note

For OLS, target_objective is the robust expected squared loss and therefore equals robust_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: BaseLinearDRO

Robust 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:

ValueError –

  • If input_dim < 1

  • If invalid solver selected

Initialization Defaults:
  1. Cost matrix initialized as identity \(I_d\)

  2. Target ratio :math:` au = 1/0.8` (20% performance margin)

  3. 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.

Parameters:

config (dict) – The model configuration

Return type:

None

fit(X, y)

Fit model to data by solving an optimization problem.

Parameters:
Return type:

Dict[str, Any]

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)