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

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

Introduction

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

Prototype

public double getPopulationVariance() 

Source Link

Document

Returns the <a href="http://en.wikibooks.org/wiki/Statistics/Summary/Variance"> population variance</a> of the available values.

Usage

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

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

    for (Plate plate : arrayIndices) {

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

        List<BigDecimal> resultList = new ArrayList<BigDecimal>();
        double aggregatedReturned = Precision
                .round(variance.platesAggregated(plate, weightsIndices, begin, end - begin), precision);

        for (Well well : plate) {

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

        assertTrue(resultAggregated == aggregatedReturned);
    }
}

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

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

    for (Plate plate : arrayIndices) {

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

        List<BigDecimal> resultList = new ArrayList<BigDecimal>();
        double aggregatedReturned = Precision
                .round(variance.setsAggregated(plate.dataSet(), weightsIndices, begin, end - begin), precision);

        for (Well well : plate) {

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

        assertTrue(resultAggregated == aggregatedReturned);
    }
}

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

/**
 * Tests the aggregated plate statistics method using the values between the indices of
 * the collection./*from   w  w w. j av 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, Double> aggregatedReturnedMap = variance.setsAggregated(collection, weightsIndices, begin,
            end - begin);
    Map<WellSet, Double> aggregatedResultMap = new TreeMap<WellSet, Double>();

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

        aggregatedResultMap.put(set, aggregatedResult);
    }

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

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

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

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

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

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

    for (WellSet set : setArrayIndices) {

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

        aggregatedResultMap.put(set, aggregatedResult);
    }

    for (WellSet plate : setArrayIndices) {

        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.statdouble.PopulationVarianceDoubleWeightsTest.java

/**
 * Tests the aggregated plate statistics method using the values between the indices.
 *///from www. ja v  a 2  s.  c o  m
@Test
public void testAggregatedPlateIndices() {

    for (PlateDouble plate : arrayIndices) {

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

        List<BigDecimal> resultList = new ArrayList<BigDecimal>();
        double aggregatedReturned = Precision
                .round(variance.platesAggregated(plate, weightsIndices, begin, end - begin), precision);

        for (WellDouble well : plate) {

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

        assertTrue(resultAggregated == aggregatedReturned);
    }
}

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

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

    for (PlateDouble plate : arrayIndices) {

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

        List<BigDecimal> resultList = new ArrayList<BigDecimal>();
        double aggregatedReturned = Precision
                .round(variance.setsAggregated(plate.dataSet(), weightsIndices, begin, end - begin), precision);

        for (WellDouble well : plate) {

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

        assertTrue(resultAggregated == aggregatedReturned);
    }
}

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

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

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

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

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

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

    for (WellSetDouble set : collection) {

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

        for (WellDouble 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 aggregatedResult = statAggregated.getPopulationVariance();

        aggregatedResultMap.put(set, aggregatedResult);
    }

    for (WellSetDouble 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.microflex.stat.statdouble.PopulationVarianceDoubleWeightsTest.java

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

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

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

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

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

    for (WellSetDouble set : setArrayIndices) {

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

        for (WellDouble 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 aggregatedResult = statAggregated.getPopulationVariance();

        aggregatedResultMap.put(set, aggregatedResult);
    }

    for (WellSetDouble plate : setArrayIndices) {

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

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

    for (PlateInteger plate : arrayIndices) {

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

        List<BigDecimal> resultList = new ArrayList<BigDecimal>();
        double aggregatedReturned = Precision
                .round(variance.platesAggregated(plate, weightsIndices, begin, end - begin), precision);

        for (WellInteger well : plate) {

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

        assertTrue(resultAggregated == aggregatedReturned);
    }
}

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

/**
 * Tests the aggregated plate statistics method using the values between the indices.
 */// w w  w. j  a va2s .  c  om
@Test
public void testAggregatedSetIndices() {

    for (PlateInteger plate : arrayIndices) {

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

        List<BigDecimal> resultList = new ArrayList<BigDecimal>();
        double aggregatedReturned = Precision
                .round(variance.setsAggregated(plate.dataSet(), weightsIndices, begin, end - begin), precision);

        for (WellInteger well : plate) {

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

        assertTrue(resultAggregated == aggregatedReturned);
    }
}