pyepo.metric.regret

True regret loss

Functions

regret(→ float)

Normalized true regret (SPO loss) of a trained predictor.

calRegret(→ float)

A function to calculate normalized true regret for a batch

Module Contents

pyepo.metric.regret.regret(predmodel: torch.nn.Module, optmodel: pyepo.model.opt.optModel, dataloader: torch.utils.data.DataLoader) float

Normalized true regret (SPO loss) of a trained predictor.

Solves the optimization problem on the predicted cost vector \(\hat{\mathbf{c}}\), then measures the excess true objective incurred by that decision: \(\sum_i (\mathbf{c}_i^\top \mathbf{w}^*(\hat{\mathbf{c}}_i) - z^*(\mathbf{c}_i)) / \sum_i |z^*(\mathbf{c}_i)|\). The result is dimensionless and comparable across problem scales. The predictor is automatically put into eval() for the call and restored to train() afterwards.

Parameters:
  • predmodel – a regression neural network for cost prediction

  • optmodel – a PyEPO optimization model

  • dataloader – PyTorch DataLoader over an optDataset (yielding (x, c, w, z) tuples)

Returns:

normalized true regret

Return type:

float

pyepo.metric.regret.calRegret(optmodel: pyepo.model.opt.optModel, pred_cost: numpy.ndarray, true_cost: numpy.ndarray, true_obj: float) float

A function to calculate normalized true regret for a batch

Parameters:
  • optmodel – optimization model

  • pred_cost – predicted costs

  • true_cost – true costs

  • true_obj – true optimal objective value

Returns:

true regret loss

Return type:

float