C/C++ 中的累积正态分布函数
我想知道是否在数学库中内置了统计函数,这些函数是标准 C++ 库(如 cmath)的一部分.如果没有,你们能推荐一个具有累积正态分布函数的好的统计库吗?提前致谢.
I was wondering if there were statistics functions built into math libraries that are part of the standard C++ libraries like cmath. If not, can you guys recommend a good stats library that would have a cumulative normal distribution function? Thanks in advance.
更具体地说,我希望使用/创建一个累积分布函数.
More specifically, I am looking to use/create a cumulative distribution function.
推荐答案
在之前回答我的人的建议下,我想出了如何使用 gsl 来解决这个问题,但后来找到了一个非图书馆解决方案(希望这有助于很多人都像我一样在寻找它):
I figured out how to do it using gsl, at the suggestion of the folks who answered before me, but then found a non-library solution (hopefully this helps many people out there who are looking for it like I was):
#ifndef Pi
#define Pi 3.141592653589793238462643
#endif
double cnd_manual(double x)
{
double L, K, w ;
/* constants */
double const a1 = 0.31938153, a2 = -0.356563782, a3 = 1.781477937;
double const a4 = -1.821255978, a5 = 1.330274429;
L = fabs(x);
K = 1.0 / (1.0 + 0.2316419 * L);
w = 1.0 - 1.0 / sqrt(2 * Pi) * exp(-L *L / 2) * (a1 * K + a2 * K *K + a3 * pow(K,3) + a4 * pow(K,4) + a5 * pow(K,5));
if (x < 0 ){
w= 1.0 - w;
}
return w;
}
相关文章