MMD DRO¶
- class dro.linear_model.mmd_dro.MMD_DRO(input_dim, model_type='svm', fit_intercept=True, solver='MOSEK', sampling_method='bound', kernel='rbf', kernel_gamma=None, kernel_degree=2, kernel_coef0=1.0)¶
Bases:
BaseLinearDROMMD-DRO (Maximum Mean Discrepancy - Distributionally Robust Optimization) Implementation with flexible sampling methods and model types.
Reference: <https://arxiv.org/abs/2006.06981>
Initialize MMD-DRO with kernel-based ambiguity set.
- Parameters:
input_dim (int) – Dimension of input features. Must match training data.
model_type (str) –
Base model type. Supported:
'svm': Support Vector Machine (hinge loss)'logistic': Logistic Regression (log loss)'ols': Ordinary Least Squares (L2 loss)'lad': Least Absolute Deviation (L1 loss)
sampling_method (str) –
Supported:
'bound''hull'
kernel (str) – Kernel defining the MMD ambiguity set. Supported values are
'rbf'(default),'laplacian','polynomial'(or'poly'), and'linear'.kernel_gamma (float or None) – Positive kernel scale for RBF, Laplacian, and polynomial kernels. If
None, RBF and Laplacian use a robust median-distance heuristic, while polynomial uses1 / (input_dim + 1).kernel_degree (int) – Positive integer degree of the polynomial kernel. Defaults to 2.
kernel_coef0 (float) – Non-negative independent term in the polynomial kernel. Defaults to 1.0.
fit_intercept (bool)
solver (str)
- Raises:
If model_type not in supported list
If input_dim ≤ 0
If sampling_method is invalid
If kernel or its hyperparameters are invalid
- Example:
>>> model = MMD_DRO(input_dim=128, model_type='svm', kernel='rbf') >>> model.sampling_method = 'hull' >>> model.eta = 0.5
- update_kernel(config)¶
Update the MMD kernel using the package’s kernel-update convention.
metricis accepted as an alias forkernel;degreeandcoef0are accepted as aliases for theirkernel_counterparts.
- update(config)¶
Update MMD-DRO model configuration.
- Parameters:
config (Dict[str, Any]) –
Configuration dictionary containing optional keys:
eta(float):MMD radius controlling distributional robustness. Must satisfy \(\eta > 0\). Defaults to current value.
sampling_method(str):Ambiguity set sampling strategy. Valid options:
'bound': Sample on MMD ball boundary'hull': Sample within convex hull
n_certify_ratio(float):Ratio of certification samples to training data size. Must satisfy \(0 < ext{ratio} \leq 1\). Defaults to current ratio.
kernel(str):MMD kernel. One of
'rbf','laplacian','polynomial'/'poly', or'linear'.
kernel_gamma(float or None):Positive kernel scale.
Noneselects the kernel-specific data-driven default.
kernel_degree(int):Positive polynomial degree. Defaults to 2.
kernel_coef0(float):Non-negative polynomial offset. Defaults to 1.0.
- Raises:
If
etais non-positiveIf
sampling_methodnot in {‘bound’, ‘hull’}If
n_certify_ratio∉ (0, 1]If config contains unrecognized keys
- Return type:
- Example:
>>> model = MMD_DRO(input_dim=10, model_type='svm') >>> model.update({ ... 'eta': 0.5, ... 'sampling_method': 'hull', ... 'kernel': 'polynomial', ... 'kernel_degree': 2 ... })
- predict(X)¶
Predict with the linear model;
kernelonly defines the MMD set.
- load(config)¶
Load linear MMD-DRO parameters independently of the MMD kernel.
- evaluate(X, y, fast=True)¶
Evaluate the linear predictor independently of the MMD kernel.