R 中的模拟退火:GenSA 运行 时间
Simulated Annealing in R: GenSA running time
我正在使用模拟退火,如在 R 的包 GenSa
(函数 GenSA
)中实现的那样,搜索导致 "good values" 的输入变量的值(与某些基线相比) 的高维函数。我注意到设置 objective 函数的最大调用次数对 运行 时间没有影响。我做错了什么还是这是一个错误?
这里是对 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
调用 objective 函数超过 46,000 次(请注意 objective 是在本地调用环境以便跟踪调用次数)。尝试通过 max.time
.
指定最大 运行 时间时会出现同样的问题
这是包维护者的回答:
max.call and max.time are soft limits that do not include local
searches that are performed before reaching these limits. The
algorithm does not stop the local search strategy loop before its end
and this may exceed the limitation that you have set but will stop
after that last search. We have designed the algorithm that way to
make sure that the algorithm isn't stopped in the middle of searching
valley. Such an option to stop anywhere will be implemented in the
next release of the package.
我正在使用模拟退火,如在 R 的包 GenSa
(函数 GenSA
)中实现的那样,搜索导致 "good values" 的输入变量的值(与某些基线相比) 的高维函数。我注意到设置 objective 函数的最大调用次数对 运行 时间没有影响。我做错了什么还是这是一个错误?
这里是对 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
调用 objective 函数超过 46,000 次(请注意 objective 是在本地调用环境以便跟踪调用次数)。尝试通过 max.time
.
这是包维护者的回答:
max.call and max.time are soft limits that do not include local searches that are performed before reaching these limits. The algorithm does not stop the local search strategy loop before its end and this may exceed the limitation that you have set but will stop after that last search. We have designed the algorithm that way to make sure that the algorithm isn't stopped in the middle of searching valley. Such an option to stop anywhere will be implemented in the next release of the package.