【发布时间】:2013-06-08 00:13:36
【问题描述】:
我有经纬度,所以需要将RBF内核重新定义为exp(-1/2||sophere distrance||^2),也就是说我需要自己重写一个内核函数。 我写我的内核如下:
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"
我测试了函数,内核应该是正确的。但是使用以下训练命令我得到了错误:
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.
比较棘手的是,我尝试了ksvm文档中的示例代码:
k <- function(x,y) {(sum(x*y) +1)*exp(-0.001*sum((x-y)^2))}
class(k) <- "kernel"
但我遇到了同样的错误。
有人知道如何正确定义核函数吗?
【问题讨论】:
-
这真的很有帮助。你能解释一下你是如何推导出核函数的吗?我看不出 exp(-1/2||sphere distnace||^2) 与您如何完成
res之间的联系。 -
@momeara,我认为它基本上是基于三角形函数的,所以可以有多种方法使用arctan、arcsin,或者像atan2。检查此链接:movable-type.co.uk/scripts/latlong.html
-
这个例子对我有用。