def tensor_from_eigs(evecs, evals, bvecs, bvals): """ Create a tensor from an eigen-vector/eigen-value combination, instead of from the q-form Parameters """ t_from_e = ozu.tensor_from_eigs(evals, evecs) T = Tensor(t_from_e, bvecs, bvals) return T
def test_decompose_tensor(): """ Testing the decomposition and recomposition of tensors from eigen-vectors and eigen-values """ # This is the self-diffusion tensor of water (according to Basser et # al. 1994): q1 = np.array([[1.7003, -0.041, 0.0027], [-0.041, 1.6388, -0.0036], [0.0027, -0.0036, 1.7007]]) evals1, evecs1 = ozu.decompose_tensor(q1) q2 = ozu.tensor_from_eigs(evals1, evecs1) npt.assert_almost_equal(q1, q2, decimal=2) evals2, evecs2 = ozu.decompose_tensor(q2) q3 = ozu.tensor_from_eigs(evals1, evecs2) npt.assert_almost_equal(q2,q3, decimal=2) # Let's see that we can do this many times: for i in range(1000): print i A = np.random.rand(9).reshape(3,3) # Make a symmetrical matrix (a 'tensor'): T1 = np.dot(A, A.T) evals, evecs = ozu.decompose_tensor(T1) Q = ozu.tensor_from_eigs(evals, evecs) evals_est, evecs_est = ozu.decompose_tensor(Q) # The result is always going to be equal, up to a sign reversal of one # of the vectors (why does this happen?): npt.assert_almost_equal(np.abs(evecs_est), np.abs(evecs), decimal=3)
def test_decompose_tensor(): """ Testing the decomposition and recomposition of tensors from eigen-vectors and eigen-values """ # This is the self-diffusion tensor of water (according to Basser et # al. 1994): q1 = np.array([[1.7003, -0.041, 0.0027], [-0.041, 1.6388, -0.0036], [0.0027, -0.0036, 1.7007]]) evals1, evecs1 = ozu.decompose_tensor(q1) q2 = ozu.tensor_from_eigs(evals1, evecs1) npt.assert_almost_equal(q1, q2, decimal=2) evals2, evecs2 = ozu.decompose_tensor(q2) q3 = ozu.tensor_from_eigs(evals1, evecs2) npt.assert_almost_equal(q2, q3, decimal=2) # Let's see that we can do this many times: for i in range(1000): print i A = np.random.rand(9).reshape(3, 3) # Make a symmetrical matrix (a 'tensor'): T1 = np.dot(A, A.T) evals, evecs = ozu.decompose_tensor(T1) Q = ozu.tensor_from_eigs(evals, evecs) evals_est, evecs_est = ozu.decompose_tensor(Q) # The result is always going to be equal, up to a sign reversal of one # of the vectors (why does this happen?): npt.assert_almost_equal(np.abs(evecs_est), np.abs(evecs), decimal=3)