From 4e8ffb91cffb69968dedf813fc9cde44f5a40eec Mon Sep 17 00:00:00 2001 From: Alec Wysoker Date: Thu, 30 Nov 2023 16:29:40 -0500 Subject: [PATCH] Don't crash with ZeroDivisionError if initial test ELBO is the best test ELBO --- cellbender/remove_background/train.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/cellbender/remove_background/train.py b/cellbender/remove_background/train.py index bf7bed6..961e06e 100644 --- a/cellbender/remove_background/train.py +++ b/cellbender/remove_background/train.py @@ -247,7 +247,12 @@ def run_training(model: RemoveBackgroundPyroModel, if model.loss['test']['elbo'][-1] < best_test_elbo: final_best_diff = best_test_elbo - model.loss['test']['elbo'][-1] initial_best_diff = best_test_elbo - model.loss['test']['elbo'][0] - if (final_best_diff / initial_best_diff) > final_elbo_fail_fraction: + if initial_best_diff == 0: + raise ElboException( + f"Training failed because there was no improvement from the initial test loss {model.loss['test']['elbo'][0]:.2f}. " + f"Final test loss was {model.loss['test']['elbo'][-1]}" + ) + elif (final_best_diff / initial_best_diff) > final_elbo_fail_fraction: raise ElboException( f"Training failed because final test loss {model.loss['test']['elbo'][-1]:.2f} " f'is not sufficiently close to best test loss {best_test_elbo:.2f}, '