使用 Apache Commons Math 确定置信区间

发布于 2024-10-30 04:08:56 字数 509 浏览 6 评论 0原文

我有一组基准数据,我使用 Apache Math Commons 计算汇总统计数据。现在我想使用该包来计算运行时间测量等算术平均值的置信区间。

这有可能吗?我确信该软件包支持这一点,但是我不知道从哪里开始。

这是我在 Brent Worden 建议的帮助下最终使用的解决方案:

private double getConfidenceIntervalWidth(StatisticalSummary statistics, double significance) {
    TDistribution tDist = new TDistribution(statistics.getN() - 1);
    double a = tDist.inverseCumulativeProbability(1.0 - significance / 2);
    return a * statistics.getStandardDeviation() / Math.sqrt(statistics.getN());
}

I have a set of benchmark data for which I compute summary statistics using Apache Math Commons. Now I want to use the package to compute confidence intervals for the arithmetic means of e.g. running time measurements.

Is this possible at all? I am convinced that the package supports this, however I am at a loss about where to start.

This is the solution I ended up using with the help of Brent Worden's suggestion:

private double getConfidenceIntervalWidth(StatisticalSummary statistics, double significance) {
    TDistribution tDist = new TDistribution(statistics.getN() - 1);
    double a = tDist.inverseCumulativeProbability(1.0 - significance / 2);
    return a * statistics.getStandardDeviation() / Math.sqrt(statistics.getN());
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

倾城花音 2024-11-06 04:08:56

Apache Commons Math 不直接支持构建置信区间。然而,它确实拥有计算它们所需的一切。

首先,使用 SummaryStatistics,或者其他一些 StatisticalSummary 实现进行总结您的数据进入样本统计。

接下来,使用 TDistribution 计算临界值达到您想要的置信度。自由度可以从汇总统计的 n 属性中推断出来。

最后,使用汇总统计中的meanvariancen 属性值以及分布中的 t 临界值来计算您的下限和置信上限。

Apache Commons Math does not have direct support for constructing confidence intervals. However, it does have everything needed to compute them.

First, use SummaryStatistics, or some other StatisticalSummary implementation to summarize your data into sample statistics.

Next, use TDistribution to compute critical values for your desired confidence level. The degrees of freedom can be inferred from the summary statistics' n property.

Last, use the mean, variance, and n property values from the summary statistics and the t critical value from the distribution to compute your lower and upper confidence limits.

橘味果▽酱 2024-11-06 04:08:56

如果您仍然想仅使用标准版本在java中计算二项式,您可以使用下面的类,如下所示。

calling sample BinomialConfidenceCalc.calcBin(13, 100,95.0D);

public class BinomialConfidenceCalc {

    public static double binP(double N,double p,double x1,double x2){
        double q = p/(1-p);
        double k = 0.0;
        double v = 1.0;
        double s = 0.0;
        double tot = 0.0;

        while(k<=N){                    
            tot += v;
            if(k >= x1 && k <= x2){                
                s += v;
            }    
            if(tot > Math.pow(10,30)){                    
                s = s/Math.pow(10,30);
                tot = tot/Math.pow(10,30);
                v = v/Math.pow(10,30);
            }
            k += 1;
            v = v*q*(N+1-k)/k;

        }
        return s/tot;
    }


    public static double[] calcBin(double vx,double vN,Double vCL){

        double vTU = (100 - vCL)/2;
        double vTL = vTU;
        double dl = 0.0;
        double vP = vx/vN;
        if(vx==0){            
            dl = 0.0;
        }
        else{
            double v = vP/2;
            double  vsL = 0;
            double vsH = vP;
            double p = vTL/100;

            while((vsH-vsL) > Math.pow(10,-5)){
                if(binP(vN, v, vx, vN) > p){
                    vsH = v;
                    v = (vsL+v)/2;
                }else{
                    vsL = v;
                    v = (v+vsH)/2;
                }
            }
            dl = v;                             
        }

        double ul = 0.0;
        if(vx==vN){            
            ul = 1.0;
        }
        else{

            double v = (1+vP)/2;
            double vsL =vP;
            double vsH = 1;
            double p = vTU/100;
            while((vsH-vsL) > Math.pow(10,-5)){
                if(binP(vN, v, 0, vx) < p){
                    vsH = v;
                    v = (vsL+v)/2;
                }
                else{
                    vsL = v;
                    v = (v+vsH)/2;
                }
            }
            ul = v;
        }
        double dlUl[] = new double[]{dl,ul};
        return dlUl;
    }



}

If you still want to calculate binomial in java by using only standard edition You can use below class like below.

calling sample BinomialConfidenceCalc.calcBin(13, 100,95.0D);

public class BinomialConfidenceCalc {

    public static double binP(double N,double p,double x1,double x2){
        double q = p/(1-p);
        double k = 0.0;
        double v = 1.0;
        double s = 0.0;
        double tot = 0.0;

        while(k<=N){                    
            tot += v;
            if(k >= x1 && k <= x2){                
                s += v;
            }    
            if(tot > Math.pow(10,30)){                    
                s = s/Math.pow(10,30);
                tot = tot/Math.pow(10,30);
                v = v/Math.pow(10,30);
            }
            k += 1;
            v = v*q*(N+1-k)/k;

        }
        return s/tot;
    }


    public static double[] calcBin(double vx,double vN,Double vCL){

        double vTU = (100 - vCL)/2;
        double vTL = vTU;
        double dl = 0.0;
        double vP = vx/vN;
        if(vx==0){            
            dl = 0.0;
        }
        else{
            double v = vP/2;
            double  vsL = 0;
            double vsH = vP;
            double p = vTL/100;

            while((vsH-vsL) > Math.pow(10,-5)){
                if(binP(vN, v, vx, vN) > p){
                    vsH = v;
                    v = (vsL+v)/2;
                }else{
                    vsL = v;
                    v = (v+vsH)/2;
                }
            }
            dl = v;                             
        }

        double ul = 0.0;
        if(vx==vN){            
            ul = 1.0;
        }
        else{

            double v = (1+vP)/2;
            double vsL =vP;
            double vsH = 1;
            double p = vTU/100;
            while((vsH-vsL) > Math.pow(10,-5)){
                if(binP(vN, v, 0, vx) < p){
                    vsH = v;
                    v = (vsL+v)/2;
                }
                else{
                    vsL = v;
                    v = (v+vsH)/2;
                }
            }
            ul = v;
        }
        double dlUl[] = new double[]{dl,ul};
        return dlUl;
    }



}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文