gpt4 book ai didi

python - PyTorch 中复杂矩阵的行列式

转载 作者:行者123 更新时间:2023-12-04 03:55:51 25 4
gpt4 key购买 nike

有没有办法在 PyTorch 中计算复数矩阵的行列式?

torch.det 未针对“ComplexFloat”实现

最佳答案

很遗憾,目前还没有实现。一种方法是实现您自己的版本或简单地使用 np.linalg.det。这是一个简短的函数,它计算我使用 LU 分解编写的复数矩阵的行列式:

def complex_det(A):
def complex_diag(A):
return torch.view_as_complex(torch.stack((A.real.diag(), A.imag.diag()),dim=1))
#Perform LU decomposition to matrix A:
A_LU, pivots = A.lu()
P, A_L, A_U = torch.lu_unpack(A_LU, pivots)
#Det. of multiplied matrices is multiplcation of det.:
det = torch.prod(complex_diag(A_L)) * torch.prod(complex_diag(A_U)) * torch.det(P.real) #Could probably calculate det(P) [which is +-1] efficiently using Sylvester's determinant identity
return det
#Test it:
A = torch.view_as_complex(torch.randn(3,3,2))
complex_det(A)

关于python - PyTorch 中复杂矩阵的行列式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63928808/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com