Commit b4f53855 authored by Asquith, William H.'s avatar Asquith, William H.

added the the.cvm, cigma, and cigmainfo for computation of a type of cross-validated error

parent 80122276
......@@ -335,20 +335,31 @@
}
if(doEN) { dat$east <- east; dat$north <- north }
if(do.not.use.sin.cosine.in.svm.under.anycase) trigUsed <- FALSE
ix <- sample(1:length(x), as.integer(ksvm.cigma.fraction*length(x)), replace=FALSE)
ix <- sort(ix)
cat <- NULL
if(length(ix) >= minimum.sample.for.svm) cat <- dat
dat <- scale(dat)
the.svm <- NULL
the.cvm <- NULL
if(length(newx) >= minimum.sample.for.svm) {
if(trigUsed) {
if(! doEN) {
try(the.svm <- ksvm(y~x+sine+cosine, data=dat, C=ksvm.cost.parameter), silent=silent)
try(the.svm <- ksvm(y~x+sine+cosine, data=dat, C=ksvm.cost.parameter, epsilon=ksvm.epsilon.parameter), silent=silent)
if(! is.null(cat)) try(the.cvm <- ksvm(y~x+sine+cosine, data=cat[ix,], C=ksvm.cost.parameter, epsilon=ksvm.epsilon.parameter), silent=silent)
} else {
try(the.svm <- ksvm(y~x+sine+cosine+east+north, data=dat, C=ksvm.cost.parameter), silent=silent)
try(the.svm <- ksvm(y~x+sine+cosine+east+north, data=dat, C=ksvm.cost.parameter, epsilon=ksvm.epsilon.parameter), silent=silent)
if(! is.null(cat)) try(the.cvm <- ksvm(y~x+sine+cosine+east+north, data=cat[ix,], C=ksvm.cost.parameter, epsilon=ksvm.epsilon.parameter), silent=silent)
}
} else {
if(! doEN) {
try(the.svm <- ksvm(y~x, data=dat, C=ksvm.cost.parameter), silent=silent)
try(the.svm <- ksvm(y~x, data=dat, C=ksvm.cost.parameter, epsilon=ksvm.epsilon.parameter), silent=silent)
if(! is.null(cat)) try(the.cvm <- ksvm(y~x, data=cat[ix,], C=ksvm.cost.parameter, epsilon=ksvm.epsilon.parameter), silent=silent)
} else {
try(the.svm <- ksvm(y~x+east+north, data=dat, C=ksvm.cost.parameter), silent=silent)
try(the.svm <- ksvm(y~x+east+north, data=dat, C=ksvm.cost.parameter, epsilon=ksvm.epsilon.parameter), silent=silent)
if(! is.null(cat)) try(the.cvm <- ksvm(y~x+east+north, data=cat[ix,], C=ksvm.cost.parameter, epsilon=ksvm.epsilon.parameter), silent=silent)
}
}
} else {
......@@ -358,31 +369,44 @@
ovl <- isSVM.OverLearned(x)
if(testOverLearn & ovl) {
zz <- list(svm=NULL, residuals=rep(NA, length(newx)), data=dat, use.east.and.north=doEN,
outliers=rep(NA, length(newx)), sigma=NA, trigUsed=FALSE, overLearned=TRUE)
outliers=rep(NA, length(newx)), sigma=NA, trigUsed=FALSE, overLearned=TRUE,
cigmainfo=rep(NA,3))
assign(svm.name, zz, envir=visGWDBenv)
return(zz)
}
if(is.null(the.svm)) {
zz <- list(svm=NULL, residuals=rep(NA, length(newx)), data=dat, use.east.and.north=doEN,
outliers=rep(NA, length(newx)), sigma=NA, trigUsed=FALSE, overLearned=NA)
outliers=rep(NA, length(newx)), sigma=NA, trigUsed=FALSE, overLearned=NA,
cigmainfo=rep(NA,3))
assign(svm.name, zz, envir=visGWDBenv)
return(zz)
}
cigma <- NA
if(! is.null(cat)) {
cred <- predict(the.cvm, cat[-ix,])
cesiduals <- y[-ix] - cred[,1]
cigma <- sqrt( sum(cesiduals^2, na.rm=TRUE) / (length(cesiduals[! is.na(cesiduals)])) )
}
#M <- attr(dat,"scaled:scale" )[1]
#B <- attr(dat,"scaled:center")[1]
pred <- postSVMprediction_of_Y(predict(the.svm), dat) # M*predict(the.svm)+B)
pred <- pred[,1]
residuals <- y - pred
sigma <- sqrt( sum(residuals^2, na.rm=TRUE) / (length(residuals[! is.na(residuals)])) )
delfit <- qt(0.99, df=length(residuals[! is.na(residuals)])-1)*sigma
fitlwr <- pred - delfit; fitupr <- pred + delfit
outliers <- y < fitlwr | y > fitupr
outliers[abs(residuals) < min.outlier.abs.residual] <- FALSE
zz <- list(svm=the.svm, residuals=residuals, data=dat, use.east.and.north=doEN,
outliers=outliers, sigma=sigma, trigUsed=trigUsed, overLearned=ovl)
outliers=outliers, sigma=sigma, trigUsed=trigUsed, overLearned=ovl,
cigmainfo=c(sigma,cigma,cigma/sigma))
assign(svm.name, zz, envir=visGWDBenv)
# potentially put another test here for overlearning on the residuals?
#print(head(zz))
return(zz)
}
#tmp.data <- stats_SVM(as.numeric(TMP$LEV_DT), lev, TMP$FRAC_YEAR, silent=FALSE)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment