From 6bf2a03419aaaeb3d56005726b1528afc902179e Mon Sep 17 00:00:00 2001 From: Casper da Costa-Luis Date: Thu, 11 Jul 2024 23:37:46 +0100 Subject: [PATCH] metrics: standalone `log()` - fixes #51 --- main_OSEM.py | 2 +- petric.py | 9 +++------ 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/main_OSEM.py b/main_OSEM.py index 85bcf2e..19a48fa 100644 --- a/main_OSEM.py +++ b/main_OSEM.py @@ -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 diff --git a/petric.py b/petric.py index ebf2139..50efb72 100755 --- a/petric.py +++ b/petric.py @@ -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])) / @@ -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)