posdefify {sfsmisc} | R Documentation |
From a matrix m
, construct a "close" positive definite
one.
posdefify(m, method = c("someEVadd", "allEVadd"), symmetric, eps.ev = 1e-07)
m |
a numeric (square) matrix. |
method |
a string specifying the method to apply; can be abbreviated. |
symmetric |
logical, simply passed to eigen . |
eps.ev |
number specifying the tolerance to use, see Details below. |
We form the eigen decomposition
m = V L V'
where L is the diagonal matrix of eigenvalues, L[j,j] = l[j], with decreasing eigenvalues l[1] >= l[2] >= ... >= l[n].
When the smallest eigenvalue l[n] are less than
Eps <- eps.ev * abs(lambda[1])
, i.e., negative or “almost
zero”, some or all eigenvalues are replaced by positive
(>= Eps
) values,
L~[j,j] = l~[j].
Then, m~ = V L~ V' is computed
and rescaled in order to keep the original diagonal (where that is
>= Eps
).
a matrix of the same dimensions and the “same” diagonal
(i.e. diag
) as m
but with the property to
be positive definite.
Martin Maechler
eigen
on which the current methods rely.
set.seed(12) m <- matrix(round(rnorm(25),2), 5, 5); m <- 1+ m + t(m); diag(m) <- diag(m) + 4 m posdefify(m) 1000 * zapsmall(m - posdefify(m))