当前位置: 首页>>代码示例>>Java>>正文


Java RealDistribution.cumulativeProbability方法代码示例

本文整理汇总了Java中org.apache.commons.math3.distribution.RealDistribution.cumulativeProbability方法的典型用法代码示例。如果您正苦于以下问题:Java RealDistribution.cumulativeProbability方法的具体用法?Java RealDistribution.cumulativeProbability怎么用?Java RealDistribution.cumulativeProbability使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.commons.math3.distribution.RealDistribution的用法示例。


在下文中一共展示了RealDistribution.cumulativeProbability方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: kolmogorovSmirnovStatistic

import org.apache.commons.math3.distribution.RealDistribution; //导入方法依赖的package包/类
/**
 * Computes the one-sample Kolmogorov-Smirnov test statistic, \(D_n=\sup_x |F_n(x)-F(x)|\) where
 * \(F\) is the distribution (cdf) function associated with {@code distribution}, \(n\) is the
 * length of {@code data} and \(F_n\) is the empirical distribution that puts mass \(1/n\) at
 * each of the values in {@code data}.
 *
 * @param distribution reference distribution
 * @param data sample being evaluated
 * @return Kolmogorov-Smirnov statistic \(D_n\)
 * @throws InsufficientDataException if {@code data} does not have length at least 2
 * @throws NullArgumentException if {@code data} is null
 */
public double kolmogorovSmirnovStatistic(RealDistribution distribution, double[] data) {
    checkArray(data);
    final int n = data.length;
    final double nd = n;
    final double[] dataCopy = new double[n];
    System.arraycopy(data, 0, dataCopy, 0, n);
    Arrays.sort(dataCopy);
    double d = 0d;
    for (int i = 1; i <= n; i++) {
        final double yi = distribution.cumulativeProbability(dataCopy[i - 1]);
        final double currD = FastMath.max(yi - (i - 1) / nd, i / nd - yi);
        if (currD > d) {
            d = currD;
        }
    }
    return d;
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:30,代码来源:KolmogorovSmirnovTest.java

示例2: cumulativeProbability

import org.apache.commons.math3.distribution.RealDistribution; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 *
 * <p>Algorithm description:<ol>
 * <li>Find the bin B that x belongs to.</li>
 * <li>Compute P(B) = the mass of B and P(B-) = the combined mass of the bins below B.</li>
 * <li>Compute K(B) = the probability mass of B with respect to the within-bin kernel
 * and K(B-) = the kernel distribution evaluated at the lower endpoint of B</li>
 * <li>Return P(B-) + P(B) * [K(x) - K(B-)] / K(B) where
 * K(x) is the within-bin kernel distribution function evaluated at x.</li></ol>
 * If K is a constant distribution, we return P(B-) + P(B) (counting the full
 * mass of B).</p>
 *
 * @since 3.1
 */
public double cumulativeProbability(double x) {
    if (x < min) {
        return 0d;
    } else if (x >= max) {
        return 1d;
    }
    final int binIndex = findBin(x);
    final double pBminus = pBminus(binIndex);
    final double pB = pB(binIndex);
    final RealDistribution kernel = k(x);
    if (kernel instanceof ConstantRealDistribution) {
        if (x < kernel.getNumericalMean()) {
            return pBminus;
        } else {
            return pBminus + pB;
        }
    }
    final double[] binBounds = getUpperBounds();
    final double kB = kB(binIndex);
    final double lower = binIndex == 0 ? min : binBounds[binIndex - 1];
    final double withinBinCum =
        (kernel.cumulativeProbability(x) -  kernel.cumulativeProbability(lower)) / kB;
    return pBminus + pB * withinBinCum;
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:40,代码来源:EmpiricalDistribution.java

示例3: cumulativeProbability

import org.apache.commons.math3.distribution.RealDistribution; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 *
 * <p>Algorithm description:<ol>
 * <li>Find the bin B that x belongs to.</li>
 * <li>Compute P(B) = the mass of B and P(B-) = the combined mass of the bins below B.</li>
 * <li>Compute K(B) = the probability mass of B with respect to the within-bin kernel
 * and K(B-) = the kernel distribution evaluated at the lower endpoint of B</li>
 * <li>Return P(B-) + P(B) * [K(x) - K(B-)] / K(B) where
 * K(x) is the within-bin kernel distribution function evaluated at x.</li></ol></p>
 *
 * @since 3.1
 */
public double cumulativeProbability(double x) {
    if (x < min) {
        return 0d;
    } else if (x >= max) {
        return 1d;
    }
    final int binIndex = findBin(x);
    final double pBminus = pBminus(binIndex);
    final double pB = pB(binIndex);
    final double[] binBounds = getUpperBounds();
    final double kB = kB(binIndex);
    final double lower = binIndex == 0 ? min : binBounds[binIndex - 1];
    final RealDistribution kernel = k(x);
    final double withinBinCum =
        (kernel.cumulativeProbability(x) -  kernel.cumulativeProbability(lower)) / kB;
    return pBminus + pB * withinBinCum;
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:31,代码来源:EmpiricalDistribution.java

示例4: addCDFSeries

import org.apache.commons.math3.distribution.RealDistribution; //导入方法依赖的package包/类
public static void addCDFSeries(Chart chart, RealDistribution distribution, String desc, int lowerBound, int upperBound) {
    // generates Log data
    List<Number> xData = new ArrayList<Number>();
    List<Number> yData = new ArrayList<Number>();
    int samples = 100;
    double stepSize = (upperBound - lowerBound) / (double) samples;
    for (double x = lowerBound; x <= upperBound; x += stepSize) {
      double density = distribution.cumulativeProbability(x);
      if (! Double.isInfinite(density) && ! Double.isNaN(density)) {
          xData.add(x);
          yData.add(density);
      }
    }

    Series series = chart.addSeries(desc, xData, yData);
    series.setMarker(SeriesMarker.NONE);
    series.setLineStyle(new BasicStroke(1.2f));
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:19,代码来源:RealDistributionComparison.java

示例5: makeCumulativeTestValues

import org.apache.commons.math3.distribution.RealDistribution; //导入方法依赖的package包/类
@Override
public double[] makeCumulativeTestValues() {
    /* 
     * Bins should be [0, 10], (10, 20], ..., (9990, 10000]
     * Kernels should be N(4.5, 3.02765), N(14.5, 3.02765)...
     * Each bin should have mass 10/10000 = .001
     */
    final double[] testPoints = getCumulativeTestPoints();
    final double[] cumValues = new double[testPoints.length];
    final EmpiricalDistribution empiricalDistribution = (EmpiricalDistribution) makeDistribution();
    final double[] binBounds = empiricalDistribution.getUpperBounds();
    for (int i = 0; i < testPoints.length; i++) {
        final int bin = findBin(testPoints[i]);
        final double lower = bin == 0 ? empiricalDistribution.getSupportLowerBound() :
            binBounds[bin - 1];
        final double upper = binBounds[bin];
        // Compute bMinus = sum or mass of bins below the bin containing the point
        // First bin has mass 11 / 10000, the rest have mass 10 / 10000.
        final double bMinus = bin == 0 ? 0 : (bin - 1) * binMass + firstBinMass;
        final RealDistribution kernel = findKernel(lower, upper);
        final double withinBinKernelMass = kernel.cumulativeProbability(lower, upper);
        final double kernelCum = kernel.cumulativeProbability(lower, testPoints[i]);
        cumValues[i] = bMinus + (bin == 0 ? firstBinMass : binMass) * kernelCum/withinBinKernelMass;
    }
    return cumValues;
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:27,代码来源:EmpiricalDistributionTest.java

示例6: makeDensityTestValues

import org.apache.commons.math3.distribution.RealDistribution; //导入方法依赖的package包/类
@Override
public double[] makeDensityTestValues() {
    final double[] testPoints = getCumulativeTestPoints();
    final double[] densityValues = new double[testPoints.length];
    final EmpiricalDistribution empiricalDistribution = (EmpiricalDistribution) makeDistribution();
    final double[] binBounds = empiricalDistribution.getUpperBounds();
    for (int i = 0; i < testPoints.length; i++) {
        final int bin = findBin(testPoints[i]);
        final double lower = bin == 0 ? empiricalDistribution.getSupportLowerBound() :
            binBounds[bin - 1];
        final double upper = binBounds[bin];
        final RealDistribution kernel = findKernel(lower, upper);
        final double withinBinKernelMass = kernel.cumulativeProbability(lower, upper);
        final double density = kernel.density(testPoints[i]);
        densityValues[i] = density * (bin == 0 ? firstBinMass : binMass) / withinBinKernelMass;   
    }
    return densityValues;
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:19,代码来源:EmpiricalDistributionTest.java

示例7: generateRandomValuesRecursive

import org.apache.commons.math3.distribution.RealDistribution; //导入方法依赖的package包/类
private ForkJoinTask<Void> generateRandomValuesRecursive(
        final RealRng rng,
        final RealDistribution distribution,
        final int startInclusive,
        final int endExclusive,
        final double[] result,
        final double[] work) {

    return new RecursiveAction() {
        @Override
        protected void compute() {
            if (endExclusive - startInclusive > FJ_TASK_SIZE) {
                int mid = startInclusive + (endExclusive - startInclusive) / 2;

                invokeAll(
                        generateRandomValuesRecursive(rng, distribution, startInclusive, mid, work, result /* swap work & result*/),
                        generateRandomValuesRecursive(rng, distribution, mid, endExclusive, work, result));

                ParallelSorts.merge(work, result, startInclusive, mid, endExclusive);

            } else {
                for (int i = startInclusive; i < endExclusive; i++) {
                    double r = rng.generate(randomSupplier.random());
                    if (Double.isNaN(r)) {
                        throw new RuntimeException("NaN");
                    }
                    result[i] = distribution.cumulativeProbability(r);
                }

                Arrays.sort(result, startInclusive, endExclusive);
            }
        }
    };
}
 
开发者ID:komiya-atsushi,项目名称:fast-rng-java,代码行数:35,代码来源:TwoLevelTester.java

示例8: inverseCumulativeProbability

import org.apache.commons.math3.distribution.RealDistribution; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 *
 * <p>Algorithm description:<ol>
 * <li>Find the smallest i such that the sum of the masses of the bins
 *  through i is at least p.</li>
 * <li>
 *   Let K be the within-bin kernel distribution for bin i.</br>
 *   Let K(B) be the mass of B under K. <br/>
 *   Let K(B-) be K evaluated at the lower endpoint of B (the combined
 *   mass of the bins below B under K).<br/>
 *   Let P(B) be the probability of bin i.<br/>
 *   Let P(B-) be the sum of the bin masses below bin i. <br/>
 *   Let pCrit = p - P(B-)<br/>
 * <li>Return the inverse of K evaluated at <br/>
 *    K(B-) + pCrit * K(B) / P(B) </li>
 *  </ol></p>
 *
 * @since 3.1
 */
@Override
public double inverseCumulativeProbability(final double p) throws OutOfRangeException {
    if (p < 0.0 || p > 1.0) {
        throw new OutOfRangeException(p, 0, 1);
    }

    if (p == 0.0) {
        return getSupportLowerBound();
    }

    if (p == 1.0) {
        return getSupportUpperBound();
    }

    int i = 0;
    while (cumBinP(i) < p) {
        i++;
    }

    final RealDistribution kernel = getKernel(binStats.get(i));
    final double kB = kB(i);
    final double[] binBounds = getUpperBounds();
    final double lower = i == 0 ? min : binBounds[i - 1];
    final double kBminus = kernel.cumulativeProbability(lower);
    final double pB = pB(i);
    final double pBminus = pBminus(i);
    final double pCrit = p - pBminus;
    if (pCrit <= 0) {
        return lower;
    }
    return kernel.inverseCumulativeProbability(kBminus + pCrit * kB / pB);
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:53,代码来源:EmpiricalDistribution.java

示例9: kB

import org.apache.commons.math3.distribution.RealDistribution; //导入方法依赖的package包/类
/**
 * Mass of bin i under the within-bin kernel of the bin.
 *
 * @param i index of the bin
 * @return the difference in the within-bin kernel cdf between the
 * upper and lower endpoints of bin i
 */
@SuppressWarnings("deprecation")
private double kB(int i) {
    final double[] binBounds = getUpperBounds();
    final RealDistribution kernel = getKernel(binStats.get(i));
    return i == 0 ? kernel.cumulativeProbability(min, binBounds[0]) :
        kernel.cumulativeProbability(binBounds[i - 1], binBounds[i]);
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:15,代码来源:EmpiricalDistribution.java

示例10: pValues

import org.apache.commons.math3.distribution.RealDistribution; //导入方法依赖的package包/类
public double [] pValues(){
  double [] res = zValues();
  RealDistribution rd = _dispersionEstimated?new TDistribution(_training_metrics.residual_degrees_of_freedom()):new NormalDistribution();
  for(int i = 0; i < res.length; ++i)
    res[i] = 2*rd.cumulativeProbability(-Math.abs(res[i]));
  return res;
}
 
开发者ID:h2oai,项目名称:h2o-3,代码行数:8,代码来源:GLMModel.java


注:本文中的org.apache.commons.math3.distribution.RealDistribution.cumulativeProbability方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。