drugforge.ml.loss.L1Loss

class drugforge.ml.loss.L1Loss(*args: Any, **kwargs: Any)[source]

Bases: L1Loss

__init__(loss_type=None)[source]

Class for calculating L1 (MAE) loss, with various options

Parameters:

loss_type (str, optional) –

Which type of loss to use:
  • None: vanilla MAE

  • “step”: step MAE loss

  • “uncertainty”: MAE loss with added uncertainty

Methods

__init__([loss_type])

Class for calculating L1 (MAE) loss, with various options

forward(pred, pose_preds, target, in_range, ...)

Dispatch method for calculating loss.

step_loss(pred, target[, in_range])

Step loss calculation.

forward(pred, pose_preds, target, in_range, uncertainty)[source]

Dispatch method for calculating loss. All arguments should be passed regardless of actual loss function to keep an identical signature for this class. Data is passed to self.loss_function.

step_loss(pred, target, in_range=None)[source]

Step loss calculation. For in_range < 0, loss is returned as 0 if pred < target, otherwise MAE is calculated as normal. For in_range > 0, loss is returned as 0 if pred > target, otherwise MAE is calculated as normal. For in_range == 0, MAE is calculated as normal.

Parameters:
  • pred (torch.Tensor) – Model prediction

  • target (torch.Tensor) – Prediction target

  • in_range (torch.Tensor, optional) – target’s presence in the dynamic range of the assay. Give a value of < 0 for target below lower bound, > 0 for target above upper bound, and 0 or None for inside range

Returns:

Calculated loss

Return type:

torch.Tensor