Boost::math::p DF () and C + + probability density function __jquery

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.