Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I'm trying to generate random number using Rayleigh distribution. I have implemented this using the c++ the library below:

#include <boost/math/distributions/rayleigh.hpp>

boost::math::rayleigh_distribution<> rayleigh();

I don't know how to use this library to return number related to sigma.

question from:https://stackoverflow.com/questions/65642518/how-to-use-rayleigh-distribution-from-boost-library-in-c

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
654 views
Welcome To Ask or Share your Answers For Others

1 Answer

The sigma is passed in the constructor, so do it like this:

const double sigma = 5.;
boost::math::rayleigh_distribution<> rayleigh(sigma);

The method sigma() merely returns a copy of the set sigma, so you cannot use that.

What Scheff was referring to is that it would also work (given you want sigma to be 1.) if you do that

boost::math::rayleigh_distribution<> rayleigh{};

as this has no ambiguity with a function declaration, but is setting sigma to 1.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...