For a project I have a specification with formulas, I have to implement. In these formulas a cumulative standard normal distribution function exists, that takes a float and outputs a probability. The function is symbolized by a Φ. Exists a Java-library, that computes this function?
对于一个项目,我有一个公式的规范,我必须实现。在这些公式中,存在累积标准正态分布函数,其采用浮点并输出概率。该功能由Φ表示。存在一个Java库,它可以计算这个函数吗?
5 个解决方案
#1
Apache Commons - Math has what you are looking for.
Apache Commons - 数学有你想要的。
More specifically, check out the NormalDistribution
class.
更具体地说,请查看NormalDistribution类。
#2
If you want the exact code, this one seems to be the same function used in OpenOffice Calc (I've made some changes for it to work in java):
如果你想要确切的代码,这个代码似乎与OpenOffice Calc中使用的功能相同(我已经对它进行了一些更改以便在java中工作):
// returns the cumulative normal distribution function (CNDF)
// for a standard normal: N(0,1)
double CNDF(double x)
{
int neg = (x < 0d) ? 1 : 0;
if ( neg == 1)
x *= -1d;
double k = (1d / ( 1d + 0.2316419 * x));
double y = (((( 1.330274429 * k - 1.821255978) * k + 1.781477937) *
k - 0.356563782) * k + 0.319381530) * k;
y = 1.0 - 0.398942280401 * Math.exp(-0.5 * x * x) * y;
return (1d - neg) * y + neg * (1d - y);
}
Found it here: http://www.codeproject.com/Messages/2622967/Re-NORMSDIST-function.aspx
在这里找到它:http://www.codeproject.com/Messages/2622967/Re-NORMSDIST-function.aspx
#3
#4
SuanShu, a Java numerical analysis library, computes the normal distribution and many other statistical distributions.
Java数值分析库SuanShu计算正态分布和许多其他统计分布。
#5
You could use the power series formula, which only takes up about 10 lines of code... see for example http://introcs.cs.princeton.edu/java/22library/Gaussian.java.html (the function Phi
)
你可以使用幂级数公式,它只占用大约10行代码...例如参见http://introcs.cs.princeton.edu/java/22library/Gaussian.java.html(函数Phi)
#1
Apache Commons - Math has what you are looking for.
Apache Commons - 数学有你想要的。
More specifically, check out the NormalDistribution
class.
更具体地说,请查看NormalDistribution类。
#2
If you want the exact code, this one seems to be the same function used in OpenOffice Calc (I've made some changes for it to work in java):
如果你想要确切的代码,这个代码似乎与OpenOffice Calc中使用的功能相同(我已经对它进行了一些更改以便在java中工作):
// returns the cumulative normal distribution function (CNDF)
// for a standard normal: N(0,1)
double CNDF(double x)
{
int neg = (x < 0d) ? 1 : 0;
if ( neg == 1)
x *= -1d;
double k = (1d / ( 1d + 0.2316419 * x));
double y = (((( 1.330274429 * k - 1.821255978) * k + 1.781477937) *
k - 0.356563782) * k + 0.319381530) * k;
y = 1.0 - 0.398942280401 * Math.exp(-0.5 * x * x) * y;
return (1d - neg) * y + neg * (1d - y);
}
Found it here: http://www.codeproject.com/Messages/2622967/Re-NORMSDIST-function.aspx
在这里找到它:http://www.codeproject.com/Messages/2622967/Re-NORMSDIST-function.aspx
#3
A co-worker suggested colt, as he used it before. This function has exactly the result as the example in the reference document.
一位同事建议小马,就像以前用过的那样。该函数与参考文档中的示例具有完全相同的结果。
#4
SuanShu, a Java numerical analysis library, computes the normal distribution and many other statistical distributions.
Java数值分析库SuanShu计算正态分布和许多其他统计分布。
#5
You could use the power series formula, which only takes up about 10 lines of code... see for example http://introcs.cs.princeton.edu/java/22library/Gaussian.java.html (the function Phi
)
你可以使用幂级数公式,它只占用大约10行代码...例如参见http://introcs.cs.princeton.edu/java/22library/Gaussian.java.html(函数Phi)