| 1817 | name='interpolate_pr_auc') |
| 1818 | |
| 1819 | def result(self): |
| 1820 | if (self.curve == metrics_utils.AUCCurve.PR and |
| 1821 | self.summation_method == metrics_utils.AUCSummationMethod.INTERPOLATION |
| 1822 | ): |
| 1823 | # This use case is different and is handled separately. |
| 1824 | return self.interpolate_pr_auc() |
| 1825 | |
| 1826 | # Set `x` and `y` values for the curves based on `curve` config. |
| 1827 | recall = math_ops.div_no_nan(self.true_positives, |
| 1828 | self.true_positives + self.false_negatives) |
| 1829 | if self.curve == metrics_utils.AUCCurve.ROC: |
| 1830 | fp_rate = math_ops.div_no_nan(self.false_positives, |
| 1831 | self.false_positives + self.true_negatives) |
| 1832 | x = fp_rate |
| 1833 | y = recall |
| 1834 | else: # curve == 'PR'. |
| 1835 | precision = math_ops.div_no_nan( |
| 1836 | self.true_positives, self.true_positives + self.false_positives) |
| 1837 | x = recall |
| 1838 | y = precision |
| 1839 | |
| 1840 | # Find the rectangle heights based on `summation_method`. |
| 1841 | if self.summation_method == metrics_utils.AUCSummationMethod.INTERPOLATION: |
| 1842 | # Note: the case ('PR', 'interpolation') has been handled above. |
| 1843 | heights = (y[:self.num_thresholds - 1] + y[1:]) / 2. |
| 1844 | elif self.summation_method == metrics_utils.AUCSummationMethod.MINORING: |
| 1845 | heights = math_ops.minimum(y[:self.num_thresholds - 1], y[1:]) |
| 1846 | else: # self.summation_method = metrics_utils.AUCSummationMethod.MAJORING: |
| 1847 | heights = math_ops.maximum(y[:self.num_thresholds - 1], y[1:]) |
| 1848 | |
| 1849 | # Sum up the areas of all the rectangles. |
| 1850 | return math_ops.reduce_sum( |
| 1851 | math_ops.multiply(x[:self.num_thresholds - 1] - x[1:], heights), |
| 1852 | name=self.name) |
| 1853 | |
| 1854 | def reset_states(self): |
| 1855 | K.batch_set_value( |