Skip to content

Commit 2f49a90

Browse files
Carole SudreCarole Sudre
authored andcommitted
update of actions
2 parents b0fa03e + 7bef02a commit 2f49a90

5 files changed

Lines changed: 63 additions & 5 deletions

File tree

.github/workflows/python-app.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@ name: Unit Tests
99

1010
on:
1111
push:
12+
<<<<<<< HEAD
1213
branches: [ main, docs_test ] # run when anything is pushed to these branches
14+
=======
15+
branches: [ main, docs_tests ] # run when anything is pushed to these branches
16+
>>>>>>> 7bef02a4357737d41391ceef32945c656e64c08e
1317
pull_request:
1418
branches: [ main ] # run for the code submitted as a PR to these branches
1519

@@ -55,12 +59,14 @@ jobs:
5559
5660
# Using Codecov's action, upload the coverage report for the triggering commit/PR
5761
- name: Upload coverage
58-
uses: codecov/codecov-action@v2
62+
uses: codecov/codecov-action@v4
5963
with:
6064
file: ./coverage.xml
6165
fail_ci_if_error: true
6266
verbose: true
6367
version: "v0.1.15"
68+
codecov:
69+
token: ${{ secrets.CODECOV_TOKEN }}
6470

6571
build_docs:
6672
runs-on: ubuntu-latest

MetricsReloaded/metrics/calibration_measures.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ def class_wise_expectation_calibration_error(self):
117117
nbins = self.dict_args["bins_ece"]
118118
else:
119119
nbins = 10
120+
print('number bins is ',nbins)
120121
step = 1.0 / nbins
121122
range_values = np.arange(0, 1.00001, step)
122123
list_values = []
@@ -385,8 +386,10 @@ def top_label_classification_error(self):
385386
prob_ref_values, prob_ref_counts = np.unique(self.ref, return_counts=True)
386387
for k in range(nclasses):
387388
idx = np.where(prob_ref_values == k)
388-
if len(idx) == 0:
389+
print(k, idx)
390+
if np.size(idx) == 0:
389391
prob[k] = 0
392+
print('nothing in ', k)
390393
else:
391394
prob[k] = prob_ref_counts[idx[0]] / numb_samples
392395

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[build-system]
22
requires = [
33
"setuptools >= 40.0.4",
4-
"setuptools < 82.0.0
4+
"setuptools < 82.0.0",
55
"setuptools_scm >= 2.0.0",
66
"wheel >= 0.29.0",
77
]

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
description=version_info["__description__"],
2626
author=version_info["__author__"],
2727
author_email=version_info["__author_email__"],
28-
url="https://github.com/csudre/MetricsReloaded",
28+
url="https://github.com/Project-MONAI/MetricsReloaded",
2929
packages=find_packages(),
3030
py_modules=[
3131
os.path.splitext(os.path.basename(path))[0]
@@ -50,7 +50,7 @@
5050
],
5151
project_urls={
5252
"Documentation": "https://MetricsReloaded.readthedocs.io/",
53-
"Issue Tracker": "https://github.com/csudre/MetricsReloaded/issues",
53+
"Issue Tracker": "https://github.com/Project-MONAI/MetricsReloaded/issues",
5454
},
5555
python_requires=">=3.7",
5656
install_requires=requirements,

test/test_metrics/test_calibration_metrics.py

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

74+
def test_root_brier_score():
75+
ref_bs = [1, 0]
76+
pred_bs = [[0.2,0.8],
77+
[0.4,0.6]]
78+
ppm = CalibrationMeasures(np.asarray(pred_bs), np.asarray(ref_bs))
79+
value_test = ppm.root_brier_score()
80+
expected_bs = 0.6325
81+
assert_allclose(expected_bs, value_test, atol=0.01)
82+
7483
#To use SN 2.14 p 99 of Metrics Reloaded
7584

7685
def test_top_label_classification_error():
@@ -86,6 +95,22 @@ def test_top_label_classification_error():
8695
value_test = cm.top_label_classification_error()
8796
assert_allclose(value_test, expected_tce, atol=0.001)
8897

98+
def test_top_label_classification_error_oneemptyclass():
99+
ref_tce = [1, 0, 1, 1]
100+
pred_tce = [[0.1, 0.8, 0, 0.1], [0.6, 0.1, 0.6, 0.7], [0.3, 0.1, 0.4, 0.2]]
101+
# 0.25 - 0.75 - 0
102+
#
103+
pred_tce = np.asarray(pred_tce).T
104+
ref_tce = np.asarray(ref_tce)
105+
expected_prob = [0.75, 0.25, 0.75, 0.75]
106+
best_prob = [0.6, 0.8, 0.6, 0.7]
107+
pred_class = [1, 0, 1, 1]
108+
# sqrt(0.15^2 + 0.55^2 + 0.15^2 + 0.05^2)/4
109+
expected_tce = 0.2958
110+
cm = CalibrationMeasures(pred_tce, ref_tce)
111+
value_test = cm.top_label_classification_error()
112+
assert_allclose(value_test, expected_tce, atol=0.001)
113+
89114

90115
def test_negative_log_likelihood():
91116
ref_nll = [1, 0, 2, 1]
@@ -111,32 +136,56 @@ def test_class_wise_expectation_calibration_error():
111136
pred_cwece = np.asarray(pred_cwece).T
112137
dict_args = {"bins_ece": 2}
113138
cm = CalibrationMeasures(pred_cwece, ref_cwece, dict_args=dict_args)
139+
cm2 = CalibrationMeasures(pred_cwece, ref_cwece)
114140
value_test = cm.class_wise_expectation_calibration_error()
141+
value_test2 = cm2.class_wise_expectation_calibration_error()
115142
expected_cwece = 0.150
143+
expected_cwece2 = 0.150
116144
assert_allclose(value_test, expected_cwece, atol=0.001)
145+
assert_allclose(value_test2, expected_cwece2, atol=0.001)
117146

118147

119148
def test_gamma_ik():
120149
pred = [[0.1, 0.8, 0, 0.1], [0.6, 0.1, 0, 0.7], [0.3, 0.1, 1, 0.2]]
121150
pred = np.asarray(pred).T
122151
ref = np.asarray([1, 0, 2, 1])
123152
cm = CalibrationMeasures(pred, ref)
153+
cm2 = CalibrationMeasures(pred, ref, dict_args={'bandwidth':0.5})
124154
value_test = cm.gamma_ik(0, 0)
155+
value_test2 = cm2.gamma_ik(0,0)
125156
expected_gamma = gamma(1.2)
157+
expected_gamma2 = gamma(1.2)
126158
assert_allclose(value_test, expected_gamma, atol=0.001)
159+
assert_allclose(value_test2, expected_gamma2, atol=0.001)
127160

128161

129162
def test_dirichlet_kernel():
130163
pred = [[0.1, 0.8, 0, 0.1], [0.6, 0.1, 0, 0.7], [0.3, 0.1, 1, 0.2]]
131164
pred = np.asarray(pred).T
132165
ref = np.asarray([1, 0, 2, 1])
133166
cm = CalibrationMeasures(pred, ref)
167+
cm2 = CalibrationMeasures(pred,ref,dict_args={'bandwidth':0.5})
134168
numerator = gamma(1.2 + 2.2 + 1.6)
135169
denominator = gamma(1.2) * gamma(2.2) * gamma(1.6)
136170
prod = np.power(0.8, 0.2) * np.power(0.1, 1.2) * np.power(0.1, 0.6)
137171
value_test = cm.dirichlet_kernel(1, 0)
172+
value_test2 = cm2.dirichlet_kernel(1,0)
138173
expected_dir = numerator * prod / denominator
174+
expected_dir2 = expected_dir
139175
assert_allclose(value_test, expected_dir, atol=0.001)
176+
assert_allclose(value_test2, expected_dir2, atol=0.001)
177+
178+
179+
180+
def test_kernel_calculation():
181+
pred = [[0.1, 0.8, 0, 0.1], [0.6, 0.1, 0, 0.7], [0.3, 0.1, 1, 0.2]]
182+
#sqrt(0.7^2 + 0.5^2 + 0.2^2)/0.2
183+
pred = np.asarray(pred).T
184+
ref = np.asarray([1, 0, 2, 1])
185+
cm = CalibrationMeasures(pred,ref,dict_args={'bandwidth_kce':0.2})
186+
value_test = cm.kernel_calculation(0,1)[0,0]
187+
expected_value = 0.01208
188+
assert_allclose(value_test, expected_value, atol=0.001)
140189

141190
def test_kernel_calibration_error():
142191
pred = [[0.1, 0.8, 0, 0.1], [0.6, 0.1, 0, 0.7], [0.3, 0.1, 1, 0.2]]

0 commit comments

Comments
 (0)