Skip to content

Weird behaviour of GenSA() when return value is -inf #50

@KevCaz

Description

@KevCaz

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    noteSomething to keep in mind

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions