mirror of
				https://github.com/fjosw/pyerrors.git
				synced 2025-11-04 01:25:46 +01:00 
			
		
		
		
	[Feat] Introduce checks of the provided inverse matrix for correlated fits (#259)
Co-authored-by: Simon Kuberski <simon.kuberski@cern.ch>
This commit is contained in:
		
					parent
					
						
							
								6ed6ce6113
							
						
					
				
			
			
				commit
				
					
						5f5438b563
					
				
			
		
					 2 changed files with 5 additions and 0 deletions
				
			
		| 
						 | 
					@ -365,6 +365,8 @@ def least_squares(x, y, func, priors=None, silent=False, **kwargs):
 | 
				
			||||||
            if (chol_inv[1] != key_ls):
 | 
					            if (chol_inv[1] != key_ls):
 | 
				
			||||||
                raise ValueError('The keys of inverse covariance matrix are not the same or do not appear in the same order as the x and y values.')
 | 
					                raise ValueError('The keys of inverse covariance matrix are not the same or do not appear in the same order as the x and y values.')
 | 
				
			||||||
            chol_inv = chol_inv[0]
 | 
					            chol_inv = chol_inv[0]
 | 
				
			||||||
 | 
					            if np.any(np.diag(chol_inv) <= 0) or (not np.all(chol_inv == np.tril(chol_inv))):
 | 
				
			||||||
 | 
					                raise ValueError('The inverse covariance matrix inv_chol_cov_matrix[0] has to be a lower triangular matrix constructed from a Cholesky decomposition.')
 | 
				
			||||||
        else:
 | 
					        else:
 | 
				
			||||||
            corr = covariance(y_all, correlation=True, **kwargs)
 | 
					            corr = covariance(y_all, correlation=True, **kwargs)
 | 
				
			||||||
            inverrdiag = np.diag(1 / np.asarray(dy_f))
 | 
					            inverrdiag = np.diag(1 / np.asarray(dy_f))
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -223,6 +223,9 @@ def test_inv_cov_matrix_input_least_squares():
 | 
				
			||||||
            diff_inv_cov_combined_fit.gamma_method()
 | 
					            diff_inv_cov_combined_fit.gamma_method()
 | 
				
			||||||
            assert(diff_inv_cov_combined_fit.is_zero(atol=1e-12))
 | 
					            assert(diff_inv_cov_combined_fit.is_zero(atol=1e-12))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        with pytest.raises(ValueError):
 | 
				
			||||||
 | 
					            pe.least_squares(x_dict, data_dict, fitf_dict,  correlated_fit = True, inv_chol_cov_matrix = [corr,chol_inv_keys_combined_fit])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def test_least_squares_invalid_inv_cov_matrix_input():
 | 
					def test_least_squares_invalid_inv_cov_matrix_input():
 | 
				
			||||||
    xvals = []
 | 
					    xvals = []
 | 
				
			||||||
    yvals = []
 | 
					    yvals = []
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue