tests/testthat/test-1D.R

cat("\ntest 1D optimization:")
# Deterministic toy example
fr <- function(v) {   ## Rosenbrock Banana function reduced to 1D
  10 * (1 - v^2)^2 + (1 - v)^2
}
set.seed(123)

# Initial parameter values, including duplicates. See ?init_grid.
parsp <- init_grid(lower=c(x=0),upper=c(x=2))

# add function values
simuls <- cbind(parsp,bb=apply(parsp,1,"fr"))

# optimization
bbresu <- bboptim(simuls)
print(bbresu)

# refine with additional points
while ( ! all(bbresu$conv_crits) ) {
  candidates <- rbb(bbresu)
  newsimuls <- cbind(candidates,bb=apply(candidates,1,"fr"))
  bbresu <- bboptim(rbind(bbresu$fit$data,newsimuls))
}

testthat::expect_equal(bbresu$optr$par,1,tolerance=1e-4)

Try the blackbox package in your browser

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

blackbox documentation built on May 3, 2023, 9:13 a.m.