Skip to content

Commit b6da9e1

Browse files
authored
Merge pull request #55 from Project-MONAI/docs_tests
Docs tests
2 parents ca3d352 + a805dd9 commit b6da9e1

File tree

5 files changed

+59
-22
lines changed

5 files changed

+59
-22
lines changed

MetricsReloaded/metrics/pairwise_measures.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1200,6 +1200,7 @@ def measured_distance(self):
12001200
and masd
12011201
12021202
"""
1203+
12031204
if "hd_perc" in self.dict_args.keys():
12041205
perc = self.dict_args["hd_perc"]
12051206
else:
@@ -1208,13 +1209,19 @@ def measured_distance(self):
12081209
if np.sum(self.pred + self.ref) == 0:
12091210
warnings.warn("Prediction and reference empty - distances set to 0")
12101211
return 0, 0, 0, 0
1212+
if np.sum(self.pred) == 0 and np.sum(self.ref)>0:
1213+
warnings.warn("Prediction empty but reference not empty - need to set to worse case in aggregation")
1214+
return np.nan, np.nan, np.nan, np.nan
1215+
if np.sum(self.ref) == 0 and np.sum(self.pred)>0:
1216+
warnings.warn('Prediction not empty but reference empty - non existing output - need be set to WORSE case in aggregation')
1217+
return np.nan, np.nan, np.nan, np.nan
12111218
(
12121219
ref_border_dist,
12131220
pred_border_dist,
12141221
ref_border,
12151222
pred_border,
12161223
) = self.border_distance()
1217-
print(ref_border_dist)
1224+
# print(ref_border_dist)
12181225
average_distance = (np.sum(ref_border_dist) + np.sum(pred_border_dist)) / (
12191226
np.sum(pred_border + ref_border)
12201227
)

test/test_metrics/test_calibration_metrics.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ def test_brier_score():
7171
expected_bs = 0.4
7272
assert_allclose(expected_bs, value_test, atol=0.01)
7373

74+
#To use SN 2.14 p 99 of Metrics Reloaded
7475

7576
def test_top_label_classification_error():
7677
ref_tce = [1, 0, 2, 1]

test/test_metrics/test_pairwise_measures.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
ppm212_1 = PM(pred212, ref212)
4747
ppm212_2 = PM(pred212,ref212,dict_args={'boundary_dist':2})
4848

49-
#Data for figure 5c (Hausdoff with annotation error p14 Pitfalls)
49+
#Data for figure 5c (Hausdorff with annotation error p14 Pitfalls)
5050
ref5c = np.zeros([14, 14])
5151
ref5c[1, 1] = 1
5252
ref5c[9:12, 9:12] = 1
@@ -630,6 +630,7 @@ def test_mcc():
630630
assert mcc < 1
631631

632632

633+
633634
def test_distance_empty():
634635
"""
635636
Testing that output is 0 when reference and prediction empty for calculation of distance
@@ -833,6 +834,30 @@ def test_hausdorff_distance_5c():
833834
hausdorff_distance_perc, expected_hausdorff_distance_perc, atol=0.01
834835
)
835836

837+
def test_distance_empty_ref():
838+
ppm1 = PM(pred29_1, ref29_1*0)
839+
hd, hd_perc, masd, assd = ppm1.measured_distance()
840+
assert np.isnan(hd)
841+
assert np.isnan(hd_perc)
842+
assert np.isnan(masd)
843+
assert np.isnan(assd)
844+
845+
def test_distance_empty_pred():
846+
ppm1 = PM(pred29_1*0, ref29_1)
847+
hd, hd_perc, masd, assd = ppm1.measured_distance()
848+
assert np.isnan(hd)
849+
assert np.isnan(hd_perc)
850+
assert np.isnan(masd)
851+
assert np.isnan(assd)
852+
853+
854+
def test_distance_empty_pred_and_ref():
855+
ppm1 = PM(pred29_1*0, ref29_1*0)
856+
hd, hd_perc, masd, assd = ppm1.measured_distance()
857+
assert hd == 0
858+
assert hd_perc == 0
859+
assert masd == 0
860+
assert assd == 0
836861

837862
def test_boundary_iou():
838863
"""

test/test_processes/test_mixed_measures_processes.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,26 +9,26 @@
99
from sklearn.metrics import cohen_kappa_score as cks
1010
from sklearn.metrics import matthews_corrcoef as mcc
1111

12-
# panoptic quality
13-
pq_pred1 = np.zeros([21, 21])
14-
pq_pred1[5:7, 2:5] = 1
15-
pq_pred2 = np.zeros([21, 21])
16-
pq_pred2[14:18, 4:6] = 1
17-
pq_pred2[16, 3] = 1
18-
pq_pred3 = np.zeros([21, 21])
19-
pq_pred3[14:18, 7:12] = 1
20-
pq_pred4 = np.zeros([21, 21])
21-
pq_pred4[2:8, 13:16] = 1
22-
pq_pred4[2:4, 12] = 1
12+
# Data for panoptic quality Figure 3.51 p96
13+
pq_pred1 = np.zeros([18, 18])
14+
pq_pred1[ 3:7,1:3] = 1
15+
pq_pred1[3:6,3:7]=1
16+
pq_pred2 = np.zeros([18, 18])
17+
pq_pred2[13:16,4:6] = 1
18+
pq_pred3 = np.zeros([18, 18])
19+
pq_pred3[7:12,13:17] = 1
20+
pq_pred4 = np.zeros([18, 18])
21+
pq_pred4[13:15,13:17] = 1
22+
pq_pred4[15,15] = 1
2323

24-
pq_ref1 = np.zeros([21, 21])
25-
pq_ref1[8:11, 3] = 1
26-
pq_ref1[9, 2:5] = 1
27-
pq_ref2 = np.zeros([21, 21])
28-
pq_ref2[14:19, 7:13] = 1
29-
pq_ref3 = np.zeros([21, 21])
30-
pq_ref3[2:7, 14:17] = 1
31-
pq_ref3[2:4, 12:14] = 1
24+
pq_ref1 = np.zeros([18, 18])
25+
pq_ref1[2:7, 1:3] = 1
26+
pq_ref1[2:5,3:6] = 1
27+
pq_ref2 = np.zeros([18, 18])
28+
pq_ref2[6:12,12:17] = 1
29+
pq_ref3 = np.zeros([18, 18])
30+
pq_ref3[14:15:,7:10] = 1
31+
pq_ref3[13:16,8:9] = 1
3232

3333

3434
def test_mismatch_category():

test/test_utility/test_assignment_localization.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,11 @@
2727
pred_boxes_6a = [pred6a1, pred6a2, pred6a3, pred6a4, pred6a5]
2828
ref_boxes_6a = [ref6a1, ref6a2, ref6a3, ref6a4]
2929

30-
#Data from Panoptic Quality - 3.51 p96
30+
#Data from SN2.17 from Metrics Reloaded
31+
32+
33+
34+
#Data from Panoptic Quality - 3.51 p96 of Pitfalls
3135
#Figure 3.51 p96
3236
pq_pred1 = np.zeros([18, 18])
3337
pq_pred1[ 3:7,1:3] = 1

0 commit comments

Comments
 (0)