pyepo.func.surrogate

Surrogate Loss function

Classes

SPOPlus

An autograd module for SPO+ Loss, as a surrogate loss function of SPO

SPOPlusFunc

A autograd function for SPO+ Loss

perturbationGradient

An autograd module for PG Loss, as a surrogate loss function of objective

Module Contents

class pyepo.func.surrogate.SPOPlus(optmodel, processes=1, solve_ratio=1, reduction='mean', dataset=None)

Bases: pyepo.func.abcmodule.optModule

An autograd module for SPO+ Loss, as a surrogate loss function of SPO (regret) Loss, which measures the decision error of the optimization problem.

For SPO/SPO+ Loss, the objective function is linear and constraints are known and fixed, but the cost vector needs to be predicted from contextual data.

The SPO+ Loss is convex with subgradient. Thus, it allows us to design an algorithm based on stochastic gradient descent.

Reference: <https://doi.org/10.1287/mnsc.2020.3922>

spop
forward(pred_cost, true_cost, true_sol, true_obj)

Forward pass

class pyepo.func.surrogate.SPOPlusFunc(*args, **kwargs)

Bases: torch.autograd.Function

A autograd function for SPO+ Loss

static forward(ctx, pred_cost, true_cost, true_sol, true_obj, module)

Forward pass for SPO+

Parameters:
  • pred_cost (torch.tensor) – a batch of predicted values of the cost

  • true_cost (torch.tensor) – a batch of true values of the cost

  • true_sol (torch.tensor) – a batch of true optimal solutions

  • true_obj (torch.tensor) – a batch of true optimal objective values

  • module (optModule) – SPOPlus modeul

Returns:

SPO+ loss

Return type:

torch.tensor

static backward(ctx, grad_output)

Backward pass for SPO+

class pyepo.func.surrogate.perturbationGradient(optmodel, sigma=0.1, two_sides=False, processes=1, solve_ratio=1, reduction='mean', dataset=None)

Bases: pyepo.func.abcmodule.optModule

An autograd module for PG Loss, as a surrogate loss function of objective value, which measures the decision quality of the optimization problem.

For PG Loss, the objective function is linear, and constraints are known and fixed, but the cost vector needs to be predicted from contextual data.

According to Danskin’s Theorem, the PG Loss is derived from different zeroth order approximations and has the informative gradient. Thus, it allows us to design an algorithm based on stochastic gradient descent.

Reference: <https://arxiv.org/abs/2402.03256>

sigma = 0.1
two_sides = False
forward(pred_cost, true_cost)

Forward pass

_finiteDifference(pred_cost, true_cost)

Zeroth order approximations for surrogate objective value