pyepo.func.regularized¶
Regularized differentiable optimization function
Classes¶
L2-Regularized Frank-Wolfe Optimizer (RFWO) -- differentiable smoothed solver. |
|
An autograd function for regularized Frank-Wolfe |
|
L2-Regularized Frank-Wolfe with Fenchel-Young loss (RFYL). |
|
An autograd function for regularized Frank-Wolfe with Fenchel-Young loss |
Module Contents¶
- class pyepo.func.regularized.regularizedFrankWolfeOpt(optmodel: pyepo.model.opt.optModel, lambd: float = 1.0, max_iter: int = 20, tol: float = 1e-06, processes: int = 1, solve_ratio: float = 1.0, dataset: pyepo.data.dataset.optDataset | None = None)¶
Bases:
pyepo.func.abcmodule.optModuleL2-Regularized Frank-Wolfe Optimizer (RFWO) – differentiable smoothed solver.
Adds an L2 regularizer \(\tfrac{\lambda}{2}\|\mathbf{w}\|_2^2\) to the linear objective and returns the regularized minimizer \(\hat{\mathbf{w}}_\lambda(\hat{\mathbf{c}}) = \arg\min_{\mathbf{w} \in \mathrm{conv}(\mathcal{S})} \hat{\mathbf{c}}^\top \mathbf{w} + \tfrac{\lambda}{2}\|\mathbf{w}\|_2^2\), which is unique, lies inside \(\mathrm{conv}(\mathcal{S})\), and varies continuously with \(\hat{\mathbf{c}}\). The program is solved by batched Frank-Wolfe iteration; the only oracle needed is the underlying linear solver (PyEPO’s standard
optModel.solve).Returns a regularized solution – not a loss. Pair with a user-defined task loss (MSE against \(\mathbf{w}^*(\mathbf{c})\) matches the imitation setting in the paper), or use
regularizedFrankWolfeFenchelYoungfor the loss-returning variant.Reference: Dalle et al. (2022) https://arxiv.org/abs/2207.13513
- lambd¶
- max_iter = 20¶
- tol = 1e-06¶
- forward(pred_cost: torch.Tensor) torch.Tensor¶
Forward pass
- compute_regularization(y: torch.Tensor) torch.Tensor¶
L2 regularizer Omega(y) = (lambd / 2) ||y||^2 per instance
- class pyepo.func.regularized.regularizedFrankWolfeOptFunc(*args, **kwargs)¶
Bases:
torch.autograd.FunctionAn autograd function for regularized Frank-Wolfe
- static forward(ctx, pred_cost: torch.Tensor, module: regularizedFrankWolfeOpt) torch.Tensor¶
Forward pass for regularized Frank-Wolfe
- Parameters:
pred_cost – a batch of predicted values of the cost
module – regularizedFrankWolfeOpt module
- Returns:
regularized solutions
- Return type:
torch.tensor
- static backward(ctx, grad_output: torch.Tensor) tuple[torch.Tensor | None, Ellipsis]¶
Backward pass for regularized Frank-Wolfe
- class pyepo.func.regularized.regularizedFrankWolfeFenchelYoung(optmodel: pyepo.model.opt.optModel, lambd: float = 1.0, max_iter: int = 20, tol: float = 1e-06, processes: int = 1, solve_ratio: float = 1.0, reduction: pyepo.func.abcmodule.Reduction = 'mean', dataset: pyepo.data.dataset.optDataset | None = None)¶
Bases:
pyepo.func.abcmodule.optModuleL2-Regularized Frank-Wolfe with Fenchel-Young loss (RFYL).
Pairs the RFWO regularized solver with the Fenchel-Young loss of the L2 regularizer, returning a convex scalar loss that compares the predicted cost \(\hat{\mathbf{c}}\) to the true optimum \(\mathbf{w}^*(\mathbf{c})\) directly – no user-defined task loss needed. Specialized to \(\Omega(\mathbf{w}) = \tfrac{\lambda}{2}\|\mathbf{w}\|_2^2\), the loss collapses to a transparent “compare regularizers + linear residual” form.
By Danskin’s theorem the gradient is the simple residual \(\mathbf{w}^*(\mathbf{c}) - \hat{\mathbf{w}}_\lambda (\hat{\mathbf{c}})\), so the backward path skips implicit differentiation through the Frank-Wolfe iterate.
Reference: Dalle et al. (2022) https://arxiv.org/abs/2207.13513
- lambd¶
- max_iter = 20¶
- tol = 1e-06¶
- forward(pred_cost: torch.Tensor, true_sol: torch.Tensor) torch.Tensor¶
Forward pass
- class pyepo.func.regularized.regularizedFrankWolfeFenchelYoungFunc(*args, **kwargs)¶
Bases:
torch.autograd.FunctionAn autograd function for regularized Frank-Wolfe with Fenchel-Young loss
- static forward(ctx, pred_cost: torch.Tensor, true_sol: torch.Tensor, module: regularizedFrankWolfeFenchelYoung) torch.Tensor¶
Forward pass for regularized Frank-Wolfe with Fenchel-Young loss
- Parameters:
pred_cost – a batch of predicted values of the cost
true_sol – a batch of true optimal solutions
module – regularizedFrankWolfeFenchelYoung module
- Returns:
Fenchel-Young loss
- Return type:
torch.tensor
- static backward(ctx, grad_output: torch.Tensor) tuple[torch.Tensor | None, Ellipsis]¶
Backward pass for regularized Frank-Wolfe with Fenchel-Young loss