Evolutionary-Optimization-Laboratory / rmoo

An R package for multi/many-objective optimization with non-dominated genetic algorithms' family
GNU General Public License v2.0
29 stars 7 forks source link

"Error in { : task 1 failed " what should the code be #11

Closed mytarmail closed 5 months ago

mytarmail commented 5 months ago

Hi!! I'm a little lost... I have a fitness function that takes one vector of size 100, and the output is three values that I need to minimize. What am I doing wrong

fit <- function(inp){
# inp vector length = 100
# some code
  x1 <- rnorm(1)
  x2 <- rnorm(1)
  x3 <- rnorm(1)
# output
 return( c(x1,x2,x3) )
}

library(rmoo)
result <- rmoo(fitness = fit,
               type = "real-valued",
               algorithm = "NSGA-III",
               lower =  rep(-10,100),
               upper =  rep( 10,100),
               monitor = T,
               parallel = T,
               popSize = 100,
               maxiter = 10)

Error in { : 
  task 1 failed - "<U+043D><U+0435><U+0438><U+0441><U+043F><U+043E><U+043B><U+044C><U+0437><U+043E><U+0432><U+0430><U+043D><U+043D><U+044B><U+0439> <U+0430><U+0440><U+0433><U+0443><U+043C><U+0435><U+043D><U+0442> (algorithm = "NSGA-III")"
In addition: There were 50 or more warnings (use warnings() to see the first 50)
benitezfj commented 5 months ago

Hi,

The error generated is not clear enough to identify the reason why it is generated, but I notice that you are trying to use NSGA-III and you have not defined the reference points (the argument reference_dirs defines it) when using it, as this parameter is mandatory to be able to execute it. It would also be ideal if you define the number of objectives, looking at the function to evaluate it would be nObj = 3.

library(rmoo)

fit <- function(inp){
    # inp vector length = 100
    # some code
    x1 <- rnorm(1)
    x2 <- rnorm(1)
    x3 <- rnorm(1)
    # output
    return( c(x1,x2,x3) )
}

ref_points <- generate_reference_points(3,12)

result <- rmoo(fitness = fit,
               type = "real-valued",
               algorithm = "NSGA-III",
               lower =  rep(-10,100),
               upper =  rep( 10,100),
               monitor = TRUE,
               parallel = FALSE,
               popSize = 100,
               reference_dirs = ref_points,
               nObj = 3,
               maxiter = 10)

Commenting, we deactivate the parallel as the overhead of using multiple cores for a function that is not costly would make it slower, so it is ideal to deactivate it.

With these changes, we were able to execute the given function without problems.

Best regards.