Proper use of the rod in the Cholesky decomposition of a positive semidefinite matrix

I do not understand how to use the chol function in R to determine a positive semidefinite matrix. (Or I, and there is an error.) The documentation reads:

If pivot = TRUE, then we can calculate the Cholesky decomposition of a positive semidefinite x. The rank x is returned as attr (Q, "rank"), taking into account numerical errors. The top returns as attr (Q, "pivot"). It is no longer the case that t (Q)% *% Q is equal to x. However, setting the hinge <- attr (Q, "rotation") and oo (axis of rotation), it is true that t (Q [, oo])% *% Q [, oo] is equal to x ...

The following example seems to contradict this description.

 > x <- matrix(1, nrow=3, ncol=3) > Q <- chol(x, pivot=TRUE) > oo <- order(attr(Q, 'pivot')) > t(Q[, oo]) %*% Q[, oo] [,1] [,2] [,3] [1,] 1 1 1 [2,] 1 1 1 [3,] 1 1 3 

The result is not x . Am I using an anchor point incorrectly?

+5
source share
1 answer

To enter the full rank, i.e. positively defined matrix x , we need

 Q <- chol(x, TRUE) oo <- order(attr(Q, 'pivot')) unpivQ <- Q[, oo] all.equal(crossprod(unpivQ), x) 

For an acceptable rank deficit of input, i.e. positive semidefinite matrix x (an indefinite matrix with negative eigenvalues ​​is illegal, but not checked in chol ), do not forget the zero defective final diagonal block:

 Q <- chol(x, TRUE) r <- attr(Q, 'rank') if (r < nrow(x)) Q[(r+1):nrow(x), (r+1):nrow(x)] <- 0 oo <- order(attr(Q, 'pivot')) unpivQ <- Q[, oo] all.equal(crossprod(unpivQ), x) 

Some people call this the β€œerror” chol , but it’s actually a function of the basic LAPACK dpstrf procedure. Factorization continues until the first diagonal element, which is below the tolerance, leaving the back matrix just untouched upon exit.


Thanks to Jan for the following observation:

You can use negative indexing R in Q[-(1:r): -(1:r)] <- 0 to skip the if .

+4
source

Source: https://habr.com/ru/post/1266132/


All Articles