linalg_pinv {torch} | R Documentation |
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 |
rcond |
(float or Tensor, optional): the tolerance value to determine when is a singular value zero
If it is a |
hermitian |
(bool, optional): indicates whether |
atol |
the absolute tolerance value. When |
rtol |
the relative tolerance value. See above for the value it takes when |
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.
Note
This function uses linalg_svd()
if hermitian= FALSE
and
linalg_eigh()
if hermitian= TRUE
.
For CUDA inputs, this function synchronizes that device with the CPU.
Consider using linalg_lstsq()
if possible for multiplying a matrix on the left by
the pseudoinverse, as linalg_lstsq(A, B)$solution == A$pinv() %*% B
It is always prefered to use linalg_lstsq()
when possible, as it is faster and more
numerically stable than computing the pseudoinverse explicitly.
See Also
-
linalg_inv()
computes the inverse of a square matrix. -
linalg_lstsq()
computesA$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_triangular()
,
linalg_solve()
,
linalg_svdvals()
,
linalg_svd()
,
linalg_tensorinv()
,
linalg_tensorsolve()
,
linalg_vector_norm()
Examples
if (torch_is_installed()) {
A <- torch_randn(3, 5)
linalg_pinv(A)
}