Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Statismo's use of std::time() as a random seed is badly suited for concurrent processing #270

Open
normanius opened this issue Apr 27, 2018 · 2 comments

Comments

@normanius
Copy link
Contributor

To seed random number generators, statismo uses the result of std::time(0). This is problematic because std::time(0) returns the time passed since epoch, measured in seconds. If multiple threads/process are started in very short time, the seed to the random number generator will always be the same, which is a problem if one wants to draw multiple samples from the same model/input in a parallel manner.

Of course there are ways to circumvent this issue, like ensuring that no two threads/processes are created in the same second. However, it would be more user friendly if the random number generator is initialized with more randomness.

Apparently, this is a bit more complicated than anticipated, but C++11 standard simplifies this considerably, as discussed in this article:

http://www.pcg-random.org/posts/cpp-seeding-surprises.html

@normanius
Copy link
Contributor Author

If @muefra's pull request #268 is merged, we could simply replace std::time(0) with std::random_device{}(). This should be completely fine in the context of statismo, because the the sampling wth gaussian processes is so heavily input-dependent, that certain biases in the random number generator (see the link above) will play a negligible role.

@normanius
Copy link
Contributor Author

normanius commented Apr 27, 2018

There is a boost correspondent to std::random_device, but I'd prefer to use the latter directly.

https://www.boost.org/doc/libs/1_46_0/doc/html/boost/random_device.html

kenavolic pushed a commit to latimagine/statismo that referenced this issue Apr 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant