luca-scr / GA

An R package for optimization using genetic algorithms
http://luca-scr.github.io/GA/
91 stars 29 forks source link

Suggestions override min and max #12

Closed JasonCEC closed 3 years ago

JasonCEC commented 6 years ago

When suggestions us used in ga, the results of ga can be outside the bounds set in min and max. This could be considered a bug, as many users expect the results to be within the set boundaries.

After looking at the code, it is clear that when a suggestion is made, it is included in the initial population, and when a suggestion outside the bounds has high value, that value can be "inherited" by future generations.

Considering that this may be expected behavior, we could produce a warning instead of forcing the results to be within the min/max bounds.

luca-scr commented 6 years ago

If a user specifies min and max (please note that these have been renamed lowerand upper, but old nomenclature is still accepted with a warning) and then provides a suggestions matrix that do not satisfy the boundary conditions specified, then there is something wrong on the user's side. That said, I can try to include a check. It is not clear to me what you propose. From my point of view, setting lowerand upper should have priority because they are mandatory arguments. So, if suggestions contradict the specified boundaries then I can 1) remove the offending suggestion, 2) force the suggestions to fulfil the boundaries. In any case a warning should be issued.

JasonCEC commented 6 years ago

I agree that passing suggestions outside the bounds of upper and lower is a user error, but, for example, while applying complex transformations to a original data set, such as word2vec, it is easy to accidentally do so, resulting in return values from ga outside of those limits.

I suggest: 1) lower and upper have priority 2) ga warn when suggestions are outside the boundaries 3) an option to deal with suggestions outside the boundaries - perhaps: drop, stop, and truncate?

drop would drop the observations outside of the boundaries, stop would error instead of warn when any suggestion is outside of the boundaries, and truncate would overwrite suggestion variables less than lower with lower and greater than upper with upper.

I think this is in line with what you wrote above, and I would be happy to help if there's a section of this I could write?