Skip to content

Instantly share code, notes, and snippets.

@chiral
Created October 15, 2011 13:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chiral/1289543 to your computer and use it in GitHub Desktop.
Save chiral/1289543 to your computer and use it in GitHub Desktop.
examination of how sigma parameters in RBF kernel affect results.
# ガウスカーネルのσパラメータの意味を調べるテスト
# examination of how sigma parameters in RBF kernel affect results.
# resulting image is,
# http://dl.dropbox.com/u/15259519/images/RBF_sigma.swf
sr <- function() source('RBF_sigma_test.R')
library(kernlab)
N <<- 100
sigmas <<- c(0.0001,0.0005,0.001,0.005,0.01,0.05,0.1,0.5,1,5,10,50)
space <- function(n) {
s<-''; for (i in 1:n) s<-paste(s,' ',sep=''); return(s)
}
plot1<-function(x,y,r,rc) {
plot(x,y)
par(new=T)
plot(x,r,type='n',axes=F)
text(x,r,substr(rc,0,1))
title(main='y=sin(x)')
}
plot2<-function(sigma,k,df) {
plot(k,data=df)
title(main=paste(space(55),'σ =',sigma))
}
main<-function() {
x<-seq(0,2*pi,length=N)
y<-sin(x)
r<-runif(N,-1,1)
r_class<-factor(r>=y)
plot1(x,y,r,r_class);
png(file='sin_x.png',width=640,height=480)
plot1(x,y,r,r_class)
dev.off()
df<-data.frame(x=x,y=r)
for (sigma in sigmas) {
readline('please enter key to proceed, ...')
k <- ksvm(r_class~r+x,kernel='rbfdot',kpar=list(sigma=sigma))
plot2(sigma,k,df)
file<-paste('RBF_sigma_',sigma,sep='')
file<-sub("[.]","_",file)
file<-paste(file,'png',sep='.')
print(paste("write to",file))
png(file=file,width=640,height=480);
plot2(sigma,k,df)
dev.off()
}
}
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment