Skip to content

Commit

Permalink
Don't crash with ZeroDivisionError if initial test ELBO is the best t…
Browse files Browse the repository at this point in the history
…est ELBO
  • Loading branch information
alecw committed Apr 22, 2024
1 parent 72e6a3f commit 4e8ffb9
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion cellbender/remove_background/train.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}, '
Expand Down

0 comments on commit 4e8ffb9

Please sign in to comment.