Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201839

(R-3.5.3 mlrMBO) Error in generateDesign(control$infill.opt.focussearch.points, ps.local, :

$
0
0

I had an issue when I use mlrMBO(1.1.2) in R-3.5.3 to optimize my function, anyone know why? many thanks!

THE ERROR:

Error in generateDesign(control$infill.opt.focussearch.points, ps.local,  : 
REAL() can only be applied to a 'numeric', not a 'NULL'
Calls: mbo ... measureTime -> force -> infill.opt.fun -> generateDesign

SOURCE CODE:

library(kernlab)
library(DiceKriging)
library(caret)
library(mlrMBO)
library(pROC)
library(e1071)
library(doParallel)

# trainingset <- read.csv("trainingset.csv")
# train_x <- trainingset[, c(-1)]
# train_y <- factor(trainingset[, "inhibitor"], levels = c(0, 1), labels = c("noninhibitor", "inhibitor")) 
# testset <- read.csv("testset.csv")
# test_x <- testset[, c(-1)]
# test_y <- factor(testset[, "inhibitor"], levels = c(0, 1), labels = c("noninhibitor", "inhibitor")) 

trainingset <- read.csv("bcrp_inhibition_tr.csv")
train_x <- trainingset[, c(-1)]
train_y <- factor(trainingset[, "classification"], levels = c("noninhibitor", "inhibitor")) 
testset <- read.csv("bcrp_inhibition_te.csv")
test_x <- testset[, c(-1)]
test_y <- factor(testset[, "classification"], levels = c("noninhibitor", "inhibitor")) 

cl <- 6
registerDoParallel(cl) 
getDoParWorkers()

set.seed(123)
seeds <- vector(mode = "list", length = 6) 
for (i in 1:5) seeds[[i]] <- sample.int(1000, 1) 
seeds[[6]] <- sample.int(1000, 1) 
k <- 666666

method.name <- "svmRadial";

parameters <- c("sigma", "C");

fun <- function(x){
  set.seed(k);
  Model <- caret::train(train_x, train_y, method = method.name, trControl = trainControl(method = "cv", number = 5, classProbs = T, savePredictions = "final", seeds = seeds), tuneGrid = data.frame(sigma = x[1], C = x[2]));
  train_cv.tab <- table(Model$pred$pred, Model$pred$obs);
  train_cv.TP <- train_cv.tab[2, 2];train_cv.FP <- train_cv.tab[2, 1];train_cv.FN <- train_cv.tab[1, 2];train_cv.TN <- train_cv.tab[1, 1];
  train_cv.MCC <- as.numeric((train_cv.TP*train_cv.TN - train_cv.FP*train_cv.FN)/sqrt((train_cv.TP + train_cv.FP) %*% (train_cv.TP + train_cv.FN) %*% (train_cv.TN + train_cv.FP) %*% (train_cv.TN + train_cv.FN)));
  1 - train_cv.MCC 
}

objfun <- makeSingleObjectiveFunction(
  name <- paste(method.name, "_boa", sep = ""), 
  fn = fun, 
  par.set = makeParamSet(
    makeNumericParam(parameters[1], lower = 0.005, upper = 0.02), 
    makeNumericParam(parameters[2], lower = 5, upper = 20)
  ), 
  minimize = T
)

surr.km <- makeLearner("regr.km", predict.type = "se", covtype = "matern3_2", control = list(trace = F)) 

control <- makeMBOControl()
control <- setMBOControlInfill(
  control = control, 
  crit = makeMBOInfillCritEI(), 
  opt.focussearch.points = 500
)

control <- setMBOControlTermination(
  control = control, 
  iters = 500
)

design <- generateDesign(n = 200, par.set = getParamSet(objfun))

mlr::configureMlr(show.info = F, show.learner.output = F, on.learner.warning = "quiet")
run <- mbo(objfun, design = design, learner = surr.km, control = control, show.info = T)

THE LOG:

Computing y column(s) for design. Not provided.
[mbo] 0: sigma=0.0101; C=9.88 : y = 0.215 : 14.6 secs : initdesign
[mbo] 0: sigma=0.0152; C=12.6 : y = 0.218 : 13.8 secs : initdesign
[mbo] 0: sigma=0.00712; C=12.2 : y = 0.221 : 9.4 secs : initdesign
......
......
......
[mbo] 409: sigma=0.0185; C=11.6 : y = 0.215 : 14.1 secs : infill_ei
[mbo] 410: sigma=0.0196; C=12.7 : y = 0.219 : 14.1 secs : infill_ei
[mbo] 411: sigma=0.0185; C=14.9 : y = 0.218 : 13.7 secs : infill_ei
[mbo] 412: sigma=0.0167; C=14.3 : y = 0.218 : 13.3 secs : infill_ei
[mbo] 413: sigma=0.00621; C=14.4 : y = 0.228 : 8.3 secs : infill_ei
[mbo] 414: sigma=0.0193; C=8.45 : y = 0.214 : 14.4 secs : infill_ei
Error in generateDesign(control$infill.opt.focussearch.points, ps.local,  : 
REAL() can only be applied to a 'numeric', not a 'NULL'
Calls: mbo ... measureTime -> force -> infill.opt.fun -> generateDesign

Viewing all articles
Browse latest Browse all 201839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>