loelschlaeger / ao

Alternating optimization in R
http://loelschlaeger.de/ao/
GNU General Public License v3.0
2 stars 2 forks source link

Issue of passing fixed function argument that is `NULL` #4

Closed loelschlaeger closed 8 months ago

loelschlaeger commented 8 months ago

Issue of passing an argument to the objective function that is NULL, for example the following leads to the error message "Error: Function evaluation threw an error: argument "ind" is missing, with no default".

stopifnot(packageVersion("ao") == "0.3.1", packageVersion("optimizeR") == "1.0.3")

f <- function(x, a, b, ind) {
  if (is.null(ind)) {
    (x[1]^2 + x[2] + a)^2 + (x[1] + x[2]^2 + b)^2 + (x[3] - 1)^2
  }
}

base_optimizer <- optimizeR::optimizer_nlm()

a <- -11

b <- -7

partition <- list(1, 2:3)

ao::ao(
  f = f,
  p = c(0, 0, 0),
  a = a,
  b = b,
  ind = NULL,
  partition = partition,
  base_optimizer = optimizeR::optimizer_nlm(),
  iterations = 10,
  tolerance = 1e-06,
  verbose = TRUE
)