pagmo2 icon indicating copy to clipboard operation
pagmo2 copied to clipboard

Flaky floating-point parameter checks in algos/probs

Open bluescarni opened this issue 5 years ago • 2 comments

While doing some heavy refactoring, I noticed that the parameter checks in algos/problems constructors are often wrong if NaNs/Infs are passed in. A typical example is something like this:

    if (cr >= 1. || cr < 0.) {
        pagmo_throw(std::invalid_argument, "The crossover probability must be in the [0,1[ range, while a value of "
                                               + std::to_string(cr) + " was detected");
    }

Here cr is a floating-point variable. If cr is nan, the check cr >= 1. || cr < 0. is false and thus no error is thrown.

I am gonna list here some instances of these issues, but this is not a comprehensive list. We need to do a sweep over all problems/algorithms constructors.

  • [ ] nsga2
  • [ ] de
  • [ ] ihs
  • [ ] moead
  • [ ] pso_gen
  • [ ] pso
  • [ ] sade (this one is not checking the floating-point input params at all)
  • [ ] sga
  • [ ] cmaes
  • [ ] de1220
  • [ ] xnes

bluescarni avatar May 03 '19 09:05 bluescarni

so would adding an additional or condition with isnan(cr) be a solution for this ?

aerophile avatar May 03 '19 11:05 aerophile

Yes, generally speaking. It should be done not blindly and on a case by case basis, understanding the meaning of the specific checks. And tests cases should be added in the unit tests to verify the new checks are working as intended.

PRs welcome as usual :) And if you want to discuss working on this, I suggest to move the conversation over to the gitter channel:

https://gitter.im/pagmo2/Lobby

bluescarni avatar May 03 '19 13:05 bluescarni