Learn R Programming

torch (version 0.8.1)

linalg_pinv: Computes the pseudoinverse (Moore-Penrose inverse) of a matrix.

Description

The pseudoinverse may be defined algebraically_ but it is more computationally convenient to understand it through the SVD_ Supports input of float, double, cfloat and cdouble dtypes. Also supports batches of matrices, and if A is a batch of matrices then the output has the same batch dimensions.

Usage

linalg_pinv(A, rcond = NULL, hermitian = FALSE, atol = NULL, rtol = NULL)

Arguments

A

(Tensor): tensor of shape (*, m, n) where * is zero or more batch dimensions.

rcond

(float or Tensor, optional): the tolerance value to determine when is a singular value zero If it is a torch_Tensor, its shape must be broadcastable to that of the singular values of A as returned by linalg_svd(). Alias for rtol. Default: 0.

hermitian

(bool, optional): indicates whether A is Hermitian if complex or symmetric if real. Default: FALSE.

atol

the absolute tolerance value. When NULL it’s considered to be zero.

rtol

the relative tolerance value. See above for the value it takes when NULL.

Details

If hermitian= TRUE, A is assumed to be Hermitian if complex or symmetric if real, but this is not checked internally. Instead, just the lower triangular part of the matrix is used in the computations. The singular values (or the norm of the eigenvalues when hermitian= TRUE) that are below the specified rcond threshold are treated as zero and discarded in the computation.

See Also

  • linalg_inv() computes the inverse of a square matrix.

  • linalg_lstsq() computes A$pinv() %*% B with a numerically stable algorithm.

Other linalg: linalg_cholesky_ex(), linalg_cholesky(), linalg_det(), linalg_eigh(), linalg_eigvalsh(), linalg_eigvals(), linalg_eig(), linalg_householder_product(), linalg_inv_ex(), linalg_inv(), linalg_lstsq(), linalg_matrix_norm(), linalg_matrix_power(), linalg_matrix_rank(), linalg_multi_dot(), linalg_norm(), linalg_qr(), linalg_slogdet(), linalg_solve(), linalg_svdvals(), linalg_svd(), linalg_tensorinv(), linalg_tensorsolve(), linalg_vector_norm()

Examples

Run this code
if (torch_is_installed()) {
A <- torch_randn(3, 5)
linalg_pinv(A)
}

Run the code above in your browser using DataLab