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

/**
 * Tests well calculation using indices.
 *//*from   w  w  w.  j a  v  a  2 s .  c om*/
@Test
public void testWellIndices() {

    for (Plate plate : arrayIndices) {

        for (Well well : plate) {

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

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

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

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

            BigDecimal returned = variance.well(well, ArrayUtils.subarray(weightsIndices, begin, end), begin,
                    end - begin, mc);
            BigDecimal result = new BigDecimal(resultDouble, mc);

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

From source file:com.github.jessemull.microflex.stat.statbigdecimal.PopulationVarianceBigDecimalWeightsTest.java

/**
 * Tests well calculation using indices.
 *///  ww  w.j  a va  2s.c om
@Test
public void testWellIndices() {

    for (PlateBigDecimal plate : arrayIndices) {

        for (WellBigDecimal well : plate) {

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

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

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

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

            BigDecimal returned = variance.well(well, ArrayUtils.subarray(weightsIndices, begin, end), begin,
                    end - begin, mc);
            BigDecimal result = new BigDecimal(resultDouble, mc);

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

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

/**
 * Tests well calculation using indices.
 *///from w  ww  . ja  v  a2 s . c  o  m
@Test
public void testWellIndices() {

    for (Plate plate : arrayIndices) {

        for (Well well : plate) {

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

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

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

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

            BigDecimal returned = variance.well(well, ArrayUtils.subarray(weightsIndices, begin, end), begin,
                    end - begin, mc);
            BigDecimal result = new BigDecimal(resultDouble, mc);

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

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

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

    for (PlateBigInteger plate : arrayIndices) {

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

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

        for (WellBigInteger well : plate) {

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

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

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

            BigDecimal result = new BigDecimal(resultDouble, mc);

            resultMap.put(well, result);
        }

        for (WellBigInteger 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.statbiginteger.PopulationVarianceBigIntegerWeightsTest.java

/**
 * Tests set calculation using indices./*from ww w  .  ja v  a  2  s . c o m*/
 */
@Test
public void testSetIndices() {

    for (PlateBigInteger plate : arrayIndices) {

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

        Map<WellBigInteger, BigDecimal> resultMap = new TreeMap<WellBigInteger, BigDecimal>();
        Map<WellBigInteger, BigDecimal> returnedMap = variance.set(plate.dataSet(),
                ArrayUtils.subarray(weightsIndices, begin, end), begin, end - begin, mc);

        for (WellBigInteger well : plate) {

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

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

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

            BigDecimal result = new BigDecimal(resultDouble, mc);

            resultMap.put(well, result);
        }

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

/**
 * Tests the plate statistics method using the values between the indices.
 *//*  w  w  w .  j ava2  s  .  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 = variance.plate(plate,
                ArrayUtils.subarray(weightsIndices, begin, end), 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() * weightsIndices[index];
                index++;
            }

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

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

/**
 * Tests set calculation using indices./*  w  w  w  .  j a va 2  s. c  o m*/
 */
@Test
public void testSetIndices() {

    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 = variance.set(plate.dataSet(),
                ArrayUtils.subarray(weightsIndices, begin, end), 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() * weightsIndices[index];
                index++;
            }

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

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

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

    for (PlateBigDecimal plate : arrayIndices) {

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

        Map<WellBigDecimal, BigDecimal> resultMap = new TreeMap<WellBigDecimal, BigDecimal>();
        Map<WellBigDecimal, BigDecimal> returnedMap = variance.plate(plate,
                ArrayUtils.subarray(weightsIndices, begin, end), 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() * weightsIndices[index];
                index++;
            }

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

            BigDecimal result = new BigDecimal(resultDouble, mc);

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

/**
 * Tests set calculation using indices.// www  .  j  a  va  2  s . co m
 */
@Test
public void testSetIndices() {

    for (PlateBigDecimal plate : arrayIndices) {

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

        Map<WellBigDecimal, BigDecimal> resultMap = new TreeMap<WellBigDecimal, BigDecimal>();
        Map<WellBigDecimal, BigDecimal> returnedMap = variance.set(plate.dataSet(),
                ArrayUtils.subarray(weightsIndices, begin, end), 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() * weightsIndices[index];
                index++;
            }

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

            BigDecimal result = new BigDecimal(resultDouble, mc);

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

/**
 * Tests the plate statistics method using the values between the indices.
 *//*from  w ww.ja va2s  . 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 = variance.plate(plate,
                ArrayUtils.subarray(weightsIndices, begin, end), 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() * weightsIndices[index];
                index++;
            }

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

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