Skip to content

Commit

Permalink
Division by zero handling in metrics. Cf #124
Browse files Browse the repository at this point in the history
  • Loading branch information
ocourtin authored and daniel-j-h committed Oct 9, 2018
1 parent 036e2ae commit dcea15d
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions robosat/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,29 @@ def get_fg_iou(self):
Returns:
The foreground Intersection over Union score for all observations seen so far.
"""
return self.tp / (self.tp + self.fn + self.fp)

try:
iou = self.tp / (self.tp + self.fn + self.fp)
except ZeroDivisionError:
iou = float("Inf")

return iou

def get_mcc(self):
"""Retrieves the Matthew's Coefficient Correlation score.
Returns:
The Matthew's Coefficient Correlation score for all observations seen so far.
"""
return (self.tp * self.tn - self.fp * self.fn) / math.sqrt(
(self.tp + self.fp) * (self.tp + self.fn) * (self.tn + self.fp) * (self.tn + self.fn)
)

try:
mcc = (self.tp * self.tn - self.fp * self.fn) / math.sqrt(
(self.tp + self.fp) * (self.tp + self.fn) * (self.tn + self.fp) * (self.tn + self.fn)
)
except ZeroDivisionError:
mcc = float("Inf")

return mcc


# Todo:
Expand Down

0 comments on commit dcea15d

Please sign in to comment.