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


Java Percentile类代码示例

本文整理汇总了Java中org.apache.commons.math3.stat.descriptive.rank.Percentile的典型用法代码示例。如果您正苦于以下问题:Java Percentile类的具体用法?Java Percentile怎么用?Java Percentile使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Percentile类属于org.apache.commons.math3.stat.descriptive.rank包,在下文中一共展示了Percentile类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getPercentile

import org.apache.commons.math3.stat.descriptive.rank.Percentile; //导入依赖的package包/类
/**
 * Returns an estimate for the pth percentile of the stored values.
 * <p>
 * The implementation provided here follows the first estimation procedure presented
 * <a href="http://www.itl.nist.gov/div898/handbook/prc/section2/prc252.htm">here.</a>
 * </p><p>
 * <strong>Preconditions</strong>:<ul>
 * <li><code>0 &lt; p &le; 100</code> (otherwise an
 * <code>MathIllegalArgumentException</code> is thrown)</li>
 * <li>at least one value must be stored (returns <code>Double.NaN
 *     </code> otherwise)</li>
 * </ul></p>
 *
 * @param p the requested percentile (scaled from 0 - 100)
 * @return An estimate for the pth percentile of the stored data
 * @throws MathIllegalStateException if percentile implementation has been
 *  overridden and the supplied implementation does not support setQuantile
 * @throws MathIllegalArgumentException if p is not a valid quantile
 */
public double getPercentile(double p) throws MathIllegalStateException, MathIllegalArgumentException {
    if (percentileImpl instanceof Percentile) {
        ((Percentile) percentileImpl).setQuantile(p);
    } else {
        try {
            percentileImpl.getClass().getMethod(SET_QUANTILE_METHOD_NAME,
                    new Class[] {Double.TYPE}).invoke(percentileImpl,
                            new Object[] {Double.valueOf(p)});
        } catch (NoSuchMethodException e1) { // Setter guard should prevent
            throw new MathIllegalStateException(
                  LocalizedFormats.PERCENTILE_IMPLEMENTATION_UNSUPPORTED_METHOD,
                  percentileImpl.getClass().getName(), SET_QUANTILE_METHOD_NAME);
        } catch (IllegalAccessException e2) {
            throw new MathIllegalStateException(
                  LocalizedFormats.PERCENTILE_IMPLEMENTATION_CANNOT_ACCESS_METHOD,
                  SET_QUANTILE_METHOD_NAME, percentileImpl.getClass().getName());
        } catch (InvocationTargetException e3) {
            throw new IllegalStateException(e3.getCause());
        }
    }
    return apply(percentileImpl);
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:42,代码来源:DescriptiveStatistics.java

示例2: subsetReadCountsToUsableTargets

import org.apache.commons.math3.stat.descriptive.rank.Percentile; //导入依赖的package包/类
/**
 * Subsets targets in the input count to the usable ones based on the percentile threshold indicated
 * by the user.
 *
 * <p>
 *     It returns a pair of object, where the left one is the updated read-counts with only the usable
 *     targets, and the right one is the corresponding target factors.
 * </p>
 *
 * @param readCounts the input read-counts.
 * @param targetFactorPercentileThreshold the minimum median count percentile under which targets are not considered useful.
 * @return never {@code null}.
 */
@VisibleForTesting
static Pair<ReadCountCollection, double[]> subsetReadCountsToUsableTargets(final ReadCountCollection readCounts,
                                                                           final double targetFactorPercentileThreshold, final Logger logger) {
    final double[] targetFactors = calculateTargetFactors(readCounts);
    final double threshold = new Percentile(targetFactorPercentileThreshold).evaluate(targetFactors);
    final List<Target> targetByIndex = readCounts.targets();
    final Set<Target> result = IntStream.range(0, targetFactors.length).filter(i -> targetFactors[i] >= threshold)
            .mapToObj(targetByIndex::get)
            .collect(Collectors.toCollection(LinkedHashSet::new));
    if (result.size() == targetByIndex.size()) {
        logger.info(String.format("All %d targets are kept", targetByIndex.size()));
        return new ImmutablePair<>(readCounts, targetFactors);
    } else {
        final int discardedCount = targetFactors.length - result.size();
        logger.info(String.format("Discarded %d target(s) out of %d with factors below %.2g (%.2f percentile)", discardedCount, targetFactors.length, threshold, targetFactorPercentileThreshold  ));
        final double[] targetFactorSubset = DoubleStream.of(targetFactors).filter(i -> i >= threshold).toArray();
        return new ImmutablePair<>(readCounts.subsetTargets(result), targetFactorSubset);
    }
}
 
开发者ID:broadinstitute,项目名称:gatk-protected,代码行数:33,代码来源:HDF5PCACoveragePoNCreationUtils.java

示例3: testTruncateExtremeCounts

import org.apache.commons.math3.stat.descriptive.rank.Percentile; //导入依赖的package包/类
@Test(dataProvider="readCountAndPercentileData")
public void testTruncateExtremeCounts(final ReadCountCollection readCount, final double percentile) {
    final RealMatrix counts = readCount.counts();
    final double[] allCounts = Stream.of(counts.getData())
            .flatMap(row -> DoubleStream.of(row).boxed())
            .mapToDouble(Double::doubleValue).toArray();
    final double bottom = new Percentile(percentile).evaluate(allCounts);
    final double top = new Percentile(100 - percentile).evaluate(allCounts);
    final double[][] expected = new double[counts.getRowDimension()][];
    for (int i = 0; i < expected.length; i++) {
        expected[i] = DoubleStream.of(counts.getRow(i)).map(d -> d < bottom ? bottom : (d > top) ? top : d).toArray();
    }
    ReadCountCollectionUtils.truncateExtremeCounts(readCount, percentile, NULL_LOGGER);
    final RealMatrix newCounts = readCount.counts();
    Assert.assertEquals(newCounts.getRowDimension(), newCounts.getRowDimension());
    Assert.assertEquals(newCounts.getColumnDimension(), newCounts.getColumnDimension());
    for (int i = 0; i < expected.length; i++) {
        for (int j = 0; j < expected[i].length; j++) {
            Assert.assertEquals(newCounts.getEntry(i, j), expected[i][j]);
        }
    }
}
 
开发者ID:broadinstitute,项目名称:gatk-protected,代码行数:23,代码来源:ReadCountCollectionUtilsUnitTest.java

示例4: testExtremeMedianColumnsData

import org.apache.commons.math3.stat.descriptive.rank.Percentile; //导入依赖的package包/类
@Test(dataProvider="readCountAndPercentileData")
public void testExtremeMedianColumnsData(final ReadCountCollection readCount, final double percentile) {
    final Median median = new Median();
    final RealMatrix counts = readCount.counts();
    final double[] columnMedians = IntStream.range(0, counts.getColumnDimension())
            .mapToDouble(i -> median.evaluate(counts.getColumn(i))).toArray();
    final double top = new Percentile(100 - percentile).evaluate(columnMedians);
    final double bottom = new Percentile(percentile).evaluate(columnMedians);
    final Boolean[] toBeKept = DoubleStream.of(columnMedians)
            .mapToObj(d -> d <= top && d >= bottom).toArray(Boolean[]::new);
    final int toBeKeptCount = (int) Stream.of(toBeKept).filter(b -> b).count();
    final ReadCountCollection result = ReadCountCollectionUtils.removeColumnsWithExtremeMedianCounts(readCount, percentile, NULL_LOGGER);
    Assert.assertEquals(result.columnNames().size(), toBeKeptCount);
    int nextIndex = 0;
    for (int i = 0; i < toBeKept.length; i++) {
        if (toBeKept[i]) {
            int index = result.columnNames().indexOf(readCount.columnNames().get(i));
            Assert.assertEquals(index, nextIndex++);
            Assert.assertEquals(counts.getColumn(i), result.counts().getColumn(index));
        } else {
            Assert.assertEquals(result.columnNames().indexOf(readCount.columnNames().get(i)), -1);
        }
    }
}
 
开发者ID:broadinstitute,项目名称:gatk-protected,代码行数:25,代码来源:ReadCountCollectionUtilsUnitTest.java

示例5: testSubsetTargetToUsableOnes

import org.apache.commons.math3.stat.descriptive.rank.Percentile; //导入依赖的package包/类
@Test(dataProvider="readCountAndPercentileData")
public void testSubsetTargetToUsableOnes(final ReadCountCollection readCount, final double percentile) {
    final Median median = new Median();
    final RealMatrix counts = readCount.counts();
    final double[] targetMedians = IntStream.range(0, counts.getRowDimension())
            .mapToDouble(i -> median.evaluate(counts.getRow(i))).toArray();
    final double threshold = new Percentile(percentile).evaluate(targetMedians);
    final Boolean[] toBeKept = DoubleStream.of(targetMedians)
            .mapToObj(d -> d >= threshold).toArray(Boolean[]::new);
    final int toBeKeptCount = (int) Stream.of(toBeKept).filter(b -> b).count();
    final Pair<ReadCountCollection, double[]> result = HDF5PCACoveragePoNCreationUtils.subsetReadCountsToUsableTargets(readCount, percentile, NULL_LOGGER);
    Assert.assertEquals(result.getLeft().targets().size(), toBeKeptCount);
    Assert.assertEquals(result.getRight().length, toBeKeptCount);
    int nextIndex = 0;
    for (int i = 0; i < toBeKept.length; i++) {
        if (toBeKept[i]) {
            int index = result.getLeft().targets().indexOf(readCount.targets().get(i));
            Assert.assertEquals(index, nextIndex++);
            Assert.assertEquals(counts.getRow(i), result.getLeft().counts().getRow(index));
            Assert.assertEquals(result.getRight()[index], targetMedians[i]);
        } else {
            Assert.assertEquals(result.getLeft().targets().indexOf(readCount.targets().get(i)), -1);
        }
    }
}
 
开发者ID:broadinstitute,项目名称:gatk-protected,代码行数:26,代码来源:HDF5PCACoveragePoNCreationUtilsUnitTest.java

示例6: process

import org.apache.commons.math3.stat.descriptive.rank.Percentile; //导入依赖的package包/类
@Override
public void process(DataFrame input) {
    double[] metrics = input.getDoubleColumnByName(columnName);
    int len = metrics.length;
    lowCutoff = new Percentile().evaluate(metrics, percentile);
    highCutoff = new Percentile().evaluate(metrics, 100.0 - percentile);

    output = input.copy();
    double[] resultColumn = new double[len];
    for (int i = 0; i < len; i++) {
        double curVal = metrics[i];
        if ((curVal > highCutoff && includeHigh)
                || (curVal < lowCutoff && includeLow)
                ) {
            resultColumn[i] = 1.0;
        }
    }
    output.addDoubleColumn(outputColumnName, resultColumn);
}
 
开发者ID:stanford-futuredata,项目名称:macrobase,代码行数:20,代码来源:PercentileClassifier.java

示例7: computeScoreStats

import org.apache.commons.math3.stat.descriptive.rank.Percentile; //导入依赖的package包/类
private Percentile computeScoreStats(String type) throws Exception {
	int alignmentNum = baseAlignments.size();		
	Percentile percentile = new Percentile();
	double[] scores = new double[alignmentNum];
	System.out.print("Computing accuracy of alignment samples...\n");
	for (int i = 0; i < alignmentNum; i++) {
		FastaAlignment testAlign = baseAlignments.get(i);	
		if (i % 100 == 0) System.out.println(i+" of "+alignmentNum);
		if (type.equals("fsa")) {
			scores[i] = refAlignment.getFsaScore(testAlign);
		}
		else if (type.equals("scol")) {
			
		}
		else throw new RuntimeException("Score type `"+type+"' not recognised.");
	}
	System.out.println("...done.");
	percentile.setData(scores);
	return percentile;
}
 
开发者ID:statalign,项目名称:WeaveAlign,代码行数:21,代码来源:AlignmentsEvaluator.java

示例8: printScoreStatsToScreen

import org.apache.commons.math3.stat.descriptive.rank.Percentile; //导入依赖的package包/类
private void printScoreStatsToScreen() throws Exception {
		double wvaFsaScore = refAlignment.getFsaScore(wvaAlignment);
//		double wvaScolScore = refAlignment.getScolScore(wvaAlignment);
		
		System.out.printf("WeaveAlign sum-of-pairs (AMA) score = %5.3f\n", wvaFsaScore);
		//System.out.printf("WeaveAlign column score = %5.3f\n", wvaScolScore);
		
		Percentile percentileFsa = computeScoreStats("fsa");		
		System.out.println("AMA scores for inputted alignment samples:");
		System.out.printf("%-10s%12s%12s%12s\n","Percentile","5%","50%","95%");
		System.out.printf("%-10s%12.3f%12.3f%12.3f\n","Score",percentileFsa.evaluate(5.0),percentileFsa.evaluate(50.0),percentileFsa.evaluate(95.0));
//		Percentile percentileScol = computeScoreStats("scol");
//		System.out.println("Column scores for inputted alignment samples:");
//		System.out.printf("%12s%12s%12s\n","5%","50%","95%");
//		System.out.printf("%12.3f%12.3f%12.3f\n",percentileScol.evaluate(5.0),percentileScol.evaluate(50.0),percentileScol.evaluate(95.0));
		
		printSummaryToScreen(wvaFsaScore,percentileFsa.getData(),"sum-of-pairs");
	}
 
开发者ID:statalign,项目名称:WeaveAlign,代码行数:19,代码来源:AlignmentsEvaluator.java

示例9: getPercentile

import org.apache.commons.math3.stat.descriptive.rank.Percentile; //导入依赖的package包/类
/**
 * Get the percentile value of the data
 * 
 * @param percentile
 *            The percentile
 * @return the percentile value
 */
public float getPercentile(double percentile)
{
	// Check the input
	if (percentile <= 0)
		percentile = Double.MIN_NORMAL;
	if (percentile > 100)
		percentile = 100;
	
	// The data should not have NaN so we ignore them for speed.
	final Percentile p = new Percentile(percentile).withNaNStrategy(NaNStrategy.FIXED);
	final int size = width * height;
	final double[] values = new double[size];
	for (int i = 0; i < size; i++)
		values[i] = data[i];
	return (float) p.evaluate(values);
}
 
开发者ID:aherbert,项目名称:GDSC-SMLM,代码行数:24,代码来源:DataEstimator.java

示例10: getPercentile

import org.apache.commons.math3.stat.descriptive.rank.Percentile; //导入依赖的package包/类
@Override
public double getPercentile(double rank) {
    if (count == 0) {
        return Double.NaN;
    }

    if (rank == 0) {
        return getMin();
    }

    // trim
    values = Arrays.copyOf(values, count);

    Percentile p = new Percentile();
    return p.evaluate(values, rank);
}
 
开发者ID:msteindorfer,项目名称:jmh,代码行数:17,代码来源:ListStatistics.java

示例11: testTadPercentile1

import org.apache.commons.math3.stat.descriptive.rank.Percentile; //导入依赖的package包/类
@Test
public void testTadPercentile1() throws Exception {
    INDArray array = Nd4j.linspace(1, 10, 10);
    Transforms.reverse(array, false);
    Percentile percentile = new Percentile(75);
    double exp = percentile.evaluate(array.data().asDouble());

    INDArray matrix = Nd4j.create(10, 10);
    for (int i = 0; i < matrix.rows(); i++)
        matrix.getRow(i).assign(array);

    INDArray res = matrix.percentile(75, 1);

    for (int i = 0; i < matrix.rows(); i++)
        assertEquals(exp, res.getDouble(i), 1e-5);
}
 
开发者ID:deeplearning4j,项目名称:nd4j,代码行数:17,代码来源:Nd4jTestsC.java

示例12: calculatePercentiles

import org.apache.commons.math3.stat.descriptive.rank.Percentile; //导入依赖的package包/类
public static List<List<Double>> calculatePercentiles(List<List<Double>> list, int[] percentiles) {

    double value = 0.0;

    List<Double> percentile = new ArrayList<>();
    for (List<Double> l : list) {
      for (int p : percentiles) {
        value = new Percentile().evaluate(listToDoubleArray(l), p);
        value = Math.round(value * 100.0) / 100.0;
        percentile.add(value);
      }
    }
    return getSubLists(percentile, percentiles.length);

  }
 
开发者ID:zoho-labs,项目名称:Explainer,代码行数:16,代码来源:ExplainerUtils.java

示例13: filterDataStream

import org.apache.commons.math3.stat.descriptive.rank.Percentile; //导入依赖的package包/类
/**
 * Evaluates 80% percentile
 * @param sampleSet set of sample names from coverage file
 * @param map value from geneStatistics map
 * @param list list of numbers from geneStatistics by sample
 * @return 80% percentile
 */
//perl version: 80 str
double filterDataStream(Set<String> sampleSet, Map<String, Double> map, List<Double> list) {
    for (String sample : sampleSet) {
        if (map.containsKey(sample)) {
            list.add(map.get(sample));
        }
    }
    double[] result = toDoubleArray(list);
    Percentile perc = new Percentile(80).withEstimationType(Percentile.EstimationType.R_5);
    return perc.evaluate(result);
}
 
开发者ID:AstraZeneca-NGS,项目名称:Seq2CJava,代码行数:19,代码来源:Cov2lr.java

示例14: DecileCollection

import org.apache.commons.math3.stat.descriptive.rank.Percentile; //导入依赖的package包/类
/**
 * Constructs a DecileCollection from a list of samples using Apache Commons {@link Percentile}.
 * @param samples   list of samples (caution should be used if this contains NaN or infinite values)
 */
public DecileCollection(final List<Double> samples) {
    Utils.nonNull(samples);
    Utils.validateArg(!samples.isEmpty(), "Cannot construct deciles for empty list of samples.");

    final Percentile percentile = new Percentile();
    percentile.setData(Doubles.toArray(samples));
    final Decile[] decileKeys = Decile.values();
    for (int i = 1; i < 10; i++) {
        final double decile = percentile.evaluate(10 * i);
        deciles.put(decileKeys[i - 1], decile);
    }
}
 
开发者ID:broadinstitute,项目名称:gatk-protected,代码行数:17,代码来源:DecileCollection.java

示例15: calculateSegmentMeanBiasInCRSpace

import org.apache.commons.math3.stat.descriptive.rank.Percentile; //导入依赖的package包/类
private double calculateSegmentMeanBiasInCRSpace(final List<ACNVModeledSegment> segments) {
    Utils.nonNull(segments);

    final double neutralCRApprox = 1;

    // Only consider values "close enough" to copy neutral (CR == 1).
    final double[] neutralSegmentMeans = segments.stream().mapToDouble(ACNVModeledSegment::getSegmentMeanInCRSpace)
            .filter(x -> Math.abs(x - neutralCRApprox) < CLOSE_ENOUGH_TO_COPY_NEUTRAL_IN_CR)
            .toArray();

    return new Percentile().evaluate(neutralSegmentMeans) - 1;
}
 
开发者ID:broadinstitute,项目名称:gatk-protected,代码行数:13,代码来源:CNLOHCaller.java


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