diff options
| author | Gertjan van den Burg <gertjanvandenburg@gmail.com> | 2018-03-28 13:41:14 +0100 |
|---|---|---|
| committer | Gertjan van den Burg <gertjanvandenburg@gmail.com> | 2018-03-28 13:41:14 +0100 |
| commit | 75d6ed3e5d919b4e5b7bd1e81283131c92530d26 (patch) | |
| tree | 907f9de5769412c25e61d0c67a50089e6d8e1d6e /R/gensvm.grid.R | |
| parent | Make sure we use "weights" everywhere instead of "weight" (diff) | |
| download | rgensvm-75d6ed3e5d919b4e5b7bd1e81283131c92530d26.tar.gz rgensvm-75d6ed3e5d919b4e5b7bd1e81283131c92530d26.zip | |
Validate params in gensvm() function
Parameter validation was only done for some parameters in the
gensvm() function and for the parameter grid in gensvm.grid()
With this commit the parameters will be tested properly for
both functions.
Diffstat (limited to 'R/gensvm.grid.R')
| -rw-r--r-- | R/gensvm.grid.R | 35 |
1 files changed, 2 insertions, 33 deletions
diff --git a/R/gensvm.grid.R b/R/gensvm.grid.R index 2acdc2f..f954b79 100644 --- a/R/gensvm.grid.R +++ b/R/gensvm.grid.R @@ -162,7 +162,8 @@ gensvm.grid <- function(X, y, param.grid='tiny', refit=TRUE, scoring=NULL, cv=3, } # Validate the range of the values for the gridsearch - gensvm.validate.param.grid(param.grid) + if (!gensvm.validate.param.grid(param.grid)) + return(NULL) # Sort the parameter grid for efficient warm starts param.grid <- gensvm.sort.param.grid(param.grid) @@ -379,38 +380,6 @@ gensvm.generate.cv.idx <- function(n, folds) return(cv.idx) } -gensvm.validate.param.grid <- function(df) -{ - expected.colnames <- c("kernel", "coef", "degree", "gamma", "weight", - "kappa", "lambda", "p", "epsilon", "max.iter") - for (name in colnames(df)) { - if (!(name %in% expected.colnames)) { - stop("Invalid header name supplied in parameter grid: ", name) - } - } - - conditions <- list( - p=function(x) { x >= 1.0 && x <= 2.0 }, - kappa=function(x) { x > -1.0 }, - lambda=function(x) {x > 0.0 }, - epsilon=function(x) { x > 0.0 }, - gamma=function(x) { x != 0.0 }, - weight=function(x) { x %in% c("unit", "group") }, - kernel=function(x) { x %in% c("linear", "poly", "rbf", "sigmoid") } - ) - - for (idx in 1:nrow(df)) { - for (param in colnames(df)) { - if (!(param %in% names(conditions))) - next - func <- conditions[[param]] - value <- df[[param]][idx] - if (!func(value)) - stop("Invalid value in grid for parameter: ", param) - } - } -} - gensvm.cv.results <- function(results, param.grid, cv.idx, y.true, scoring, return.train.score=TRUE) { |
