Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix lesion_TPR_at_FPR #20

Merged
merged 1 commit into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def run(self):
long_description = fh.read()

setuptools.setup(
version='1.4.7', # also update version in metrics.py -> version
version='1.4.8', # also update version in metrics.py -> version
author_email='[email protected]',
long_description=long_description,
long_description_content_type="text/markdown",
Expand Down
2 changes: 1 addition & 1 deletion src/picai_eval/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def score(self):
def lesion_TPR_at_FPR(self, FPR: float) -> float:
"""Calculate the lesion-level true positive rate (sensitivity) at a given
false positive rate (average number of false positives per examimation)"""
if np.max(self.lesion_FPR) < FPR:
if np.min(self.lesion_FPR) > FPR:
return 0
return self.lesion_TPR[self.lesion_FPR <= FPR][-1]

Expand Down
30 changes: 30 additions & 0 deletions tests/test_lesion_tpr_at_fpr.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import numpy as np

from picai_eval import Metrics


def test_lesion_tpr_at_fpr():
"""
Test the lesion TPR at FPR function
"""
lesion_results = {
"0": [(0, 1, 1.)],
"1": [(0, 2, 1.)],
"2": [(1, 3, 1.)],
"3": [(1, 1, 1.), (1, 1, 1.)],
"4": [(0, 3, 1.)],
"5": [(1, 2.5, 1.), (1, 1.5, 1.)],
}
metrics = Metrics(lesion_results=lesion_results)
np.testing.assert_allclose(metrics.lesion_TPR, [0.2, 0.4, 0.4, 0.6, 0.6])
np.testing.assert_allclose(metrics.lesion_FPR, [0.16666667, 0.16666667, 0.33333334, 0.33333334, np.inf])

# test with FPR = 0.3
np.testing.assert_almost_equal(metrics.lesion_TPR_at_FPR(0.3), 0.4)

# test with too low FPR
np.testing.assert_almost_equal(metrics.lesion_TPR_at_FPR(0.1), 0.0)


if __name__ == "__main__":
test_lesion_tpr_at_fpr()
Loading