Only length-1 columns are recycled

I am working with R. I am trying to follow the example from this page (Function Maximization) on optimization - I tried to make a new example for a function with "multiple inputs".

For example:

#load necessary library
library(ParBayesianOptimization)

#define function to be optimized
bayesian_function <- function(x1, x2, x3, x4) {
    var_1 <- sin(x1 + x2)
    var_2 <- cos(x1 - x2)
    var_3 <- x1 + x4
    var_4 <- x3 + x4 -7
    goal = sum(var_1 + var_2 + var_3 + var_4)

    return(goal)

}

}


FUNwrapper <- function(x1,x2,x3,x4) list(
    "Score"=bayesian_function(x1=x1,
                              x2=x2,
                              x3=x3,
                              x4=x4)
)

#specify bounds
bounds <- list(x1 =c(20,40), x2 = c(30,45), x3 = c(10,20), x4 = c(10,50))

#run optimization algorithm
optObj <- bayesOpt(
    FUN = FUNwrapper
    , bounds = bounds
    , initPoints = 10
    , acq = "ei"
    , iters.n = 2
    , gsPoints = 25
)

When I look at the output for this example, it is indicated that the optimization algorithm did not converge:

Running initial scoring function 10 times in 1 thread(s)...  2.71 seconds


Starting Epoch 3 
  1) Fitting Gaussian Process...
  2) Running local optimum search...
     - Convergence Not Found. Trying again with tighter parameters...        0.5 seconds
  3) Running FUN 1 times in 1 thread(s)...  0.28 seconds

Therefore, I tried to increase the number of iterations so that the algorithm might be able to find a better point:

#increase the number of iterations
optObj <- bayesOpt(
    FUN = bayesian_function
    , bounds = bounds
    , initPoints = 1000
    , acq = "ei"
    , iters.n = 10
    , gsPoints = 25
)

But this produces the following error:

Running initial scoring function 1000 times in 1 thread(s)...  359 seconds
Error in rbindlist(scoreSummary) : 
  Column 2 of item 1 is length 6 inconsistent with column 1 which is length 100. Only length-1 columns are recycled.

Does anyone know why this error is being produced? Is it because the function has been iterated too many times?

Thanks

You changed what FUN you are using... was that intentional?

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.