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

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

Introduction

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

Prototype

public double getVariance() 

Source Link

Document

Returns the (sample) variance of the available values.

Usage

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

/**
 * Tests well calculation./*from   w  w w.  ja va 2  s .c o  m*/
 */
@Test
public void testWell() {

    for (Plate plate : array) {

        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(input);
            double resultDouble = stat.getVariance();
            resultDouble *= well.size() - 1;
            resultDouble /= well.size();

            BigDecimal returned = variance.well(well, mc);
            BigDecimal result = new BigDecimal(resultDouble);

            BigDecimal[] corrected = correctRoundingErrors(returned, result);
            assertEquals(corrected[0], corrected[1]);
        }
    }
}

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

/**
 * Tests well calculation.//from   ww w. j  av a 2  s .  c  om
 */
@Test
public void testWell() {

    for (PlateBigInteger plate : array) {

        for (WellBigInteger well : plate) {

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

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

            DescriptiveStatistics stat = new DescriptiveStatistics(input);
            double resultDouble = stat.getVariance();
            resultDouble *= well.size() - 1;
            resultDouble /= well.size();

            BigDecimal returned = variance.well(well, mc);
            BigDecimal result = new BigDecimal(resultDouble);

            BigDecimal[] corrected = correctRoundingErrors(returned, result);
            assertEquals(corrected[0], corrected[1]);
        }
    }
}

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

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

    List<Plate> collection = Arrays.asList(array);
    Map<Plate, BigDecimal> aggregatedReturnedMap = variance.platesAggregated(collection, mc);
    Map<Plate, BigDecimal> aggregatedResultMap = new TreeMap<Plate, BigDecimal>();

    for (Plate plate : collection) {

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

        for (Well well : plate) {
            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.getVariance();

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

    for (Plate 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.microflexbiginteger.stat.SampleVarianceTest.java

/**
 * Tests the aggregated plate statistics method using an array.
 *//*from   w w w. j  a  v  a  2 s.  com*/
@Test
public void testAggregatedPlateArray() {

    Map<Plate, BigDecimal> aggregatedReturnedMap = variance.platesAggregated(array, mc);
    Map<Plate, BigDecimal> aggregatedResultMap = new TreeMap<Plate, BigDecimal>();

    for (Plate plate : array) {

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

        for (Well well : plate) {
            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.getVariance();

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

    for (Plate plate : array) {

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

/**
 * Tests the aggregated plate statistics method using a collection.
 *//*  w  w w  .  ja v a2  s . c  om*/
@Test
public void testAggregatedPlateCollection() {

    List<PlateBigInteger> collection = Arrays.asList(array);
    Map<PlateBigInteger, BigDecimal> aggregatedReturnedMap = variance.platesAggregated(collection, mc);
    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());
        }

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

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

/**
 * Tests the aggregated plate statistics method using an array.
 *///from   w w  w  .  j a  va 2 s . c  om
@Test
public void testAggregatedPlateArray() {

    Map<PlateBigInteger, BigDecimal> aggregatedReturnedMap = variance.platesAggregated(array, mc);
    Map<PlateBigInteger, BigDecimal> aggregatedResultMap = new TreeMap<PlateBigInteger, BigDecimal>();

    for (PlateBigInteger plate : array) {

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

        for (WellBigInteger well : plate) {
            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.getVariance();

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

    for (PlateBigInteger plate : array) {

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

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

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

    Map<PlateBigDecimal, BigDecimal> aggregatedReturnedMap = variance.platesAggregated(arrayIndices, begin,
            end - begin, mc);
    Map<PlateBigDecimal, BigDecimal> aggregatedResultMap = new TreeMap<PlateBigDecimal, BigDecimal>();

    for (PlateBigDecimal plate : arrayIndices) {

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

        for (WellBigDecimal 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 resultAggregatedDouble = statAggregated.getVariance();

        BigDecimal aggregatedResult = new BigDecimal(resultAggregatedDouble);

        aggregatedResultMap.put(plate, aggregatedResult);
    }

    for (PlateBigDecimal 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.microflexbigdecimal.stat.SampleVarianceTest.java

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

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

    Map<Plate, BigDecimal> aggregatedReturnedMap = variance.platesAggregated(arrayIndices, begin, end - begin,
            mc);
    Map<Plate, BigDecimal> aggregatedResultMap = new TreeMap<Plate, BigDecimal>();

    for (Plate plate : arrayIndices) {

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

        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 resultAggregatedDouble = statAggregated.getVariance();

        BigDecimal aggregatedResult = new BigDecimal(resultAggregatedDouble);

        aggregatedResultMap.put(plate, aggregatedResult);
    }

    for (Plate 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.microflex.stat.statbigdecimal.SampleVarianceBigDecimalTest.java

/**
 * Tests the aggregated plate statistics method using the values between the indices of
 * the collection.//from  w  w w.ja  v  a2 s  .  c om
 */
@Test
public void testAggregatedPlateCollectionIndices() {

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

    List<PlateBigDecimal> collection = Arrays.asList(arrayIndices);
    Map<PlateBigDecimal, BigDecimal> aggregatedReturnedMap = variance.platesAggregated(collection, begin,
            end - begin, mc);

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

    for (PlateBigDecimal plate : collection) {

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

        for (WellBigDecimal 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 resultAggregatedDouble = statAggregated.getVariance();

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

    for (PlateBigDecimal 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.statbigdecimal.SampleVarianceBigDecimalTest.java

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

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

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

    Map<WellSetBigDecimal, BigDecimal> aggregatedReturnedMap = variance.setsAggregated(collection, mc);
    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.getVariance();

        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]);
    }
}