Example usage for org.apache.commons.math3.stat.descriptive.rank Median evaluate

List of usage examples for org.apache.commons.math3.stat.descriptive.rank Median evaluate

Introduction

In this page you can find the example usage for org.apache.commons.math3.stat.descriptive.rank Median evaluate.

Prototype

@Override
public double evaluate(final double[] values, final int start, final int length)
        throws MathIllegalArgumentException 

Source Link

Document

Returns an estimate of the quantileth percentile of the designated values in the values array.

Usage

From source file:org.broadinstitute.gatk.utils.genotyper.ReadLikelihoods.java

/**
 * Updates the likelihood of the NonRef allele (if present) based on the likehoods of a set of concrete
 * alleles./*from w  ww  .ja v a2 s  . c o m*/
 * <p>
 *     This method does
 * </p>
 *
 *
 * @param allelesToConsider
 */
public void updateNonRefAlleleLikelihoods(final AlleleList<A> allelesToConsider) {
    if (nonRefAlleleIndex < 0)
        return;
    final int alleleCount = alleles.alleleCount();
    final int nonRefAlleleIndex = alleleIndex((A) GATKVCFConstants.NON_REF_SYMBOLIC_ALLELE);
    final int concreteAlleleCount = nonRefAlleleIndex < 0 ? alleleCount : alleleCount - 1;
    // likelihood buffer reused across reads:
    final double[] qualifiedAlleleLikelihoods = new double[concreteAlleleCount];
    final Median medianCalculator = new Median();
    for (int s = 0; s < samples.sampleCount(); s++) {
        final double[][] sampleValues = valuesBySampleIndex[s];
        final int readCount = sampleValues[0].length;
        for (int r = 0; r < readCount; r++) {
            final BestAllele bestAllele = searchBestAllele(s, r, true);
            int numberOfQualifiedAlleleLikelihoods = 0;
            for (int i = 0; i < alleleCount; i++) {
                final double alleleLikelihood = sampleValues[i][r];
                if (i != nonRefAlleleIndex && alleleLikelihood < bestAllele.likelihood
                        && !Double.isNaN(alleleLikelihood)
                        && allelesToConsider.alleleIndex(alleles.alleleAt(i)) != -1) {
                    qualifiedAlleleLikelihoods[numberOfQualifiedAlleleLikelihoods++] = alleleLikelihood;
                }
            }
            final double nonRefLikelihood = medianCalculator.evaluate(qualifiedAlleleLikelihoods, 0,
                    numberOfQualifiedAlleleLikelihoods);
            // when the median is NaN that means that all applicable likekihoods are the same as the best
            // so the read is not informative at all given the existing alleles. Unless there is only one (or zero) concrete
            // alleles with give the same (the best) likelihood to the NON-REF. When there is only one (or zero) concrete
            // alleles we set the NON-REF likelihood to NaN.
            sampleValues[nonRefAlleleIndex][r] = !Double.isNaN(nonRefLikelihood) ? nonRefLikelihood
                    : concreteAlleleCount <= 1 ? Double.NaN : bestAllele.likelihood;
        }
    }
}

From source file:tests.RepeatTest.java

/**
 * Prints the Average/Median Runtimes of this Testcase into the Result-Output-Logger.
 * @param results// w w w  .ja v a2 s . c  o  m
 * @param algorithm
 * @throws SecurityException
 * @throws IOException
 */
public void printResults(List<Result> results, SkylineAlgorithm algorithm)
        throws SecurityException, IOException {
    // Add the Result Output-Logger
    logger.getParent().addHandler(fileHandler);

    // Calculation
    int repeatCount = results.size();
    long timeComp = 0, timeInput = 0;
    double[] compTimes = new double[repeatCount], inputTimes = new double[repeatCount];

    for (int i = 0; i < repeatCount; i++) {
        // Big RepeatCounts? Remove the first Calculations, to reduce the impact of the non-JIT-optimized Calculations
        if (i > 2 || repeatCount <= 3) {
            timeComp = timeComp + results.get(i).getTimeobject().getCalcTime();
            timeInput = timeInput + results.get(i).getTimeobject().getInputTime();
        }
        compTimes[i] = results.get(i).getTimeobject().getCalcTime();
        inputTimes[i] = results.get(i).getTimeobject().getInputTime();
    }
    if (repeatCount > 3) {
        repeatCount = repeatCount - 3;
    }
    long avgComp = timeComp / (repeatCount);
    long avgInpt = timeInput / (repeatCount);
    if (!algorithm.buildDataStructureEveryIteration)
        avgInpt = (long) inputTimes[0];

    // Average
    String str = "";
    if (printAverage) {
        str = String.format("%3d\t%5d\t%8d\t%16d\t%16d\t%5s\t%s", threadCount, dimensions, tupleCount, avgComp,
                avgInpt, "avg", algorithm.getClass().getSimpleName());
        logger.info(str);
    }

    // Median
    if (printMedian) {
        Median med = new Median();
        Double medCalc;
        Double medInpt;
        if (repeatCount > 3) {
            medCalc = med.evaluate(compTimes, 3, repeatCount);
            medInpt = med.evaluate(inputTimes, 3, repeatCount);
        } else {
            medCalc = med.evaluate(compTimes, 0, compTimes.length);
            medInpt = med.evaluate(inputTimes, 0, inputTimes.length);
        }

        if (!algorithm.buildDataStructureEveryIteration)
            medInpt = inputTimes[0];
        str = String.format("%3d\t%5d\t%8d\t%16.0f\t%16.0f\t%5s\t%s", threadCount, dimensions, tupleCount,
                medCalc, medInpt, "med", algorithm.getClass().getSimpleName());
        logger.info(str);
    }

    // Remove the Handler, the Result File should contain only Results
    logger.getParent().removeHandler(fileHandler);
}