bbopt / nomad

NOMAD - A blackbox optimization software
https://nomad-4-user-guide.readthedocs.io/
GNU Lesser General Public License v3.0
120 stars 23 forks source link

RNG::setSeed complexity is O(seed_value) #174

Open jan-provaznik opened 4 months ago

jan-provaznik commented 4 months ago

Hello,

I've noticed that setting the seed of the random generator advances the generator by seed_value .

While this is perhaps a valid strategy, the side effect is that the complexity is not O(1) as one might naively expect but O(seed_value) instead. Since its value can be [0, INT_MAX] the initialization can end up being stuck for quite some time, which actually is how I noticed this issue.

As far as my understanding of the xorshift algorithm used in NOMAD goes, it can be seeded with any integer triplet; the choice of initial values is completely arbitrary. Instead of advancing the state seed_value times, any one of the three currently used initialization values could be replaced with seed_value. The benefit would be a constant complexity.

On this note, apparently the xorshift algorithm is not as good as PCG PRNGs. Maybe there would be merit in swapping it out. The example implementation is licensed under Apache 2.0 license and should be compatible with LGPL 3.0 used by NOMAD.

If there is any interest, I can submit a patch.