Reprint please indicate the source: Http://my.csdn.NET/ye_shen_wei_mian
Recently in an open source code to contact the probability density function, the probability density function is normal (Gaussian) distribution, is based on boost library implementation, very easy to use.
This function is explained by the official website:
PDF (my_dist, x); Returns PDF (density) at point x of distribution my_dist.
As for usage, it's simple:
boost::math::normal_distribution<float> nd (SEED->MU, norm_scale);
float result = Boost::math::p df (nd, x);
For more information on PDF and CDF functions, refer to the http://www.boost.org/doc/libs/1_63_0/libs/math/doc/html/math_toolkit/stat_tut/overview/ Generic.html this website
Think of Boost as C + + as a quasi-standard library components, in C + + standard library is the same implementation?
Unfortunately, after the collection of data found that there seems to be no, in the StackOverflow to detail the question of the received answer probability density Function using the standard library. (URL: http://stackoverflow.com/questions/19387222/probability-density-function-using-the-standard-library) In fact, to write their own common probability distribution density function is not difficult, can write their own. In StackOverflow find a normal (Gaussian) distribution of the implementation of others, for everyone to reference: Using the Gaussian probability density function in C + + (url: http:// stackoverflow.com/questions/10847007/using-the-gaussian-probability-density-function-in-c#) The author gives two kinds of implementations:
float normal_pdf (float x, float m, float s)
{
static const float INV_SQRT_2PI = 0.3989422804014327;
float a = (x-m)/s;
Return inv_sqrt_2pi/s * STD::EXP ( -0.5f * A * a);
}
Or you can make a template function:
Template <typename t>
t normal_pdf (t X, T M, T s)
{
static const t INV_SQRT_2PI = 0.3989422804014327;
t a = (x-m)/s;
Return inv_sqrt_2pi/s * STD::EXP (-t (0.5) * A * a);
}
As for how to use the STD's own probability distribution to produce a normal distribution or other distributed random number, you can refer to the random number generation method under the normal distribution:
Http://www.cplusplus.com/reference/random/normal_distribution/?kw=normal_distribution