mirror of
https://github.com/fjosw/pyerrors.git
synced 2025-06-30 08:49:28 +02:00
feat: correlated_fit now throws an exception when the correlation matrix
is ill conditioned with respect to the machine precision. Criterion for warning for ill-conditioned covariance matrix changed to cond > sqrt(eps) Test added.
This commit is contained in:
parent
a069f84264
commit
e6813a6c8e
2 changed files with 10 additions and 2 deletions
|
@ -464,8 +464,10 @@ def _standard_fit(x, y, func, silent=False, **kwargs):
|
|||
corr = covariance(y, correlation=True)
|
||||
covdiag = np.diag(1 / np.asarray(dy_f))
|
||||
condn = np.linalg.cond(corr)
|
||||
if condn > 1e8:
|
||||
warnings.warn("Correlation matrix may be ill-conditioned, condition number: %1.2e" % (condn), RuntimeWarning)
|
||||
if condn > 0.1 / np.finfo(float).eps:
|
||||
raise Exception(f"Cannot invert correlation matrix as its condition number exceeds machine precision ({condn:1.2e})")
|
||||
if condn > 1 / np.sqrt(np.finfo(float).eps):
|
||||
warnings.warn("Correlation matrix may be ill-conditioned, condition number: {%1.2e}" % (condn), RuntimeWarning)
|
||||
chol = np.linalg.cholesky(corr)
|
||||
chol_inv = np.linalg.inv(chol)
|
||||
chol_inv = np.dot(chol_inv, covdiag)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue