set.seed(102941)

nobs <- 500
sdv <- 1.0

x <- seq(-1,1,length=nobs)
f <- 6*x^3 + 1.5*sin(11*x)*exp(-x^2*6)
f <- 1.4*f

out <- cbind(x,f)
write(t(out),file="bv_tru.dat",ncol=ncol(out))

e <- rnorm(n=nobs,mean=0.0,sd=sdv)
y <- f + e
out <- cbind(x,y)
write(t(out),file="bv_lrn.dat",ncol=ncol(out))

e <- rnorm(n=nobs,mean=0.0,sd=sdv)
y <- f + e
out <- cbind(x,y)
write(t(out),file="bv_val.dat",ncol=ncol(out))

lrn <- read.table("bv_lrn.dat",
         header=F,colClasses="numeric",col.names=c("x","y"))
val <- read.table("bv_val.dat",
         header=F,colClasses="numeric",col.names=c("x","y"))
tru <- read.table("bv_tru.dat",
         header=F,colClasses="numeric",col.names=c("x","f"))

x <- lrn$x
y <- lrn$y
f <- tru$f
e <- y - f

source("psopts.r")

postscript(file="bv_lrn.eps")

plot(x=x,y=y,type="n",xlab="feature",ylab="target")
points(x=x,y=y,pch="o",cex=0.5)

dev.off()

postscript(file="bv_tru.eps")

plot(x=x,y=y,type="n",xlab="feature",ylab="target")
points(x=x,y=y,pch="o",cex=0.5)
lines(x=x,y=f,type="l",lty="solid",col="blue",lwd=2)

dev.off()
