0
$\begingroup$

Related to this question, but adding a nugget isn't helping. Possibly I'm just making a silly coding mistake:

x <- cbind(runif(5),runif(5))
d <- dist(x)
k <- exp(-d^2)
chol(k)
# Error in chol.default(k) :
#    the leading minor of order 1 is not positive definite

Adding a nugget doesn't help:

k <- as.matrix(k)
diag(k) <- diag(k) + 0.1
chol(k)
# Error in chol.default(k) :
#   the leading minor of order 1 is not positive definite

What am I doing wrong here with my squared exponential kernel so that it isn't positive definite?

$\endgroup$
1
  • $\begingroup$ k <- exp(-as.matrix(d)^2) might help $\endgroup$
    – Henry
    Commented Aug 24, 2023 at 23:01

1 Answer 1

2
$\begingroup$
> as.matrix(k)
          1         2         3         4         5
1 0.0000000 0.8305698 0.6825535 0.8021312 0.7282046
2 0.8305698 0.0000000 0.8834873 0.6476372 0.6340222
3 0.6825535 0.8834873 0.0000000 0.3842710 0.3584702
4 0.8021312 0.6476372 0.3842710 0.0000000 0.9839804
5 0.7282046 0.6340222 0.3584702 0.9839804 0.0000000

The dist function gives a triangular structure with no diagonal and converting it to a matrix inside chol.default gives zeroes on the diagonal. You need to fix up the diagonal.

$\endgroup$
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.