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.microflexinteger.stat.PercentileTest.java

/**
 * Tests the aggregated plate statistics method.
 *//*  w w w.  j a v  a2 s .  c  o  m*/
@Test
public void testAggregatedPlate() {

    for (Plate plate : array) {

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

        List<Double> resultList = new ArrayList<Double>();
        double aggregatedReturned = Precision.round(percentile.platesAggregated(plate, inputPercentile),
                precision);

        for (Well well : plate) {
            resultList.addAll(well.toDouble());
        }

        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 resultAggregated = Precision.round(statAggregated.getPercentile(inputPercentile), precision);

        assertTrue(resultAggregated == aggregatedReturned);
    }
}

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

/**
 * Tests the aggregated plate statistics method using the values between the indices of
 * the collection.//w  w  w  .j  a  va  2  s  .  c om
 */
@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<Plate> collection = Arrays.asList(arrayIndices);
    Map<Plate, Double> aggregatedReturnedMap = percentile.platesAggregated(collection, begin, end - begin,
            inputPercentile);

    Map<Plate, Double> aggregatedResultMap = new TreeMap<Plate, Double>();

    for (Plate plate : collection) {

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

        for (Well well : plate) {
            resultList.addAll(well.toDouble().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 aggregatedResult = statAggregated.getPercentile(inputPercentile);

        aggregatedResultMap.put(plate, aggregatedResult);
    }

    for (Plate plate : collection) {

        double result = Precision.round(aggregatedResultMap.get(plate), precision);
        double returned = Precision.round(aggregatedReturnedMap.get(plate), precision);

        assertTrue(result == returned);
    }
}

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

/**
 * Tests the aggregated plate statistics method.
 *//*www. j ava  2 s  .  com*/
@Test
public void testAggregatedSet() {

    for (Plate plate : array) {

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

        List<Double> resultList = new ArrayList<Double>();
        double aggregatedReturned = Precision.round(percentile.setsAggregated(plate.dataSet(), inputPercentile),
                precision);

        for (Well well : plate) {
            resultList.addAll(well.toDouble());
        }

        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 resultAggregated = Precision.round(statAggregated.getPercentile(inputPercentile), precision);

        assertTrue(resultAggregated == aggregatedReturned);
    }
}

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

/**
 * Tests the aggregated plate statistics method using an array.
 */// w ww. j a  v  a 2s  .c o  m
@Test
public void testAggregatedSetArray() {

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

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

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

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

    for (WellSet set : setArray) {

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

        for (Well well : set) {
            resultList.addAll(well.toDouble());
        }

        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 aggregatedResult = statAggregated.getPercentile(inputPercentile);

        aggregatedResultMap.put(set, aggregatedResult);
    }

    for (WellSet set : setArray) {

        double result = Precision.round(aggregatedResultMap.get(set), precision);
        double returned = Precision.round(aggregatedReturnedMap.get(set), precision);

        assertTrue(result == returned);
    }

}

From source file:com.github.jessemull.microflex.stat.statdouble.PercentileDoubleTest.java

/**
 * Tests the aggregated plate statistics method using the values between the indices of
 * the array.//from w  ww  .j  ava 2 s .  co  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<PlateDouble, Double> aggregatedReturnedMap = percentile.platesAggregated(arrayIndices, begin,
            end - begin, inputPercentile);
    Map<PlateDouble, Double> aggregatedResultMap = new TreeMap<PlateDouble, Double>();

    for (PlateDouble plate : arrayIndices) {

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

        for (WellDouble well : plate) {
            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 aggregatedResult = statAggregated.getPercentile(inputPercentile);

        aggregatedResultMap.put(plate, aggregatedResult);
    }

    for (PlateDouble plate : arrayIndices) {

        double result = Precision.round(aggregatedResultMap.get(plate), precision);
        double returned = Precision.round(aggregatedReturnedMap.get(plate), precision);

        assertTrue(result == returned);
    }
}

From source file:com.github.jessemull.microflex.stat.statinteger.PercentileIntegerTest.java

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

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

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

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

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

    for (WellSetInteger set : collection) {

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

        for (WellInteger well : set) {
            resultList.addAll(well.toDouble());
        }

        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 aggregatedResult = statAggregated.getPercentile(inputPercentile);

        aggregatedResultMap.put(set, aggregatedResult);
    }

    for (WellSetInteger set : collection) {

        double result = Precision.round(aggregatedResultMap.get(set), precision);
        double returned = Precision.round(aggregatedReturnedMap.get(set), precision);

        assertTrue(result == returned);
    }
}

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

/**
 * Tests the aggregated plate statistics method.
 *///from w ww .j  ava 2  s .c om
@Test
public void testAggregatedPlate() {

    for (Plate plate : array) {

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

        List<Double> resultList = new ArrayList<Double>();
        double aggregatedReturned = Precision.round(percentile.platesAggregated(plate, inputPercentile),
                precision);

        for (Well well : plate) {
            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 resultAggregated = Precision.round(statAggregated.getPercentile(inputPercentile), precision);

        assertTrue(resultAggregated == aggregatedReturned);
    }
}

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

/**
 * Tests the aggregated plate statistics method using the values between the indices of
 * the collection./*from  w ww.  j  av  a  2 s  .c om*/
 */
@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<Plate> collection = Arrays.asList(arrayIndices);
    Map<Plate, Double> aggregatedReturnedMap = percentile.platesAggregated(collection, begin, end - begin,
            inputPercentile);

    Map<Plate, Double> aggregatedResultMap = new TreeMap<Plate, Double>();

    for (Plate plate : collection) {

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

        for (Well well : plate) {
            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 aggregatedResult = statAggregated.getPercentile(inputPercentile);

        aggregatedResultMap.put(plate, aggregatedResult);
    }

    for (Plate plate : collection) {

        double result = Precision.round(aggregatedResultMap.get(plate), precision);
        double returned = Precision.round(aggregatedReturnedMap.get(plate), precision);

        assertTrue(result == returned);
    }
}

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

/**
 * Tests the aggregated plate statistics method.
 *//*from  www.j av a  2s .c om*/
@Test
public void testAggregatedSet() {

    for (Plate plate : array) {

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

        List<Double> resultList = new ArrayList<Double>();
        double aggregatedReturned = Precision.round(percentile.setsAggregated(plate.dataSet(), inputPercentile),
                precision);

        for (Well well : plate) {
            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 resultAggregated = Precision.round(statAggregated.getPercentile(inputPercentile), precision);

        assertTrue(resultAggregated == aggregatedReturned);
    }
}

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

/**
 * Tests the aggregated plate statistics method using an array.
 *///from   ww w  .  j  a  v a2 s  .c om
@Test
public void testAggregatedSetArray() {

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

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

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

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

    for (WellSet set : setArray) {

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

        for (Well 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 aggregatedResult = statAggregated.getPercentile(inputPercentile);

        aggregatedResultMap.put(set, aggregatedResult);
    }

    for (WellSet set : setArray) {

        double result = Precision.round(aggregatedResultMap.get(set), precision);
        double returned = Precision.round(aggregatedReturnedMap.get(set), precision);

        assertTrue(result == returned);
    }

}