BioChemoinformatics BioChemoinformatics - 9 months ago 24
R Question

Inverse of square root of a PSD (positive semi-definite) matrix

Suppose I have a positive semi-definite matrix

S
and I would like to get the inverse of square root of this matrix, that is
S^(-1/2)
.

May I do like this?

ei <- eigen(S)
V <- ei$vectors
res <- V %*% diag(1 / sqrt(ei$values)) %*% t(V)


Is
res
equal to
S^(-1/2)
?

I just do
inverse of square root
for eigenvalue of
S
, is this correct?

I know that: if one wants to get
S^(1/2)
, then
res <- V %*% diag(sqrt(ei$values)) %*% t(V)
, which is
res = S^(1/2)
.

How about for
S^(-1/2)
?

Thanks.

Answer Source

Yes. We can easily take an example S and check that S times res times res is the identity matrix:

set.seed(123)
S <- crossprod(matrix(rnorm(9), 3))

ei <- eigen(S)
V <- ei$vectors
res <- V %*% diag(1 / sqrt(ei$values)) %*% t(V)

S %*% res %*% res
##             [,1]        [,2]        [,3]
## [1,]  1.0000e+00 -2.3731e-15 -1.6653e-16
## [2,]  3.3346e-15  1.0000e+00 -6.6613e-16
## [3,] -1.0235e-16  8.3267e-16  1.0000e+00