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

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

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

    Map<Plate, BigDecimal> aggregatedReturnedMap = variance.platesAggregated(arrayIndices, weightsIndices,
            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) {

            List<BigDecimal> input = well.data().subList(begin, end);

            for (int i = 0; i < input.size(); i++) {
                resultList.add(input.get(i).multiply(new BigDecimal(weightsIndices[i])));
            }

        }

        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();
        resultAggregatedDouble *= resultList.size() - 1;
        resultAggregatedDouble /= resultList.size();

        BigDecimal aggregatedResult = new BigDecimal(resultAggregatedDouble, mc);
        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.microflexbiginteger.stat.PopulationVarianceWeightsTest.java

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

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

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

    Map<WellSet, BigDecimal> aggregatedReturnedMap = variance.setsAggregated(setArray, weights, mc);
    Map<WellSet, BigDecimal> aggregatedResultMap = new TreeMap<WellSet, BigDecimal>();

    for (WellSet set : setArray) {

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

        for (Well well : set) {

            List<BigDecimal> input = well.toBigDecimal();

            for (int i = 0; i < input.size(); i++) {
                resultList.add(input.get(i).multiply(new BigDecimal(weights[i])));
            }

        }

        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();
        resultAggregatedDouble *= resultList.size() - 1;
        resultAggregatedDouble /= resultList.size();

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

    for (WellSet 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.statbigdecimal.PopulationVarianceBigDecimalWeightsTest.java

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

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

    List<PlateBigDecimal> collection = Arrays.asList(arrayIndices);
    Map<PlateBigDecimal, BigDecimal> aggregatedReturnedMap = variance.platesAggregated(collection,
            weightsIndices, 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) {

            List<BigDecimal> input = well.data().subList(begin, end);

            for (int i = 0; i < input.size(); i++) {
                resultList.add(input.get(i).multiply(new BigDecimal(weightsIndices[i])));
            }

        }

        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();
        resultAggregatedDouble *= resultList.size() - 1;
        resultAggregatedDouble /= resultList.size();

        BigDecimal aggregatedResult = new BigDecimal(resultAggregatedDouble, mc);
        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.microflexbigdecimal.stat.PopulationVarianceWeightsTest.java

/**
 * Tests the aggregated plate statistics method using the values between the indices of
 * the collection.//from  w w  w. j ava 2  s  .  c  o m
 */
@Test
public void testAggregatedPlateCollectionIndices() {

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

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

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

    for (Plate plate : collection) {

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

        for (Well well : plate) {

            List<BigDecimal> input = well.data().subList(begin, end);

            for (int i = 0; i < input.size(); i++) {
                resultList.add(input.get(i).multiply(new BigDecimal(weightsIndices[i])));
            }

        }

        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();
        resultAggregatedDouble *= resultList.size() - 1;
        resultAggregatedDouble /= resultList.size();

        BigDecimal aggregatedResult = new BigDecimal(resultAggregatedDouble, mc);
        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.microflex.stat.statbigdecimal.PopulationVarianceBigDecimalWeightsTest.java

/**
 * Tests the aggregated plate statistics method using a collection.
 *///ww w.  j  a  v a2s .  com
@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, weights, mc);
    Map<WellSetBigDecimal, BigDecimal> aggregatedResultMap = new TreeMap<WellSetBigDecimal, BigDecimal>();

    for (WellSetBigDecimal set : collection) {

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

        for (WellBigDecimal well : set) {

            List<BigDecimal> input = well.data();

            for (int i = 0; i < input.size(); i++) {
                resultList.add(input.get(i).multiply(new BigDecimal(weights[i])));
            }

        }

        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();
        resultAggregatedDouble *= resultList.size() - 1;
        resultAggregatedDouble /= resultList.size();

        BigDecimal aggregatedResult = new BigDecimal(resultAggregatedDouble, mc);
        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.PopulationVarianceBigIntegerWeightsTest.java

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

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

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

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

    Map<WellSetBigInteger, BigDecimal> aggregatedReturnedMap = variance.setsAggregated(collection,
            weightsIndices, begin, end - begin, mc);
    Map<WellSetBigInteger, BigDecimal> aggregatedResultMap = new TreeMap<WellSetBigInteger, BigDecimal>();

    for (WellSetBigInteger set : collection) {

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

        for (WellBigInteger well : set) {

            List<BigDecimal> input = well.toBigDecimal().subList(begin, end);

            for (int i = 0; i < input.size(); i++) {
                resultList.add(input.get(i).multiply(new BigDecimal(weightsIndices[i])));
            }

        }

        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();
        resultAggregatedDouble *= resultList.size() - 1;
        resultAggregatedDouble /= resultList.size();

        BigDecimal aggregatedResult = new BigDecimal(resultAggregatedDouble, mc);
        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.microflexbigdecimal.stat.PopulationVarianceWeightsTest.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() {

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

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

    Map<WellSet, BigDecimal> aggregatedReturnedMap = variance.setsAggregated(collection, weights, mc);
    Map<WellSet, BigDecimal> aggregatedResultMap = new TreeMap<WellSet, BigDecimal>();

    for (WellSet set : collection) {

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

        for (Well well : set) {

            List<BigDecimal> input = well.data();

            for (int i = 0; i < input.size(); i++) {
                resultList.add(input.get(i).multiply(new BigDecimal(weights[i])));
            }

        }

        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();
        resultAggregatedDouble *= resultList.size() - 1;
        resultAggregatedDouble /= resultList.size();

        BigDecimal aggregatedResult = new BigDecimal(resultAggregatedDouble, mc);
        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.microflexbiginteger.stat.PopulationVarianceWeightsTest.java

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

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

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

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

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

    for (WellSet set : collection) {

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

        for (Well well : set) {

            List<BigDecimal> input = well.toBigDecimal().subList(begin, end);

            for (int i = 0; i < input.size(); i++) {
                resultList.add(input.get(i).multiply(new BigDecimal(weightsIndices[i])));
            }

        }

        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();
        resultAggregatedDouble *= resultList.size() - 1;
        resultAggregatedDouble /= resultList.size();

        BigDecimal aggregatedResult = new BigDecimal(resultAggregatedDouble, mc);
        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.PopulationVarianceBigDecimalWeightsTest.java

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

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

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

    Map<WellSetBigDecimal, BigDecimal> aggregatedReturnedMap = variance.setsAggregated(setArray, weights, mc);
    Map<WellSetBigDecimal, BigDecimal> aggregatedResultMap = new TreeMap<WellSetBigDecimal, BigDecimal>();

    for (WellSetBigDecimal set : setArray) {

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

        for (WellBigDecimal well : set) {

            List<BigDecimal> input = well.data();

            for (int i = 0; i < input.size(); i++) {
                resultList.add(input.get(i).multiply(new BigDecimal(weights[i])));
            }

        }

        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();
        resultAggregatedDouble *= resultList.size() - 1;
        resultAggregatedDouble /= resultList.size();

        BigDecimal aggregatedResult = new BigDecimal(resultAggregatedDouble, mc);
        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.PopulationVarianceBigIntegerWeightsTest.java

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

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

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

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

    Map<WellSetBigInteger, BigDecimal> aggregatedReturnedMap = variance.setsAggregated(setArrayIndices,
            weightsIndices, begin, end - begin, mc);
    Map<WellSetBigInteger, BigDecimal> aggregatedResultMap = new TreeMap<WellSetBigInteger, BigDecimal>();

    for (WellSetBigInteger set : setArrayIndices) {

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

        for (WellBigInteger well : set) {

            List<BigDecimal> input = well.toBigDecimal().subList(begin, end);

            for (int i = 0; i < input.size(); i++) {
                resultList.add(input.get(i).multiply(new BigDecimal(weightsIndices[i])));
            }

        }

        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();
        resultAggregatedDouble *= resultList.size() - 1;
        resultAggregatedDouble /= resultList.size();

        BigDecimal aggregatedResult = new BigDecimal(resultAggregatedDouble, mc);

        aggregatedResultMap.put(set, aggregatedResult);
    }

    for (WellSetBigInteger plate : setArrayIndices) {

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

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