复杂矩阵的行列式

复杂矩阵的行列式

本文介绍了PyTorch中复杂矩阵的行列式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种方法可以计算PyTroch中复杂矩阵的行列式?

Is there a way to calculate the determinant of a complex matrix in PyTroch?

torch.det

推荐答案

很遗憾,当前尚未实现.一种方法是实现您自己的版本,或仅使用 np.linalg.det .这是一个简短的函数,用于计算使用LU分解编写的复杂矩阵的行列式:

Unfortunately it's not implemented currently. One way would be to implement your own version or simply use np.linalg.det.Here is a short function which computes the determinant of a complex matrix that I wrote using LU-decomposition:

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)

这篇关于PyTorch中复杂矩阵的行列式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-25 23:11