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

Random number generator from a normal distribution #196

Closed
rcurtin opened this issue Dec 29, 2014 · 2 comments
Closed

Random number generator from a normal distribution #196

rcurtin opened this issue Dec 29, 2014 · 2 comments
Assignees

Comments

@rcurtin
Copy link
Member

rcurtin commented Dec 29, 2014

Reported by pram on 11 Sep 42124316 15:22 UTC
We have random number generators from the uniform distribution in MLpack which use the boost library. Apparently, there are normal (Gaussian) random number generators in boost as well. Is there any way to add them to MLPack.

Example of boost::normal_distribution:

http://www.bnikolic.co.uk/blog/cpp-boost-rand-normal.html

This is the boost documentation on normal_distribution.

http://www.boost.org/doc/libs/1_35_0/libs/math/doc/sf_and_dist/html/math_toolkit/dist/dist_ref/dists/normal_dist.html

@rcurtin rcurtin self-assigned this Dec 29, 2014
@rcurtin rcurtin closed this as completed Dec 29, 2014
@rcurtin
Copy link
Member Author

rcurtin commented Dec 30, 2014

Commented by jcline3 on 8 Aug 42124347 04:24 UTC
It actually looks like there are quite a few to choose from.

Boost 1.48.0:
http://www.boost.org/doc/libs/1_48_0/libs/math/doc/sf_and_dist/html/math_toolkit/dist/dist_ref.html

And for boost 1.35.0, which has a few less:
http://www.boost.org/doc/libs/1_35_0/libs/math/doc/sf_and_dist/html/math_toolkit/dist/dist_ref.html

@rcurtin
Copy link
Member Author

rcurtin commented Dec 30, 2014

Commented by rcurtin on 20 Jun 42129453 03:36 UTC
I added RandNormal() which gives numbers on the standard normal distribution as well as an overload which takes a mean and variance. I don't want to wrap all the distributions there, so if we have any other commonly-used ones, we can add them to random.hpp but it's fairly easy to use one of the other ones in your code:

// some stuff
...
// Now I need a random number!
boost::random::cauchy_distribution<> dist;
double randomNumber = dist(randGen);

This exploits the global object 'randGen', which is basically the random seed object all the Boost random number generators use (it's defined in random.hpp and is of type boost::random::mt19937).

Careful though -- before Boost 1.47, all of the Boost.Random stuff was just in the boost namespace; now, it's in boost::random. You can see how I handle this in random.hpp pretty easily.

Let me know if maybe there is a better name we could use than RandNormal().

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