avaneev / biteopt

Derivative-Free Global Optimization Algorithm (C++, Python binding) - Continuous, Discrete, TSP, NLS, MINLP
MIT License
141 stars 9 forks source link

wrapParamReal gives parameters outside of range; a typo? #6

Closed tom7 closed 1 year ago

tom7 commented 1 year ago

In wrapParamReal, is the line

return( maxv - rnd.get() * ( v - dv ));

supposed to be

return( maxv - rnd.get() * ( v - maxv ));

? This would mirror the symmetric case for when v < minv. In any case, the current code can return a parameter value outside the range. In my test case I have minv: -1000, maxv: 1000, so dv = 2000. The incoming sample is 1039.54, which reaches line 1802, giving 1000 - rnd.get() * (1039.54 - 2000). Since rnd.get() is in [0,1] and the parenthetical is negative, we get a resulting sample greater than 1000, the supposed maximum.

Thanks for biteopt! :)

avaneev commented 1 year ago

Thank you for reporting the bug, I've just re-run all tests and released an update - should be okay now in this aspect.

Note that this bug mainly affected NMSOpt which is a sub-optimizer. BiteOpt itself is based on wrapParam() which works correctly.