0

I ran into a problem with the DEoptim package. I am trying to minimize the function minF by optimizing vector optVector (see code).

##construct function
minF <- function(x, y, z){
return(mean((z-rowSums(t(x*t(y))))^2))
}

#random matrix and vector
testmrx <- matrix(rnorm(6),38,9) 
vctr <- runif(38, min=0, max=50)

#Vector to be optimized and its bounds
optVector = c(20,20,50,30,30,10,3,5,5)
lowr = c(0,0,0,0,0,0,0,0,0)
uppr = c(50,50,200,100,100,50,20,20,20)

#Call of DEoptim
DEoptim(fn = minF(optVector, testmrx, vctr), lower=lowr, upper=uppr)

When I try to do this I get following error:

Error in get(as.character(FUN), mode = "function", envir = envir) : 
object 'fn' of mode 'function' was not found

I found a similar error posted (link), but the proposed solution of changing variable names did not work. I have no idea what might be causing the problem here. Any help would be greatly appreciated!

  • I don't know much about DEoptim package, but the problem here could be the way you have specified function parameter of *minF* inside DEoptim function. I don't know if it makes sense but if you define the variable x,y,z inside the function minF in the very beginning and then just use `DEoptim(minF, lower=lowr, upper=uppr)` it could work. – Biranjan Feb 15 '18 at 13:13
  • @Biranjan thanks for the reply. I just tried it, but it does not work. DEoptim specifically requires fn to be _"the function to be optimized (minimized). The function should have as its first argument the vector of real-valued parameters to optimize, and return a scalar real result. NA and NaN values are not allowed."_ If you try declaring x, y, z in the start, it will not work. – jibberyjabber Feb 15 '18 at 13:30
  • Okay, yea I think it doesn't make sense to define x inside the constructor function but how about y and z. – Biranjan Feb 15 '18 at 13:59
  • @Biranjan Same result unfortunately.. – jibberyjabber Feb 15 '18 at 14:06

0 Answers0