When the function to be monimized in in GenSA keeps returning -inf the random generation of parameters is always the same, even when set.seed() takes different values. I don't know if this is actually desired but this is problematic for fitMC().
A workaround is to replace -inf by a very large negative value but this has some limits.
Reprex:
Rastrigin <- function(x) {
print(x[1])
sum(x^2 - 10 * cos(2 * pi * x)) + 10 * length(x)
log(0)
}
set.seed(1234)
dimension <- 2
global.min <- 0
tol <- 1e-13
lower <- rep(-5.12, dimension)
upper <- rep(5.12, dimension)
out <- GenSA(lower = lower, upper = upper, fn = Rastrigin,
control=list(maxit = 10, threshold.stop=global.min+tol,verbose=TRUE))
out[c("value","par","counts")]
set.seed(789)
dimension <- 2
global.min <- 0
tol <- 1e-13
lower <- rep(-5.12, dimension)
upper <- rep(5.12, dimension)
out <- GenSA(lower = lower, upper = upper, fn = Rastrigin,
control=list(maxit = 10, threshold.stop=global.min+tol,verbose=TRUE))
out[c("value","par","counts")]
and check the values printed in both case.
When the function to be monimized in in GenSA keeps returning
-infthe random generation of parameters is always the same, even whenset.seed()takes different values. I don't know if this is actually desired but this is problematic forfitMC().A workaround is to replace
-infby a very large negative value but this has some limits.Reprex:
and check the values printed in both case.