skwdro.operations_research package
Module contents
- class skwdro.operations_research.NewsVendor(rho: float = 0.01, k: float = 5, u: float = 7, cost: str = 't-NC-1-2', l2_reg: float = 0.0, solver_reg: float = 0.01, n_zeta_samples: int = 10, solver: str = 'entropic', random_state: int = 0, opt_cond: ~skwdro.solvers.optim_cond.OptCondTorch | None = <skwdro.solvers.optim_cond.OptCondTorch object>)[source]
Bases:
BaseEstimatorA NewsVendor Wasserstein Distributionally Robust Estimator.
The cost function is XXX Uncertainty is XXX
- Parameters:
- rhofloat, default=1e-2
Robustness radius
- kfloat, default=5
Buying cost
- ufloat, default=7
Selling cost
- cost: str, default=”n-NC-1-2”
Tiret-separated code to define the transport cost: “<engine>-<cost id>-<k-norm type>-<power>” for

- solver: str, default=’entropic’
Solver to be used: ‘entropic’, ‘entropic_torch’ (_pre or _post) or ‘dedicated’
- n_zeta_samples: int, default=10
number of adversarial samples to draw
- opt_cond: Optional[OptCondTorch]
optimality condition, see
OptCondTorch
- Attributes:
- coef_float
parameter vector (
in the cost function formula)
Examples
>>> from skwdro.operations_research import NewsVendor >>> import numpy as np >>> X = np.random.exponential(scale=2.0,size=(20,1)) >>> estimator = NewsVendor() >>> estimator.fit(X) NewsVendor()
- eval(X)[source]
Evaluates the loss with the theta obtained from the fit function.
- Parameters:
- Xarray-like, shape (n_samples_test,m)
The testing input samples.
- class skwdro.operations_research.Portfolio(rho=0.01, eta=0.0, alpha=0.95, C=None, d=None, fit_intercept=None, cost='t-NC-1-1', solver='dedicated', solver_reg=0.001, reparam='softmax', n_zeta_samples: int = 10, seed: int = 0, opt_cond: ~skwdro.solvers.optim_cond.OptCondTorch | None = <skwdro.solvers.optim_cond.OptCondTorch object>)[source]
Bases:
BaseEstimatorA Wasserstein Distributionally Robust Mean-Risk Portfolio estimator.
Model for the portfolio optimization problem
![\mathbb{E}[ - \langle x ; \xi \rangle ] + \eta \mathrm{CVar}_\alpha[- \langle x ; \xi \rangle]](../_images/math/d4eee55498d4edfd1ee9cfa0ae825ace280ed065.png)
which amounts to using the following loss function

where
is an extra real parameter accounting for the threshold of the CVaR (see [Rockafellar and Uryasev (2000)]). The parameter
is constrained to live in the simplex (This is encoded in the constraints of the problem in [Esfahani et al. (2018)] and by an exponential reparametrization for the entropy-regularized version).- Parameters:
- rhofloat, default=1e-2
Robustness radius
- eta: float > 0, default=0
Risk-aversion parameter linked to the Conditional Value at Risk
- alpha: float in (0,1], default=0.95
Confidence level of the Conditional Value at Risk
- C(nb_constraints, nb_assets), default=None
Matrix of constraints observed by the user.
- d(nb_constraints,), default=None
Vector of constraints observed by the user.
- fit_intercept: boolean, default=None
Determines if an intercept is fit or not
- cost: str, default=”t-NC-1-1”
Tiret-separated code to define the transport cost: “<engine>-<cost id>-<k-norm type>-<power>” for

- solver: str, default=’entropic’
Solver to be used: ‘entropic’ or ‘dedicated’
- solver_reg: float, default=1.0
regularization value for the entropic solver
- reparam: str, default=”softmax”
Reparametrization method of theta for the entropic torch loss
- random_state: int, default=None
Seed used by the random number generator when using non-deterministic methods on the estimator
- Examples
- >>> from skwdro.estimators import Portfolio
- >>> import numpy as np
- >>> X = np.random.normal(size=(10,2))
- >>> estimator = Portfolio()
- >>> estimator.fit(X)
- Portfolio()
- ——–
- eval(X)[source]
Evaluates the loss with the theta obtained from the fit function.
- Parameters:
- Xarray-like, shape (n_samples_test,m)
The testing input samples.
- class skwdro.operations_research.Weber(rho: float = 0.1, kappa: float = 10.0, solver_reg: float = 0.01, sampler_reg: float = 0.01, l2_reg: float = 0.0, n_zeta_samples: int = 10, cost: str = 't-NLC-2-2', solver='entropic_torch', random_state: int = 0, opt_cond: ~skwdro.solvers.optim_cond.OptCondTorch | None = <skwdro.solvers.optim_cond.OptCondTorch object>)[source]
Bases:
BaseEstimatorA Weber Wasserstein Distributionally Robust Estimator.
The cost function is XXX Uncertainty is XXX
- Parameters:
- rhofloat, default=1e-1
Robustness radius
- kappa: float, default=10.
For the cost
- solver_reg: float, default=1e-2
regularization value for the entropic solver
- n_zeta_samples: int, default=10
number of adversarial samples to draw
- solver: str, default=’entropic_torch’
Solver to be used: ‘entropic_torch’ (only this is implemented for now)
- Attributes:
- position_float
parameter vector (
in the cost function formula)
Examples
>>> from skwdro.operations_research import Weber >>> import numpy as np >>> m = 20 >>> X = np.random.exponential(scale=2.0,size=(m,2)) >>> w = np.ones(m) >>> estimator = Weber() >>> estimator.fit(X,w) Weber()
- eval(X)[source]
Evaluates the loss with the theta obtained from the fit function.
- Parameters:
- Xarray-like, shape (n_samples_test,m)
The testing input samples.