non-finite value supplied by optim

I am working with R. I am trying to follow the instructions from the "gpareto" R package to optimize some arbitrary function that I defined: https://cran.r-project.org/web/packages/GPareto/GPareto.pdf

Here is the function (7 inputs, 4 outputs):

library(gpareto)
library(dplyr)

# create some data for this example
    a1 = rnorm(1000,100,10)
    b1 = rnorm(1000,100,5)
    c1 = sample.int(1000, 1000, replace = TRUE)
    train_data = data.frame(a1,b1,c1)

funct_set <- function (x) {
    x1 <- x[1]; x2 <- x[2]; x3 <- x[3] ; x4 <- x[4]; x5 <- x[5]; x6 <- x[6]; x[7] <- x[7]
    f <- numeric(4)
    
    
    #bin data according to random criteria
    train_data <- train_data %>%
        mutate(cat = ifelse(a1 <= x1 & b1 <= x3, "a",
                            ifelse(a1 <= x2 & b1 <= x4, "b", "c")))
    
    train_data$cat = as.factor(train_data$cat)
    
    #new splits
    a_table = train_data %>%
        filter(cat == "a") %>%
        select(a1, b1, c1, cat)
    
    b_table = train_data %>%
        filter(cat == "b") %>%
        select(a1, b1, c1, cat)
    
    c_table = train_data %>%
        filter(cat == "c") %>%
        select(a1, b1, c1, cat)
    
    
    
    #calculate  quantile ("quant") for each bin
    
    table_a = data.frame(a_table%>% group_by(cat) %>%
                             mutate(quant = ifelse(c1 > x[5],1,0 )))
    
    table_b = data.frame(b_table%>% group_by(cat) %>%
                             mutate(quant = ifelse(c1 > x[6],1,0 )))
    
    table_c = data.frame(c_table%>% group_by(cat) %>%
                             mutate(quant = ifelse(c1 > x[7],1,0 )))
    
    f[1] = mean(table_a$quant)
    f[2] = mean(table_b$quant)
    f[3] = mean(table_c$quant)
    
    
    #group all tables
    
    final_table = rbind(table_a, table_b, table_c)
    # calculate the total mean 
    
    f[4] = mean(final_table$quant)
    
    
    
    
    return (f);
}

I then set up the specifications for the optimization (e.g. upper and lower bounds, number of iterations):

lower=c(80,80,80,80, 100,200,300)
upper=c(120,120,120,120,200,300,400)
budget <- 25

Next, I run the optimization algorithm:

omEGO <- easyGParetoptim(fn = funct_set, budget = budget, lower = lower, upper = upper)

But this produces an error:

Error in optim(par = parinit, fn = fn, gr = gr, method = "L-BFGS-B", lower = lower,  : 
  non-finite value supplied by optim

I tried to research on the internet other instances that encountered similar errors, e.g.: "non-finite value supplied by optim" error when using betareg

But I am not sure how to apply the logic from these posts to fix my problem.

Could someone please show me what to do?
Thanks

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.