org.apache.commons.math.special.Erf
中可用,如此处和此处所讨论的那样。
附录:@Brent Worden的answer中提出的方法极大地简化了解决此类问题的过程。具体示例代码如下,展示了如何解决您所提到的examples问题。此外,我发现将here的定义与使用Erf.erf
实现的cumulativeProbability()
进行比较是有帮助的。还要注意inverseCumulativeProbability()
的实现如何推广所需的迭代方法。
import org.apache.commons.math.MathException;
import org.apache.commons.math.distribution.NormalDistribution;
import org.apache.commons.math.distribution.NormalDistributionImpl;
/**
* @see http://stattrek.com/Tables/Normal.aspx#examples
* @see https://dev59.com/0VjUa4cB1Zd3GeqPPkF5
*/
public class CumulativeProbability {
private static NormalDistribution d;
public static void main(String[] args) throws MathException {
// Problem 1; µ = 1000; σ = 100
d = new NormalDistributionImpl(1000, 100);
System.out.println(d.cumulativeProbability(1200));
// Problem 2; µ = 50; σ = 10
d = new NormalDistributionImpl(50, 10);
System.out.println(d.inverseCumulativeProbability(0.9));
}
}
控制台:
0.9772498680518208 62.81551565546365
讨论:
问题1:在平均寿命为1000小时,标准差为100小时的设备中,大约97.7%的设备将在1200小时内失效。
问题2:在具有正态分布技能的人群中,平均可重复50次,标准差为10次,一个人需要63次重复才能超过90%的人群。
另一个可选方案是使用来自commons-math的NormalDistributionImpl:
new org.apache.commons.math.distribution.NormalDistributionImpl(mean, std)
.cumulativeProbability(a, b)
这个公式计算的是正态分布下 X 在区间 [a, b] 内的概率 P(a ≤ X ≤ b)。
从更新后的问题来看,你想构建置信区间。如果是的话,请使用 inverseCumulativeProbability 方法。它可以计算出当概率为 p 时,使得 P(X ≤ x) = p 的值 x。
Colt库是由欧洲核子研究组织开发的,支持许多统计函数;cern.jet.random.Normal
中也包含正态(又称高斯)分布。