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.
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 ofA
as returned bylinalg_svd()
. Alias forrtol
. 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.
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)
}
#> torch_tensor
#> 0.6886 0.2109 0.0239
#> 0.0302 0.1808 0.1159
#> 0.3785 0.2301 -0.3357
#> -0.4896 -0.6582 0.2559
#> -0.1375 -0.4979 0.0205
#> [ CPUFloatType{5,3} ]