我正在使用 R 的包GenSa
(函数GenSA
)中实现的模拟退火来搜索输入变量的值,这些值会导致高维函数的“好值”(与某些基线相比)。我注意到设置目标函数的最大调用次数对运行时间没有影响。我做错了什么还是这是一个错误?
这是GenSA
帮助文件中给出的示例的修改。
library(GenSA)
Rastrigin <- local({
index <- 0
function(x){
index <<- index + 1
if(index%%1000 == 0){
cat(index, " ")
}
sum(x^2 - 10*cos(2*pi*x)) + 10*length(x)
}
})
set.seed(1234)
dimension <- 1000
lower <- rep(-5.12, dimension)
upper <- rep(5.12, dimension)
out <- GenSA(lower = lower, upper = upper, fn = Rastrigin, control = list(max.call = 10^4))
即使max.call
指定为 10,000,GenSA
调用目标函数也超过 46,000 次(请注意,在本地环境中调用目标是为了跟踪调用次数)。尝试通过 指定最大运行时间时会出现同样的问题max.time
。