mirror of
https://github.com/fjosw/pyerrors.git
synced 2025-03-15 14:50:25 +01:00
feat: eigenvalue calculation in pe.covariance is not done if only the
correlation matrix is requested.
This commit is contained in:
parent
328c564fdd
commit
658c2b30de
1 changed files with 9 additions and 9 deletions
|
@ -1452,13 +1452,6 @@ def covariance(obs, visualize=False, correlation=False, smooth=None, **kwargs):
|
|||
if isinstance(smooth, int):
|
||||
corr = _smooth_eigenvalues(corr, smooth)
|
||||
|
||||
errors = [o.dvalue for o in obs]
|
||||
cov = np.diag(errors) @ corr @ np.diag(errors)
|
||||
|
||||
eigenvalues = np.linalg.eigh(cov)[0]
|
||||
if not np.all(eigenvalues >= 0):
|
||||
warnings.warn("Covariance matrix is not positive semi-definite (Eigenvalues: " + str(eigenvalues) + ")", RuntimeWarning)
|
||||
|
||||
if visualize:
|
||||
plt.matshow(corr, vmin=-1, vmax=1)
|
||||
plt.set_cmap('RdBu')
|
||||
|
@ -1467,8 +1460,15 @@ def covariance(obs, visualize=False, correlation=False, smooth=None, **kwargs):
|
|||
|
||||
if correlation is True:
|
||||
return corr
|
||||
else:
|
||||
return cov
|
||||
|
||||
errors = [o.dvalue for o in obs]
|
||||
cov = np.diag(errors) @ corr @ np.diag(errors)
|
||||
|
||||
eigenvalues = np.linalg.eigh(cov)[0]
|
||||
if not np.all(eigenvalues >= 0):
|
||||
warnings.warn("Covariance matrix is not positive semi-definite (Eigenvalues: " + str(eigenvalues) + ")", RuntimeWarning)
|
||||
|
||||
return cov
|
||||
|
||||
|
||||
def _smooth_eigenvalues(corr, E):
|
||||
|
|
Loading…
Add table
Reference in a new issue