YouTip LogoYouTip

Pytorch Torch Cholesky_Inverse

# PyTorch torch.cholesky_inverse Function * * Pytorch torch Reference Manual](#) `torch.cholesky_inverse` is a function in PyTorch used to calculate the inverse of a matrix using its Cholesky decomposition. It uses the result of the Cholesky decomposition to efficiently compute the inverse of the matrix. ### Function Definition torch.cholesky_inverse(L, upper=False, out=None) **Parameters**: * `L` (Tensor): Upper or lower triangular matrix obtained from Cholesky decomposition. * `upper` (bool, optional): If True, L is an upper triangular matrix; otherwise, it is a lower triangular matrix. Default is False. * `out` (Tensor, optional): Output tensor. **Return Value**: * `torch.Tensor`: Returns the inverse of the original matrix. * * * ## Usage Example ## Example import torch # Create a Symmetric Positive Definite Matrix A = torch.tensor([[4.0,2.0,2.0], [2.0,5.0,3.0], [2.0,3.0,6.0]], dtype=torch.float64) # Cholesky Decomposition L = torch.cholesky(A) # Compute Inverse Matrix Using Cholesky Decomposition A_inv = torch.cholesky_inverse(L) print("Original Matrix A:") print(A) print("nInverse Matrix A^-1:") print(A_inv) print("nvalidation: A @ A^-1 =") print(A @ A_inv) The output result is: Original matrix A: tensor([[4., 2., 2.], [2., 5., 3.], [2., 3., 6.]], dtype=torch.float64)Inverse matrix A^-1: tensor([[ 0.7500, -0.5000, -0.2500], [-0.5000, 1.0000, -0.0000], [-0.2500, -0.0000, 0.2500]], dtype=torch.float64)Verification: A @ A^-1 = tensor([[ 1.0000e+00, -1.4901e-08, 0.0000e+00], [-7.4506e-09, 1.0000e+00, 1.4901e-08], [ 0.0000e+00, 7.4506e-09, 1.0000e+00]], dtype=torch.float64) * * Pytorch torch Reference Manual](#)
← Pytorch Torch ChunkPytorch Torch Chain_Matmul β†’