Sign and natural log of the absolute determinant.
Returns the pair such that
Stays correct where itself leaves the floating-point range — large or small covariance matrices in log-likelihood calculations, or any matrix whose determinant would overflow to or underflow to .
Parameters
(*, n, n).Returns
Tensor (or for singular matrices), shape
(*,).
Notes
Computed from the LU factorisation as
, with the sign the product
of the signs of and of the permutation — the
determinant itself is never formed, so nothing here can overflow. Cost
is . A zero pivot makes the matrix singular: the sign is
the signed zero would be, and logabsdet is
.
The gradient of logabsdet is , solved from the LU
factors of the value was read from rather than formed as
, so it stays finite wherever the matrix is
invertible — and a matrix the factorisation found a nonzero last pivot
for, however small, has a (large) gradient instead of an error. At a
singular matrix it is —
along the adjugate of a matrix of rank .
Examples
>>> import lucid
>>> from lucid.linalg import slogdet
>>> sign, logabs = slogdet(lucid.tensor([[1.0, 2.0], [3.0, 4.0]]))
>>> sign, logabs
(tensor(-1.), tensor(0.6931))