From cee77bc88c7c48dd7a958cf2c465436dfa98b340 Mon Sep 17 00:00:00 2001 From: Pierre-Edouard Portier Date: Mon, 20 Feb 2023 09:41:21 +0100 Subject: [PATCH] correction of a bug in gauss kernel computation --- 19_nystroem_approximation_code.R | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/19_nystroem_approximation_code.R b/19_nystroem_approximation_code.R index b289f03..c0a534b 100644 --- a/19_nystroem_approximation_code.R +++ b/19_nystroem_approximation_code.R @@ -8,7 +8,7 @@ function(X1, X2, sigma2) K <- matrix(nrow = n1, ncol = n2) for(i in 1:n1) for(j in 1:n2) - K[i,j] <- sum(X1[i,] - X2[j,])^2 + K[i,j] <- sum((X1[i,] - X2[j,])^2) K <- exp(-1*K/sigma2) } @@ -39,7 +39,8 @@ function(X, y, sigma2=NULL, lambda=1E-4, landmarks=NULL, nb.landmarks=NULL) svdK11 <- svd(K11) # K11 will often be ill-formed, thus we drop the bottom singular values - k <- which(svdK11$d < 1E-12)[1] - 1 + ks <- which(svdK11$d < 1E-12) + if (length(ks)>0) {k <- ks[1]} else {k <- length(svdK11$d)} US <- svdK11$u[,1:k] %*% diag(1 / sqrt(svdK11$d[1:k])) L <- C %*% US @@ -109,4 +110,4 @@ function(X, y, K=5, lambdas=NULL, sigma2=NULL, landmarks=NULL, nb.landmarks=NULL minmmaes <- min(mmaes) bestlambda <- lambdas[which(mmaes == minmmaes)] nakrm <- nakr(X, y, sigma2, bestlambda, landmarks, nb.landmarks) -} \ No newline at end of file +}