我遇到了DEoptim包的问题。我试图通过优化vector optVector 来最小化函数 minF (参见代码)。
##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)
当我尝试这样做时,我收到以下错误:
Error in get(as.character(FUN), mode = "function", envir = envir) :
object 'fn' of mode 'function' was not found
我发现了一个类似的错误(link),但建议的更改变量名称的解决方案不起作用。我不知道这可能导致什么问题。任何帮助将不胜感激!