I have latitudes and longitudes, so I need to redefine the RBF core to exp (-1/2 || sophere spance || ^ 2), which means I need to rewrite the 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 must be correct. But with the following tutorial, I get an error message:
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 complicated thing, I tried the sample code in the ksvm document:
k <- function(x,y) {(sum(x*y) +1)*exp(-0.001*sum((xy)^2))} class(k) <- "kernel"
But I get the same error.
Does anyone know how to correctly determine the kernel function?
source share