
where U and V are orthogonal, V' means V transposed, and
D is a diagonal matrix containing only the positive singular values
(as determined by tol
, see also fast.svd
).
The pseudoinverse, also known as Moore-Penrose or generalized inverse
is then obtained as
pseudoinverse(m, tol)
tol = max(dim(m))*max(D)*.Machine$double.eps
)iM %*% M - I
, where I is an appropriate
identity matrix, is minimized. For non-singular matrices the
pseudoinverse is equivalent to the standard inverse.solve
, fast.svd
# load corpcor library
library("corpcor")
# a singular matrix
m = rbind(
c(1,2),
c(1,2)
)
# not possible to invert exactly
try(solve(m))
# pseudoinverse
p = pseudoinverse(m)
p
# characteristics of the pseudoinverse
zapsmall( m %*% p %*% m ) == zapsmall( m )
zapsmall( p %*% m %*% p ) == zapsmall( p )
zapsmall( p %*% m ) == zapsmall( t(p %*% m ) )
zapsmall( m %*% p ) == zapsmall( t(m %*% p ) )
# example with an invertable matrix
m2 = rbind(
c(1,1),
c(1,0)
)
zapsmall( solve(m2) ) == zapsmall( pseudoinverse(m2) )
Run the code above in your browser using DataLab