From 5b5380430eb3b701c1c43e18524a6b4759f46e27 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Mon, 22 Nov 2021 15:31:40 +0100 Subject: handle fit errors in cross validation --- lib/paramfit.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'lib/paramfit.py') diff --git a/lib/paramfit.py b/lib/paramfit.py index 8cfd486..9923e1a 100644 --- a/lib/paramfit.py +++ b/lib/paramfit.py @@ -202,9 +202,15 @@ def _try_fits( if function_name not in raw_results: raw_results[function_name] = dict() error_function = param_function.error_function - res = optimize.least_squares( - error_function, [0, 1], args=(X, Y), xtol=2e-15 - ) + try: + res = optimize.least_squares( + error_function, [0, 1], args=(X, Y), xtol=2e-15 + ) + except FloatingPointError as e: + logger.warning( + f"optimize.least_squares threw '{e}' when fitting {param_function} on {X}, {Y}" + ) + continue measures = regression_measures(param_function.eval(res.x, X), Y) raw_results_by_param[other_parameters][function_name] = measures for measure, error_rate in measures.items(): -- cgit v1.2.3