Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions pypots/nn/functional/error.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,14 @@ def calc_quantile_loss(
q: float,
eval_points: Union[np.ndarray, torch.Tensor],
) -> Union[float, torch.Tensor]:
# check types and NaN (but not predictions/targets shape, which is
# broadcast here and explicitly differs in the calc_quantile_crps_sum
# caller). Mask shape is still validated against targets by _check_inputs.
_check_inputs(predictions, targets, eval_points, check_shape=False)

# preserve numpy-in/numpy-out contract used by calc_mae/calc_mse/calc_rmse/calc_mre
numpy_in = isinstance(predictions, np.ndarray)

# Handle numpy arrays by converting to torch tensors
if isinstance(predictions, np.ndarray):
predictions = torch.from_numpy(predictions)
Expand All @@ -271,6 +279,8 @@ def calc_quantile_loss(
quantile_loss = 2 * torch.sum(
torch.abs((predictions - targets) * eval_points * ((targets <= predictions) * 1.0 - q))
)
if numpy_in:
return quantile_loss.detach().cpu().numpy()
return quantile_loss


Expand Down