lucid.linalg.det¶
The det function computes the determinant of a square matrix.
Function Signature¶
def det(a: Tensor) -> Tensor
Parameters¶
- a (Tensor):
The input tensor, which must be a square matrix (same number of rows and columns).
Returns¶
- Tensor:
A tensor containing the determinant of the input matrix.
Forward Calculation¶
The forward calculation for det is:
where \(\mathbf{A}\) is the input square matrix.
Backward Gradient Calculation¶
For a tensor \(\mathbf{A}\), the gradient of the determinant with respect to the input is given by:
This involves the determinant and inverse of the matrix \(\mathbf{A}\), and the gradients are propagated accordingly during backpropagation.
Raises¶
Attention
ValueError: If the input tensor is not a square matrix.
LinAlgError: If the determinant cannot be computed (e.g., for singular or ill-conditioned matrices).
Example¶
>>> import lucid
>>> a = lucid.Tensor([[1.0, 2.0], [3.0, 4.0]])
>>> det_a = lucid.linalg.det(a)
>>> print(det_a)
Tensor(-2.0)
Note
The determinant is a scalar value that describes certain properties of a matrix, such as whether it is invertible.
The input tensor must have two dimensions and be square, i.e., \(a.shape[0] == a.shape[1]\).