Skip to content

Commit

Permalink
metrics: standalone log()
Browse files Browse the repository at this point in the history
- fixes #51
  • Loading branch information
casperdcl committed Jul 11, 2024
1 parent a62efb0 commit 6bf2a03
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 7 deletions.
2 changes: 1 addition & 1 deletion main_OSEM.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def update(self):
def update_objective(self):
"""
NB: The objective value is not required by OSEM nor by PETRIC, so this returns `0`.
NB: In theory it should be `sum(prompts * log(acq_model.forward(self.x)) - self.x * sensitivity)` across all subsets.
NB: It should be `sum(prompts * log(acq_model.forward(self.x)) - self.x * sensitivity)` across all subsets.
"""
return 0

Expand Down
9 changes: 3 additions & 6 deletions petric.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,11 @@ def __call__(self, algorithm):
iteration = algorithm.iteration
if iteration % algorithm.update_objective_interval != 0 and iteration != algorithm.max_iteration:
return
self.log(algorithm.x, iteration)

def log(self, test_im, iteration):
assert not any(self.filter.values()), "Filtering not implemented"
test_im_arr = algorithm.x.as_array()

# (1) global metrics & statistics
test_im_arr = test_im.as_array()
self.tb_summary_writer.add_scalar(
"RMSE_whole_object",
np.sqrt(mse(self.ref_im_arr[self.whole_object_indices], test_im_arr[self.whole_object_indices])) /
Expand All @@ -115,10 +115,7 @@ def __call__(self, algorithm):
"RMSE_background",
np.sqrt(mse(self.ref_im_arr[self.background_indices], test_im_arr[self.background_indices])) / self.norm,
iteration)

# (2) local metrics & statistics
for voi_name, voi_indices in sorted(self.voi_indices.items()):
# AEM not to be confused with MAE
self.tb_summary_writer.add_scalar(
f"AEM_VOI_{voi_name}",
np.abs(test_im_arr[voi_indices].mean() - self.ref_im_arr[voi_indices].mean()) / self.norm, iteration)
Expand Down

0 comments on commit 6bf2a03

Please sign in to comment.