tests/testthat/test.optim.R

context("Optim")

test_that("check optimizer are evaluated without errors", {
    ## test optimDE.R: it should generate the same results as the original DEoptim() function
    skip_on_cran() 
    Rosenbrock <- function(x) {
        100 * (x[2] - x[1] * x[1]) ^ 2 + (1 - x[1]) ^ 2
    }
    set.seed(1234)
    resDE <-
        DEoptim(
            Rosenbrock,
            lower = c(-10,-10),
            upper = c(10, 10),
            DEoptim.control(
                VTR = -Inf,
                strategy = 2,
                bs = FALSE,
                NP = 20,
                itermax = 28,
                CR = 0.7,
                F = 1.2,
                trace = FALSE,
                p = 0.2,
                c = 0,
                reltol = sqrt(.Machine$double.eps),
                steptol = 200,
                parallelType = 0
            )
        )
    set.seed(1234)
    resSPOT <- optimDE(
        ,
        fun = funRosen,
        lower = c(-10,-10),
        upper = c(10, 10),
        control = list(
            populationSize = 20,
            funEvals = 580,
            F = 1.2,
            CR = 0.7
        )
    )
    expect_equal(resDE$optim$bestval , as.double(resSPOT$ybest))
})


test_that("check logging", {
  res <- spot(x=NULL,
              funMoo,
              lower = c(1,2),
              upper = c(10,20),
              control=list(funEvals=15, 
                           noise = TRUE,
                           verbosity=0,
              # optimizer=optimDE,
              optimizer = optimLHD,
              plots = FALSE,
              progress = TRUE,
              seedFun = 1, # mandatory for multi-dim responses
              noise = TRUE,
              seedSPOT = 1,
              model = buildRandomForest
              )
  )
expect_equal(sum(res$y + res$logInfo),0)
})

Try the SPOT package in your browser

Any scripts or data that you put into this service are public.

SPOT documentation built on June 26, 2022, 1:06 a.m.