catch possible exception in fit error calculation, maybe source of #39

This commit is contained in:
Dominik Demuth 2023-04-06 18:40:16 +02:00
parent 43285b4bd5
commit 330f36fd66

View File

@ -14,6 +14,8 @@ from .result import FitResultCreator
__all__ = ['FitRoutine', 'FitAbortException']
from ..lib.logger import logger
class FitAbortException(Exception):
pass
@ -464,11 +466,18 @@ class FitRoutine(object):
def _calc_error(jac, chi, nobs, nvars):
# copy of scipy.curve_fit to calculate covariance
# noinspection PyTupleAssignmentBalance
_, s, vt = la.svd(jac, full_matrices=False)
threshold = EPS * max(jac.shape) * s[0]
s = s[s > threshold]
vt = vt[:s.size]
pcov = np.dot(vt.T / s**2, vt) * chi / (nobs - nvars)
try:
_, s, vt = la.svd(jac, full_matrices=False)
except ValueError as e:
# this may be issue #39: On entry to DGESSD parameter had an illegal value
# catch this exception and ignore error calculation
logger.error(f'Error calculation failed with {e.args}')
pcov = None
else:
threshold = EPS * max(jac.shape) * s[0]
s = s[s > threshold]
vt = vt[:s.size]
pcov = np.dot(vt.T / s**2, vt) * chi / (nobs - nvars)
if pcov is None:
_err = np.zeros(nvars)