Example usage for org.apache.commons.math3.stat.descriptive DescriptiveStatistics getPercentile

List of usage examples for org.apache.commons.math3.stat.descriptive DescriptiveStatistics getPercentile

Introduction

In this page you can find the example usage for org.apache.commons.math3.stat.descriptive DescriptiveStatistics getPercentile.

Prototype

public double getPercentile(double p) throws MathIllegalStateException, MathIllegalArgumentException 

Source Link

Document

Returns an estimate for the pth percentile of the stored values.

Usage

From source file:com.github.jessemull.microflexbiginteger.stat.PercentileTest.java

/**
 * Tests the plate statistics method using the values between the indices.
 *//*  w ww .  ja  v a2s. co  m*/
@Test
public void testPlateIndices() {

    for (Plate plate : arrayIndices) {

        int inputPercentile = 1 + random.nextInt(100);

        int size = arrayIndices[0].first().size();
        int begin = random.nextInt(size - 5);
        int end = (begin + 4) + random.nextInt(size - (begin + 4) + 1);

        Map<Well, BigDecimal> resultMap = new TreeMap<Well, BigDecimal>();
        Map<Well, BigDecimal> returnedMap = percentile.plate(plate, begin, end - begin, inputPercentile);

        for (Well well : plate) {

            double[] input = new double[well.size()];
            int index = 0;

            for (BigInteger bi : well) {
                input[index++] = bi.doubleValue();
            }

            DescriptiveStatistics stat = new DescriptiveStatistics(ArrayUtils.subarray(input, begin, end));
            double resultDouble = stat.getPercentile(inputPercentile);

            BigDecimal result = new BigDecimal(resultDouble);

            resultMap.put(well, result);
        }

        for (Well well : plate) {

            BigDecimal result = resultMap.get(well);
            BigDecimal returned = returnedMap.get(well);

            BigDecimal[] corrected = correctRoundingErrors(result, returned);

            assertEquals(corrected[0], corrected[1]);
        }
    }
}

From source file:com.github.jessemull.microflexbiginteger.stat.PercentileTest.java

/**
 * Tests the aggregated plate statistics method using the values between the indices of
 * the collection./*w  w w.  java 2  s  .co m*/
 */
@Test
public void testAggregatedSetCollectionIndices() {

    int inputPercentile = 1 + random.nextInt(100);

    int size = arrayIndices[0].first().size();
    int begin = random.nextInt(size - 5);
    int end = (begin + 4) + random.nextInt(size - (begin + 4) + 1);

    List<WellSet> collection = new ArrayList<WellSet>();

    for (Plate plate : arrayIndices) {
        collection.add(plate.dataSet());
    }

    Map<WellSet, BigDecimal> aggregatedReturnedMap = percentile.setsAggregated(collection, begin, end - begin,
            inputPercentile);
    Map<WellSet, BigDecimal> aggregatedResultMap = new TreeMap<WellSet, BigDecimal>();

    for (WellSet set : collection) {

        List<BigDecimal> resultList = new ArrayList<BigDecimal>();

        for (Well well : set) {
            resultList.addAll(well.toBigDecimal().subList(begin, end));
        }

        double[] inputAggregated = new double[resultList.size()];

        for (int i = 0; i < resultList.size(); i++) {
            inputAggregated[i] = resultList.get(i).doubleValue();
        }

        DescriptiveStatistics statAggregated = new DescriptiveStatistics(inputAggregated);
        double resultAggregatedDouble = statAggregated.getPercentile(inputPercentile);

        BigDecimal aggregatedResult = new BigDecimal(resultAggregatedDouble);
        aggregatedResultMap.put(set, aggregatedResult);
    }

    for (WellSet set : collection) {

        BigDecimal result = aggregatedResultMap.get(set);
        BigDecimal returned = aggregatedReturnedMap.get(set);
        BigDecimal[] corrected = correctRoundingErrors(result, returned);

        assertEquals(corrected[0], corrected[1]);
    }
}

From source file:com.github.jessemull.microflex.stat.statbigdecimal.PercentileBigDecimalTest.java

/**
 * Tests the aggregated plate statistics method using a collection.
 *///  w  w w  . jav  a 2  s .  co m
@Test
public void testAggregatedSetCollection() {

    int inputPercentile = 1 + random.nextInt(100);

    List<WellSetBigDecimal> collection = new ArrayList<WellSetBigDecimal>();

    for (PlateBigDecimal plate : array) {
        collection.add(plate.dataSet());
    }

    Map<WellSetBigDecimal, BigDecimal> aggregatedReturnedMap = percentile.setsAggregated(collection,
            inputPercentile);
    Map<WellSetBigDecimal, BigDecimal> aggregatedResultMap = new TreeMap<WellSetBigDecimal, BigDecimal>();

    for (WellSetBigDecimal set : collection) {

        List<BigDecimal> resultList = new ArrayList<BigDecimal>();

        for (WellBigDecimal well : set) {
            resultList.addAll(well.data());
        }

        double[] inputAggregated = new double[resultList.size()];

        for (int i = 0; i < resultList.size(); i++) {
            inputAggregated[i] = resultList.get(i).doubleValue();
        }

        DescriptiveStatistics statAggregated = new DescriptiveStatistics(inputAggregated);
        double resultAggregatedDouble = statAggregated.getPercentile(inputPercentile);

        BigDecimal aggregatedResult = new BigDecimal(resultAggregatedDouble);
        aggregatedResultMap.put(set, aggregatedResult);
    }

    for (WellSetBigDecimal set : collection) {

        BigDecimal result = aggregatedResultMap.get(set);
        BigDecimal returned = aggregatedReturnedMap.get(set);

        BigDecimal[] corrected = correctRoundingErrors(result, returned);

        assertEquals(corrected[0], corrected[1]);
    }
}

From source file:com.github.jessemull.microflex.stat.statbiginteger.PercentileBigIntegerTest.java

/**
 * Tests the aggregated plate statistics method using the values between the indices of
 * the array./*from  w w  w  .j ava2s . c o  m*/
 */
@Test
public void testAggregatedPlateArrayIndices() {

    int inputPercentile = 1 + random.nextInt(100);

    int size = arrayIndices[0].first().size();
    int begin = random.nextInt(size - 5);
    int end = (begin + 4) + random.nextInt(size - (begin + 4) + 1);

    Map<PlateBigInteger, BigDecimal> aggregatedReturnedMap = percentile.platesAggregated(arrayIndices, begin,
            end - begin, inputPercentile);
    Map<PlateBigInteger, BigDecimal> aggregatedResultMap = new TreeMap<PlateBigInteger, BigDecimal>();

    for (PlateBigInteger plate : arrayIndices) {

        List<BigDecimal> resultList = new ArrayList<BigDecimal>();

        for (WellBigInteger well : plate) {
            resultList.addAll(well.toBigDecimal().subList(begin, end));
        }

        double[] inputAggregated = new double[resultList.size()];

        for (int i = 0; i < resultList.size(); i++) {
            inputAggregated[i] = resultList.get(i).doubleValue();
        }

        DescriptiveStatistics statAggregated = new DescriptiveStatistics(inputAggregated);
        double resultAggregatedDouble = statAggregated.getPercentile(inputPercentile);

        BigDecimal aggregatedResult = new BigDecimal(resultAggregatedDouble);

        aggregatedResultMap.put(plate, aggregatedResult);
    }

    for (PlateBigInteger plate : arrayIndices) {

        BigDecimal result = aggregatedResultMap.get(plate);
        BigDecimal returned = aggregatedReturnedMap.get(plate);
        BigDecimal[] corrected = correctRoundingErrors(result, returned);

        assertEquals(corrected[0], corrected[1]);
    }
}

From source file:com.github.jessemull.microflexbiginteger.stat.PercentileTest.java

/**
 * Tests set calculation using indices.// w  w w . j av a2  s.  c  o  m
 */
@Test
public void testSetIndices() {

    for (Plate plate : arrayIndices) {

        int inputPercentile = 1 + random.nextInt(100);

        int size = arrayIndices[0].first().size();
        int begin = random.nextInt(size - 5);
        int end = (begin + 4) + random.nextInt(size - (begin + 4) + 1);

        Map<Well, BigDecimal> resultMap = new TreeMap<Well, BigDecimal>();
        Map<Well, BigDecimal> returnedMap = percentile.set(plate.dataSet(), begin, end - begin,
                inputPercentile);

        for (Well well : plate) {

            double[] input = new double[well.size()];
            int index = 0;

            for (BigInteger bi : well) {
                input[index++] = bi.doubleValue();
            }

            DescriptiveStatistics stat = new DescriptiveStatistics(ArrayUtils.subarray(input, begin, end));
            double resultDouble = stat.getPercentile(inputPercentile);

            BigDecimal result = new BigDecimal(resultDouble);

            resultMap.put(well, result);
        }

        for (Well well : plate) {

            BigDecimal result = resultMap.get(well);
            BigDecimal returned = returnedMap.get(well);

            BigDecimal[] corrected = correctRoundingErrors(result, returned);

            assertEquals(corrected[0], corrected[1]);
        }
    }
}

From source file:com.github.jessemull.microflexbiginteger.stat.PercentileTest.java

/**
 * Tests the aggregated plate statistics method using the values between the indices of
 * the array.//from  w  w  w  .j a  v a 2 s . c  om
 */
@Test
public void testAggregatedSetArrayIndices() {

    int inputPercentile = 1 + random.nextInt(100);

    int size = arrayIndices[0].first().size();
    int begin = random.nextInt(size - 5);
    int end = (begin + 4) + random.nextInt(size - (begin + 4) + 1);

    WellSet[] setArrayIndices = new WellSet[arrayIndices.length];

    for (int i = 0; i < setArrayIndices.length; i++) {
        setArrayIndices[i] = arrayIndices[i].dataSet();
    }

    Map<WellSet, BigDecimal> aggregatedReturnedMap = percentile.setsAggregated(setArrayIndices, begin,
            end - begin, inputPercentile);
    Map<WellSet, BigDecimal> aggregatedResultMap = new TreeMap<WellSet, BigDecimal>();

    for (WellSet set : setArrayIndices) {

        List<BigDecimal> resultList = new ArrayList<BigDecimal>();

        for (Well well : set) {
            resultList.addAll(well.toBigDecimal().subList(begin, end));
        }

        double[] inputAggregated = new double[resultList.size()];

        for (int i = 0; i < resultList.size(); i++) {
            inputAggregated[i] = resultList.get(i).doubleValue();
        }

        DescriptiveStatistics statAggregated = new DescriptiveStatistics(inputAggregated);
        double resultAggregatedDouble = statAggregated.getPercentile(inputPercentile);

        BigDecimal aggregatedResult = new BigDecimal(resultAggregatedDouble);

        aggregatedResultMap.put(set, aggregatedResult);
    }

    for (WellSet plate : setArrayIndices) {

        BigDecimal result = aggregatedResultMap.get(plate);
        BigDecimal returned = aggregatedReturnedMap.get(plate);
        BigDecimal[] corrected = correctRoundingErrors(result, returned);

        assertEquals(corrected[0], corrected[1]);
    }
}

From source file:com.github.jessemull.microflex.stat.statbigdecimal.PercentileBigDecimalTest.java

/**
 * Tests the aggregated plate statistics method using an array.
 *//*from   www.  j  a v  a2s .  c o m*/
@Test
public void testAggregatedSetArray() {

    int inputPercentile = 1 + random.nextInt(100);

    WellSetBigDecimal[] setArray = new WellSetBigDecimal[array.length];

    for (int i = 0; i < setArray.length; i++) {
        setArray[i] = array[i].dataSet();
    }

    Map<WellSetBigDecimal, BigDecimal> aggregatedReturnedMap = percentile.setsAggregated(setArray,
            inputPercentile);
    Map<WellSetBigDecimal, BigDecimal> aggregatedResultMap = new TreeMap<WellSetBigDecimal, BigDecimal>();

    for (WellSetBigDecimal set : setArray) {

        List<BigDecimal> resultList = new ArrayList<BigDecimal>();

        for (WellBigDecimal well : set) {
            resultList.addAll(well.data());
        }

        double[] inputAggregated = new double[resultList.size()];

        for (int i = 0; i < resultList.size(); i++) {
            inputAggregated[i] = resultList.get(i).doubleValue();
        }

        DescriptiveStatistics statAggregated = new DescriptiveStatistics(inputAggregated);
        double resultAggregatedDouble = statAggregated.getPercentile(inputPercentile);

        BigDecimal aggregatedResult = new BigDecimal(resultAggregatedDouble);
        aggregatedResultMap.put(set, aggregatedResult);
    }

    for (WellSetBigDecimal set : setArray) {

        BigDecimal result = aggregatedResultMap.get(set);
        BigDecimal returned = aggregatedReturnedMap.get(set);

        BigDecimal[] corrected = correctRoundingErrors(result, returned);

        assertEquals(corrected[0], corrected[1]);
    }

}

From source file:com.github.jessemull.microflex.stat.statbiginteger.PercentileBigIntegerTest.java

/**
 * Tests the aggregated plate statistics method using the values between the indices of
 * the collection.//ww  w . j  a v  a2 s  . com
 */
@Test
public void testAggregatedPlateCollectionIndices() {

    int inputPercentile = 1 + random.nextInt(100);

    int size = arrayIndices[0].first().size();
    int begin = random.nextInt(size - 5);
    int end = (begin + 4) + random.nextInt(size - (begin + 4) + 1);

    List<PlateBigInteger> collection = Arrays.asList(arrayIndices);
    Map<PlateBigInteger, BigDecimal> aggregatedReturnedMap = percentile.platesAggregated(collection, begin,
            end - begin, inputPercentile);

    Map<PlateBigInteger, BigDecimal> aggregatedResultMap = new TreeMap<PlateBigInteger, BigDecimal>();

    for (PlateBigInteger plate : collection) {

        List<BigDecimal> resultList = new ArrayList<BigDecimal>();

        for (WellBigInteger well : plate) {
            resultList.addAll(well.toBigDecimal().subList(begin, end));
        }

        double[] inputAggregated = new double[resultList.size()];

        for (int i = 0; i < resultList.size(); i++) {
            inputAggregated[i] = resultList.get(i).doubleValue();
        }

        DescriptiveStatistics statAggregated = new DescriptiveStatistics(inputAggregated);
        double resultAggregatedDouble = statAggregated.getPercentile(inputPercentile);

        BigDecimal aggregatedResult = new BigDecimal(resultAggregatedDouble);
        aggregatedResultMap.put(plate, aggregatedResult);
    }

    for (PlateBigInteger plate : collection) {

        BigDecimal result = aggregatedResultMap.get(plate);
        BigDecimal returned = aggregatedReturnedMap.get(plate);
        BigDecimal[] corrected = correctRoundingErrors(result, returned);

        assertEquals(corrected[0], corrected[1]);
    }
}

From source file:com.github.jessemull.microflex.stat.statbiginteger.PercentileBigIntegerTest.java

/**
 * Tests the aggregated plate statistics method using a collection.
 *///from w  w  w.  ja  v a  2s. c  o m
@Test
public void testAggregatedSetCollection() {

    int inputPercentile = 1 + random.nextInt(100);

    List<WellSetBigInteger> collection = new ArrayList<WellSetBigInteger>();

    for (PlateBigInteger plate : array) {
        collection.add(plate.dataSet());
    }

    Map<WellSetBigInteger, BigDecimal> aggregatedReturnedMap = percentile.setsAggregated(collection,
            inputPercentile);
    Map<WellSetBigInteger, BigDecimal> aggregatedResultMap = new TreeMap<WellSetBigInteger, BigDecimal>();

    for (WellSetBigInteger set : collection) {

        List<BigDecimal> resultList = new ArrayList<BigDecimal>();

        for (WellBigInteger well : set) {
            resultList.addAll(well.toBigDecimal());
        }

        double[] inputAggregated = new double[resultList.size()];

        for (int i = 0; i < resultList.size(); i++) {
            inputAggregated[i] = resultList.get(i).doubleValue();
        }

        DescriptiveStatistics statAggregated = new DescriptiveStatistics(inputAggregated);
        double resultAggregatedDouble = statAggregated.getPercentile(inputPercentile);

        BigDecimal aggregatedResult = new BigDecimal(resultAggregatedDouble);
        aggregatedResultMap.put(set, aggregatedResult);
    }

    for (WellSetBigInteger set : collection) {

        BigDecimal result = aggregatedResultMap.get(set);
        BigDecimal returned = aggregatedReturnedMap.get(set);

        BigDecimal[] corrected = correctRoundingErrors(result, returned);

        assertEquals(corrected[0], corrected[1]);
    }
}

From source file:com.github.jessemull.microflex.stat.statbigdecimal.PercentileBigDecimalTest.java

/**
 * Tests the aggregated plate statistics method using the values between the indices of
 * the collection./*from   w w w.j  a va 2 s  . com*/
 */
@Test
public void testAggregatedSetCollectionIndices() {

    int inputPercentile = 1 + random.nextInt(100);

    int size = arrayIndices[0].first().size();
    int begin = random.nextInt(size - 5);
    int end = (begin + 4) + random.nextInt(size - (begin + 4) + 1);

    List<WellSetBigDecimal> collection = new ArrayList<WellSetBigDecimal>();

    for (PlateBigDecimal plate : arrayIndices) {
        collection.add(plate.dataSet());
    }

    Map<WellSetBigDecimal, BigDecimal> aggregatedReturnedMap = percentile.setsAggregated(collection, begin,
            end - begin, inputPercentile);
    Map<WellSetBigDecimal, BigDecimal> aggregatedResultMap = new TreeMap<WellSetBigDecimal, BigDecimal>();

    for (WellSetBigDecimal set : collection) {

        List<BigDecimal> resultList = new ArrayList<BigDecimal>();

        for (WellBigDecimal well : set) {
            resultList.addAll(well.data().subList(begin, end));
        }

        double[] inputAggregated = new double[resultList.size()];

        for (int i = 0; i < resultList.size(); i++) {
            inputAggregated[i] = resultList.get(i).doubleValue();
        }

        DescriptiveStatistics statAggregated = new DescriptiveStatistics(inputAggregated);
        double resultAggregatedDouble = statAggregated.getPercentile(inputPercentile);

        BigDecimal aggregatedResult = new BigDecimal(resultAggregatedDouble);
        aggregatedResultMap.put(set, aggregatedResult);
    }

    for (WellSetBigDecimal set : collection) {

        BigDecimal result = aggregatedResultMap.get(set);
        BigDecimal returned = aggregatedReturnedMap.get(set);
        BigDecimal[] corrected = correctRoundingErrors(result, returned);

        assertEquals(corrected[0], corrected[1]);
    }
}