0

Im trying to use DEoptim to find the global minimum of z in in -1 < x < 1 , -1 < y < 1, but im getting Error in FUN(newX[, i], ...) : argument "y" is missing, with no default and I dont know what im supposed to do for the mission "y"

install.packages("Rmpfr")
install.packages("DEoptim")
library(gmp)
library(Rmpfr)
library(parallel) # https://cran.r-project.org/web/packages/DEoptim/vignettes/DEoptim.pdf
library(DEoptim)

z = function(x,y) {
  (exp(sin(60.0*x)) + sin(50.0*exp(y)) + sin(80.0*sin(x)) + sin(sin(70.0*y)) - sin(10.0*(x+y)) + (x*x+y*y)/4.0)
}

optimized_Minimum <- DEoptim(z, lower = c(-1,-1), upper = c(1,1),
                             control=list(storepopfrom=1, trace=FALSE))
# optimized_Minimum <- optim(z, lower = c(-1,-1), upper = c(1,1), method = "Brent")
Hack-R
  • 22,422
  • 14
  • 75
  • 131

1 Answers1

2

DEoptim is not expecting you to pass it 2 separate arguments to your function (x and y), but you can still solve for multiple variables.

You need to pass in a vector rather than 2 separate variables with the DEoptim package, as with the optim function.

I tested this with the functions from the linked solution and it worked:

fxcalc <- function(s,t){(1-(1-(parametros$ap/xm)^(s))^t)*100}
suma   <- function(s,t){(parametros$fx-fxcalc(s,t))^2}

func <- function(st){
  s  <- st[1]
  t  <- st[2]
  sum(suma(s,t))
}

optimized_Minimum <- DEoptim(func, lower = c(-1,-1), upper = c(1,1),
                             control=list(storepopfrom=1, trace=FALSE))

summary(optimized_Minimum)
***** summary of DEoptim object ***** 
best member   :  1 1 
best value    :  0 
after         :  200 generations 
fn evaluated  :  402 times 
*************************************
Hack-R
  • 22,422
  • 14
  • 75
  • 131