drugforge.ml.loss.SmoothL1Loss
- class drugforge.ml.loss.SmoothL1Loss(*args: Any, **kwargs: Any)[source]
Bases:
SmoothL1Loss- __init__(loss_type=None)[source]
Class for calculating smooth L1 loss, with various options
- Parameters:
loss_type (str, optional) –
- Which type of loss to use:
None: vanilla smooth L1
“step”: step smooth L1 loss
“uncertainty”: smooth L1 loss with added uncertainty
Methods
__init__([loss_type])Class for calculating smooth L1 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 loss is calculated as normal. For in_range > 0, loss is returned as 0 if pred > target, otherwise loss is calculated as normal. For in_range == 0, loss 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