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

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

Introduction

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

Prototype

public double getSumsq() 

Source Link

Document

Returns the sum of the squares of the available values.

Usage

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

/**
 * Tests the aggregated plate statistics method using the values between the indices.
 *//*w  w w .j  av  a 2s  .co m*/
@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(sum.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.getSumsq(), precision);

        assertTrue(resultAggregated == aggregatedReturned);
    }
}

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

/**
 * Tests the aggregated plate statistics method using the values between the indices of
 * the collection./*from   w w  w  . jav a2 s  .  co  m*/
 */
@Test
public void testAggregatedSetCollectionIndices() {

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

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

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

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

    for (WellSetInteger set : collection) {

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

        for (WellInteger 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.getSumsq();

        aggregatedResultMap.put(set, aggregatedResult);
    }

    for (WellSetInteger 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.statinteger.SumOfSquaresIntegerWeightsTest.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;

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

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

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

    for (WellSetInteger set : setArrayIndices) {

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

        for (WellInteger 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.getSumsq();

        aggregatedResultMap.put(set, aggregatedResult);
    }

    for (WellSetInteger 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.microflexdouble.stat.SumOfSquaresWeightsTest.java

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

    for (Plate plate : arrayIndices) {

        for (Well well : plate) {

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

            for (double db : well) {
                input[index] = db * 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 result = Precision.round(stat.getSumsq(), precision);
            double returned = Precision.round(
                    sum.well(well, ArrayUtils.subarray(weightsIndices, begin, end), begin, end - begin),
                    precision);

            assertTrue(result == returned);
        }
    }
}

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

/**
 * Tests well calculation using indices.
 *///www  . java  2  s  . co m
@Test
public void testWellIndices() {

    for (PlateDouble plate : arrayIndices) {

        for (WellDouble well : plate) {

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

            for (double db : well) {
                input[index] = db * 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 result = Precision.round(stat.getSumsq(), precision);
            double returned = Precision.round(
                    sum.well(well, ArrayUtils.subarray(weightsIndices, begin, end), begin, end - begin),
                    precision);

            assertTrue(result == returned);
        }
    }
}

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

/**
 * Tests well calculation using indices.
 *///  www . j av  a 2 s . c  o  m
@Test
public void testWellIndices() {

    for (PlateInteger plate : arrayIndices) {

        for (WellInteger well : plate) {

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

            for (double db : well) {
                input[index] = db * 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 result = Precision.round(stat.getSumsq(), precision);
            double returned = Precision.round(
                    sum.well(well, ArrayUtils.subarray(weightsIndices, begin, end), begin, end - begin),
                    precision);

            assertTrue(result == returned);
        }
    }
}

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

/**
 * Tests the aggregated plate statistics method.
 *//* ww  w.  j  av a2s .  co  m*/
@Test
public void testAggregatedPlate() {

    for (PlateBigDecimal plate : array) {

        List<BigDecimal> resultList = new ArrayList<BigDecimal>();
        BigDecimal aggregatedReturned = sum.platesAggregated(plate, mc);

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

        BigDecimal aggregatedResult = new BigDecimal(resultAggregatedDouble);

        BigDecimal[] corrected = correctRoundingErrors(aggregatedResult, aggregatedReturned);
        assertEquals(corrected[0], corrected[1]);
    }
}

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

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

    for (PlateBigDecimal plate : array) {

        List<BigDecimal> resultList = new ArrayList<BigDecimal>();
        BigDecimal aggregatedReturned = sum.setsAggregated(plate.dataSet(), mc);

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

        BigDecimal aggregatedResult = new BigDecimal(resultAggregatedDouble);

        BigDecimal[] corrected = correctRoundingErrors(aggregatedResult, aggregatedReturned);
        assertEquals(corrected[0], corrected[1]);
    }
}

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

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

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

        List<BigDecimal> resultList = new ArrayList<BigDecimal>();
        BigDecimal aggregatedReturned = sum.platesAggregated(plate, begin, end - begin, mc);

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

        BigDecimal aggregatedResult = new BigDecimal(resultAggregatedDouble);

        BigDecimal[] corrected = correctRoundingErrors(aggregatedResult, aggregatedReturned);
        assertEquals(corrected[0], corrected[1]);
    }
}

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

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

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

        List<BigDecimal> resultList = new ArrayList<BigDecimal>();
        BigDecimal aggregatedReturned = sum.setsAggregated(plate.dataSet(), begin, end - begin, mc);

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

        BigDecimal aggregatedResult = new BigDecimal(resultAggregatedDouble);

        BigDecimal[] corrected = correctRoundingErrors(aggregatedResult, aggregatedReturned);
        assertEquals(corrected[0], corrected[1]);
    }
}