Evolutionary.jl icon indicating copy to clipboard operation
Evolutionary.jl copied to clipboard

ga fails to minimize functions with negative range

Open fredcallaway opened this issue 6 years ago • 5 comments

Example:

best, = ga(x->-sum(x), 
          5,
          initPopulation=n->rand(Bool, n),
          iterations=10000,
          mutationRate = 0.2,
          selection = roulette
          )

I think this is because you maximize the inverse of the provided objective function. Is there a reason to do this rather than just directly minimizing the function? (Or I guess, maximizing the negation of the function)

fredcallaway avatar Feb 03 '19 00:02 fredcallaway

Looking at the code more, lots of stuff won't make sense with negative objective values. Is this just a standard assumption for genetic algorithms? (I'm no expert!)

fredcallaway avatar Feb 03 '19 02:02 fredcallaway

I guess it is because the selection methods need to sort the population basing on the fitness. So the ga method should take in input a max/min parameter to drive the sorting phases. Maybe this is a limitation of this first version.

apeano avatar Feb 22 '19 17:02 apeano

You need to rewrite your problem to fit the package.

phelipe avatar Feb 22 '19 18:02 phelipe

This package performs an objective function minimization by maximizing its inverse. Shape your problem to fit the package behavior.

wildart avatar Feb 24 '19 21:02 wildart

OK sure that's fine. But I think it would be good to include the constraint that the objective function be positive in the documentation.

Also, it's worth noting that taking the inverse has scaling effects that may be undesirable. In particular, for values near 0, very small differences in the objective function will lead to large differences in the inverse objective function, which could reduce population diversity if using selection functions such as roulette or SUS.

fredcallaway avatar Feb 25 '19 02:02 fredcallaway