def test_ch_inv_not_chol_given_upper(test_mat): """test ch_inv works with upper cholesky""" A = test_mat.A.copy() A_i = test_mat.A_i.copy() atol_loc1 = np.max(np.abs(A))*atol_rel_use atol_loc2 = np.max(np.abs(A_i))*atol_rel_use assert np.allclose(ch_inv(A,cholesky_given=False,lower=False),A_i,atol=atol_loc2,rtol=rtol_use) assert np.allclose(ch_inv(A_i,cholesky_given=False,lower=False),A,atol=atol_loc1,rtol=rtol_use)
def test_ch_inv_C_then_F_order(test_mat): """test ch_inv works switching orderings""" A = test_mat.A.copy() A_i = test_mat.A_i.copy() test_A1 = A.copy('C') atol_loc1 = np.max(np.abs(A))*atol_rel_use atol_loc2 = np.max(np.abs(A_i))*atol_rel_use assert np.allclose(ch_inv(test_A1,cholesky_given=False),A_i,atol=atol_loc2,rtol=rtol_use) assert np.allclose(A,test_A1,atol=atol_loc1,rtol=rtol_use) assert np.allclose(ch_inv(ch_inv(test_A1,cholesky_given=False),cholesky_given=False),A,atol=atol_loc1,rtol=rtol_use) assert np.allclose(ch_inv(A_i,cholesky_given=False),A,atol=atol_loc1,rtol=rtol_use)
def test_ch_inv_chol_given_lower(test_mat): """test ch_inv works with lower cholesky""" A_i = test_mat.A_i.copy() chol_i = test_mat.chol_i.copy() test_chol_i = chol_i.copy() atol_loc2 = np.max(np.abs(A_i))*atol_rel_use assert np.allclose(ch_inv(test_chol_i,cholesky_given=True,lower=True),A_i,atol=atol_loc2,rtol=rtol_use)
def test_cov_any_input_any_initial(fisher_params): """test get_covar consistency""" fab = fisher_params.fisher_input.fab.copy() cov = fisher_params.fisher_input.cov.copy() fisher = copy.deepcopy(fisher_params.fisher) cov_res1 = fisher.get_covar() atol_loc1 = np.max(np.abs(cov)) * atol_rel_use atol_loc2 = np.max(np.abs(fab)) * atol_rel_use assert np.all(cov_res1 == cov_res1.T) assert np.allclose(cov, cov_res1, atol=atol_loc1, rtol=rtol_use) assert np.allclose(ch_inv(cov_res1, lower=True), fab, atol=atol_loc2, rtol=rtol_use) assert np.allclose(ch_inv(fab, lower=True), cov_res1, atol=atol_loc1, rtol=rtol_use)
def __init__(self, fisher_in): """fisher_in: the fisher matrix""" self.fab = fisher_in self.cov = ch_inv(self.fab, cholesky_given=False, lower=True) self.chol_cov = cholesky_inplace(self.cov, inplace=False, lower=True) self.chol_cov_i = invert_triangular(self.chol_cov, lower=True)
def __init__(self, cov_in): """cov_in: the covariance matrix""" self.cov = cov_in self.chol_cov = cholesky_inplace(self.cov, inplace=False, lower=True) self.chol_cov_i = invert_triangular(self.chol_cov, lower=True) self.fab = ch_inv(self.cov, cholesky_given=False)