From aae6ed30e072b6d300ef033506d8e6b24b40abd6 Mon Sep 17 00:00:00 2001 From: Kris Thielemans Date: Thu, 19 Sep 2024 20:49:58 +0100 Subject: [PATCH] Threshold before computing sqrt for kappa For noisy data, the numerical errors can lead to tiny positive values in the Hessian, then giving NaN in the sqrt. So, we threshold. --- SIRF_data_preparation/create_initial_images.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/SIRF_data_preparation/create_initial_images.py b/SIRF_data_preparation/create_initial_images.py index 936aeb5..f8b13a2 100644 --- a/SIRF_data_preparation/create_initial_images.py +++ b/SIRF_data_preparation/create_initial_images.py @@ -82,9 +82,8 @@ def compute_kappa_image(obj_fun, initial_image): WARNING: Assumes the objective function has been set-up already """ - # This needs SIRF 3.7. If you don't have that yet, you should probably upgrade anyway! - Hessian_row_sum = obj_fun.multiply_with_Hessian(initial_image, initial_image.allocate(1)) - return (-1 * Hessian_row_sum).power(.5) + minus_Hessian_row_sum = -1 * obj_fun.multiply_with_Hessian(initial_image, initial_image.allocate(1)) + return minus_Hessian_row_sum.maximum(0).power(.5) def main(argv=None):