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

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

Introduction

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

Prototype

public DescriptiveStatistics(DescriptiveStatistics original) throws NullArgumentException 

Source Link

Document

Copy constructor.

Usage

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

/**
 * Tests the aggregated plate statistics method using a collection.
 *//*ww w. j  av a2s  . c o  m*/
@Test
public void testAggregatedPlateCollection() {

    List<PlateInteger> collection = Arrays.asList(array);
    Map<PlateInteger, Integer> aggregatedReturnedMap = n.platesAggregated(collection);
    Map<PlateInteger, Integer> aggregatedResultMap = new TreeMap<PlateInteger, Integer>();

    for (PlateInteger plate : collection) {

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

        for (WellInteger well : plate) {

            for (double db : well) {
                resultList.add(db);
            }

        }

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

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

        DescriptiveStatistics statAggregated = new DescriptiveStatistics(inputAggregated);
        double resultAggregated = statAggregated.getN();

        aggregatedResultMap.put(plate, (int) resultAggregated);
    }

    for (PlateInteger plate : collection) {

        int result = aggregatedResultMap.get(plate);
        int returned = aggregatedReturnedMap.get(plate);

        assertEquals(result, returned);
    }
}

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

/**
 * Tests the plate statistics method using the values between the indices.
 *//*from  w w w  .  j  av  a  2s  .  c  o  m*/
@Test
public void testPlateIndices() {

    for (Plate plate : arrayIndices) {

        int begin = random.nextInt(plate.first().size() - 4);
        int end = begin + random.nextInt(3) + 3;

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

        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.getMean();

            BigDecimal result = new BigDecimal(resultDouble, mc);

            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.microflexbigdecimal.stat.StandardDeviationTest.java

/**
 * Tests the plate statistics method using the values between the indices.
 *//*from w w  w.jav  a  2  s.  c om*/
@Test
public void testPlateIndices() {

    for (Plate plate : arrayIndices) {

        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 = deviation.plate(plate, begin, end - begin, mc);

        for (Well well : plate) {

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

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

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

            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.microflex.stat.statinteger.PopulationVarianceIntegerWeightsTest.java

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

    for (PlateInteger plate : arrayIndices) {

        int begin = random.nextInt(plate.first().size() - 4);
        int end = begin + random.nextInt(3) + 3;

        Map<WellInteger, Double> resultMap = new TreeMap<WellInteger, Double>();
        Map<WellInteger, Double> returnedMap = variance.plate(plate,
                ArrayUtils.subarray(weightsIndices, begin, end), begin, end - begin);

        for (WellInteger well : plate) {

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

            for (double db : well) {
                input[index] = db * weightsIndices[index];
                index++;
            }

            DescriptiveStatistics stat = new DescriptiveStatistics(ArrayUtils.subarray(input, begin, end));
            double result = stat.getPopulationVariance();

            resultMap.put(well, result);
        }

        for (WellInteger well : plate) {

            double result = Precision.round(resultMap.get(well), precision);
            double returned = Precision.round(returnedMap.get(well), precision);

            assertTrue(result == returned);
        }
    }
}

From source file:com.github.jessemull.microflexbigdecimal.stat.SampleVarianceTest.java

/**
 * Tests the plate statistics method using the values between the indices.
 *//*from ww  w  . jav a 2  s.  co  m*/
@Test
public void testPlateIndices() {

    for (Plate plate : arrayIndices) {

        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 = variance.plate(plate, begin, end - begin, mc);

        for (Well well : plate) {

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

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

            double[] inputArray = ArrayUtils.subarray(input, begin, end);

            DescriptiveStatistics stat = new DescriptiveStatistics(inputArray);
            double resultDouble = stat.getVariance();

            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.StandardDeviationTest.java

/**
 * Tests the plate statistics method using the values between the indices.
 *//*  w  w  w. j  a v a  2  s  . co  m*/
@Test
public void testPlateIndices() {

    for (Plate plate : arrayIndices) {

        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 = deviation.plate(plate, begin, end - begin, mc);

        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.getStandardDeviation();

            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.SampleVarianceTest.java

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

    for (Plate plate : arrayIndices) {

        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 = variance.plate(plate, begin, end - begin, mc);

        for (Well well : plate) {

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

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

            double[] inputArray = ArrayUtils.subarray(input, begin, end);

            DescriptiveStatistics stat = new DescriptiveStatistics(inputArray);
            double resultDouble = stat.getVariance();

            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.microflex.stat.statbigdecimal.MaxBigDecimalTest.java

/**
 * Tests the plate statistics method using the values between the indices.
 *//*from   w  w  w.jav a  2s .  c  om*/
@Test
public void testPlateIndices() {

    for (PlateBigDecimal plate : arrayIndices) {

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

        Map<WellBigDecimal, BigDecimal> resultMap = new TreeMap<WellBigDecimal, BigDecimal>();
        Map<WellBigDecimal, BigDecimal> returnedMap = max.plate(plate, begin, end - begin);

        for (WellBigDecimal well : plate) {

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

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

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

            BigDecimal result = new BigDecimal(resultDouble);

            resultMap.put(well, result);
        }

        for (WellBigDecimal 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.microflex.stat.statbigdecimal.MinBigDecimalTest.java

/**
 * Tests the plate statistics method using the values between the indices.
 *//*  ww w  .j  a  va  2 s . c o m*/
@Test
public void testPlateIndices() {

    for (PlateBigDecimal plate : arrayIndices) {

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

        Map<WellBigDecimal, BigDecimal> resultMap = new TreeMap<WellBigDecimal, BigDecimal>();
        Map<WellBigDecimal, BigDecimal> returnedMap = min.plate(plate, begin, end - begin);

        for (WellBigDecimal well : plate) {

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

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

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

            BigDecimal result = new BigDecimal(resultDouble);

            resultMap.put(well, result);
        }

        for (WellBigDecimal 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.microflex.stat.statbigdecimal.SumBigDecimalTest.java

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

    for (PlateBigDecimal plate : arrayIndices) {

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

        Map<WellBigDecimal, BigDecimal> resultMap = new TreeMap<WellBigDecimal, BigDecimal>();
        Map<WellBigDecimal, BigDecimal> returnedMap = sum.plate(plate, begin, end - begin, mc);

        for (WellBigDecimal well : plate) {

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

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

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

            BigDecimal result = new BigDecimal(resultDouble);

            resultMap.put(well, result);
        }

        for (WellBigDecimal well : plate) {

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

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

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