correction of a bug in gauss kernel computation

This commit is contained in:
Pierre-Edouard Portier 2023-02-20 09:41:21 +01:00
parent 97412812bd
commit cee77bc88c
1 changed files with 4 additions and 3 deletions

View File

@ -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)
}
}