From 7b6fa4e72e8b15500bd04ed1b1781efc2f8d6fe3 Mon Sep 17 00:00:00 2001
From: "Daniel.Frisinghelli" <daniel.frisinghelli@eurac.edu>
Date: Wed, 20 Oct 2021 11:32:07 +0200
Subject: [PATCH] Implemented median reduction.

---
 climax/core/loss.py | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/climax/core/loss.py b/climax/core/loss.py
index c2cc811..2147c5b 100644
--- a/climax/core/loss.py
+++ b/climax/core/loss.py
@@ -26,6 +26,8 @@ class NaNLoss(_Loss):
             return tensor.mean()
         elif self.reduction == 'sum':
             return tensor.sum()
+        elif self.reduction == 'median':
+            return tensor.median()
 
 
 class MSELoss(NaNLoss):
@@ -133,13 +135,9 @@ class BernoulliWeibullLoss(BernoulliLoss):
         # clip probabilities to (0, 1)
         p_pred = torch.sigmoid(y_pred[:, 0, ...].squeeze()[mask])
 
-        # clip scale to (0, +infinity)
-        scale = torch.exp(y_pred[:, 2, ...].squeeze()[mask][~mask_p])
-
-        # clip shape to (0, 10)
-        # NOTE: in general shape in (0, +infinity), clipping is required for
-        #       numerical stability
+        # clip shape and scale to (0, +infinity)
         shape = torch.exp(y_pred[:, 1, ...].squeeze()[mask][~mask_p])
+        scale = torch.exp(y_pred[:, 2, ...].squeeze()[mask][~mask_p])
 
         # negative log-likelihood function of Bernoulli-Weibull distribution
         loss = torch.zeros_like(y_true)
-- 
GitLab