mirror of
https://github.com/fjosw/pyerrors.git
synced 2025-05-14 19:43:41 +02:00
Feature/corr matrix and inverse cov matrix as input in least squares function for correlated fits (#223)
* feat: corr_matrix kwargs as input for least squares fit * feat/tests: inverse covariance matrix and correlation matrix kwargs as input for least squares function * feat/tests/example: reduced new kwargs to 'inv_chol_cov_matrix' and outsourced the inversion & cholesky decomposition of the covariance matrix (function 'invert_corr_cov_cholesky(corr, covdiag)') * tests: added tests for inv_chol_cov_matrix kwarg for the case of combined fits * fix: renamed covdiag to inverrdiag needed for the cholesky decomposition and corrected its documentation * examples: added an example of a correlated combined fit to the least_squares documentation * feat/tests/fix(of typos): added function 'sort_corr()' (and a test of it) to sort correlation matrix according to a list of alphabetically sorted keys * docs: added more elaborate documentation/example of sort_corr(), fixed typos in documentation of invert_corr_cov_cholesky()
This commit is contained in:
parent
3830e3f777
commit
1d6f7f65c0
5 changed files with 596 additions and 46 deletions
|
@ -1063,6 +1063,27 @@ def test_covariance_reorder_non_overlapping_data():
|
|||
assert np.isclose(corr1[0, 1], corr2[0, 1], atol=1e-14)
|
||||
|
||||
|
||||
def test_sort_corr():
|
||||
xd = {
|
||||
'b': [1, 2, 3],
|
||||
'a': [2.2, 4.4],
|
||||
'c': [3.7, 5.1]
|
||||
}
|
||||
|
||||
yd = {k : pe.cov_Obs(xd[k], [.2 * o for o in xd[k]], k) for k in xd}
|
||||
key_orig = list(yd.keys())
|
||||
y_all = np.concatenate([np.array(yd[key]) for key in key_orig])
|
||||
[o.gm() for o in y_all]
|
||||
cov = pe.covariance(y_all)
|
||||
|
||||
key_ls = key_sorted = sorted(key_orig)
|
||||
y_sorted = np.concatenate([np.array(yd[key]) for key in key_sorted])
|
||||
[o.gm() for o in y_sorted]
|
||||
cov_sorted = pe.covariance(y_sorted)
|
||||
retcov = pe.obs.sort_corr(cov, key_orig, yd)
|
||||
assert np.sum(retcov - cov_sorted) == 0
|
||||
|
||||
|
||||
def test_empty_obs():
|
||||
o = pe.Obs([np.random.rand(100)], ['test'])
|
||||
q = o + pe.Obs([], [], means=[])
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue