I have latitudes and longitudes, so I need to redefine the RBF kernel into exp(-1/2||sophere distrance||^2), which means I need to rewrite a kernel function myself. I write my kernel as follows:
round.kernel <- function(x,y){
sigma <- 1
#R <- 6371
R <- 1
a <- (sin( (x[1]-y[1])/2 ))^2+cos(x[1])*cos(y[1])*(sin((x[2]-y[2])/2))^2
c <- 2*atan2(sqrt(a),sqrt(1-a))
d <- R*c
res <- exp(-d^2/(2*sigma))
return (res)
}
class(round.kernel) <- "kernel"
I tested the function, the kernel should be correct. But with the following training command I am getting the error:
fit <- ksvm(y=train[,2],x=train[,3:4],kernel=round.kernel,type='eps-svr')
Error in .local(x, ...) :
List interface supports only the stringdot kernel.
The more trickly thing is, I tried the sample code in ksvm document:
k <- function(x,y) {(sum(x*y) +1)*exp(-0.001*sum((x-y)^2))}
class(k) <- "kernel"
But I am getting the same error.
Anyone knows how to correctly define a kernel function?