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

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

Introduction

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

Prototype

public double getMean() 

Source Link

Document

Returns the <a href="http://www.xycoon.com/arithmetic_mean.htm"> arithmetic mean </a> of the available values

Usage

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

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

    List<PlateDouble> collection = Arrays.asList(array);
    Map<PlateDouble, Double> aggregatedReturnedMap = mean.platesAggregated(collection, weights);
    Map<PlateDouble, Double> aggregatedResultMap = new TreeMap<PlateDouble, Double>();

    for (PlateDouble plate : collection) {

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

        for (WellDouble well : plate) {

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

        aggregatedResultMap.put(plate, aggregatedResult);
    }

    for (PlateDouble plate : collection) {

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

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

    Map<PlateDouble, Double> aggregatedReturnedMap = mean.platesAggregated(array, weights);
    Map<PlateDouble, Double> aggregatedResultMap = new TreeMap<PlateDouble, Double>();

    for (PlateDouble plate : array) {

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

        for (WellDouble well : plate) {

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

        aggregatedResultMap.put(plate, aggregatedResult);
    }

    for (PlateDouble plate : array) {

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

/**
 * Tests the aggregated plate statistics method using a collection.
 *///from w  ww .j av  a2s  .co m
@Test
public void testAggregatedPlateCollection() {

    List<PlateInteger> collection = Arrays.asList(array);
    Map<PlateInteger, Double> aggregatedReturnedMap = mean.platesAggregated(collection, weights);
    Map<PlateInteger, Double> aggregatedResultMap = new TreeMap<PlateInteger, Double>();

    for (PlateInteger plate : collection) {

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

        for (WellInteger well : plate) {

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

        aggregatedResultMap.put(plate, aggregatedResult);
    }

    for (PlateInteger plate : collection) {

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

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

    Map<PlateInteger, Double> aggregatedReturnedMap = mean.platesAggregated(array, weights);
    Map<PlateInteger, Double> aggregatedResultMap = new TreeMap<PlateInteger, Double>();

    for (PlateInteger plate : array) {

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

        for (WellInteger well : plate) {

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

        aggregatedResultMap.put(plate, aggregatedResult);
    }

    for (PlateInteger plate : array) {

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

/**
 * Tests the plate statistics method using the values between the indices.
 *//*from  ww w.j a v a  2s. 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, Double> resultMap = new TreeMap<Well, Double>();
        Map<Well, Double> returnedMap = mean.plate(plate, ArrayUtils.subarray(weightsIndices, begin, end),
                begin, end - begin);

        for (Well well : plate) {

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

            for (double db : well) {
                input[index] = db * weightsIndices[index];
                index++;
            }

            DescriptiveStatistics stat = new DescriptiveStatistics(ArrayUtils.subarray(input, begin, end));
            double result = stat.getMean();

            resultMap.put(well, result);
        }

        for (Well well : plate) {

            double result = Precision.round(resultMap.get(well), precision);
            double returned = Precision.round(returnedMap.get(well), precision);

            assertTrue(result == returned);
        }
    }
}

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

/**
 * Tests set calculation using indices.//  w  ww  . j a v  a  2s  . c om
 */
@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, Double> resultMap = new TreeMap<Well, Double>();
        Map<Well, Double> returnedMap = mean.set(plate.dataSet(),
                ArrayUtils.subarray(weightsIndices, begin, end), begin, end - begin);

        for (Well well : plate) {

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

            for (double db : well) {
                input[index] = db * weightsIndices[index];
                index++;
            }

            DescriptiveStatistics stat = new DescriptiveStatistics(ArrayUtils.subarray(input, begin, end));
            double result = stat.getMean();

            resultMap.put(well, result);
        }

        for (Well well : plate) {

            double result = Precision.round(resultMap.get(well), precision);
            double returned = Precision.round(returnedMap.get(well), precision);

            assertTrue(result == returned);
        }
    }
}

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

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

    for (PlateDouble plate : arrayIndices) {

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

        Map<WellDouble, Double> resultMap = new TreeMap<WellDouble, Double>();
        Map<WellDouble, Double> returnedMap = mean.plate(plate, ArrayUtils.subarray(weightsIndices, begin, end),
                begin, end - begin);

        for (WellDouble well : plate) {

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

            for (double db : well) {
                input[index] = db * weightsIndices[index];
                index++;
            }

            DescriptiveStatistics stat = new DescriptiveStatistics(ArrayUtils.subarray(input, begin, end));
            double result = stat.getMean();

            resultMap.put(well, result);
        }

        for (WellDouble well : plate) {

            double result = Precision.round(resultMap.get(well), precision);
            double returned = Precision.round(returnedMap.get(well), precision);

            assertTrue(result == returned);
        }
    }
}

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

/**
 * Tests set calculation using indices.//from ww w  .  jav a  2s.  co  m
 */
@Test
public void testSetIndices() {

    for (PlateDouble plate : arrayIndices) {

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

        Map<WellDouble, Double> resultMap = new TreeMap<WellDouble, Double>();
        Map<WellDouble, Double> returnedMap = mean.set(plate.dataSet(),
                ArrayUtils.subarray(weightsIndices, begin, end), begin, end - begin);

        for (WellDouble well : plate) {

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

            for (double db : well) {
                input[index] = db * weightsIndices[index];
                index++;
            }

            DescriptiveStatistics stat = new DescriptiveStatistics(ArrayUtils.subarray(input, begin, end));
            double result = stat.getMean();

            resultMap.put(well, result);
        }

        for (WellDouble well : plate) {

            double result = Precision.round(resultMap.get(well), precision);
            double returned = Precision.round(returnedMap.get(well), precision);

            assertTrue(result == returned);
        }
    }
}

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

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

    for (PlateInteger plate : arrayIndices) {

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

        Map<WellInteger, Double> resultMap = new TreeMap<WellInteger, Double>();
        Map<WellInteger, Double> returnedMap = mean.plate(plate,
                ArrayUtils.subarray(weightsIndices, begin, end), begin, end - begin);

        for (WellInteger well : plate) {

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

            for (double db : well) {
                input[index] = db * weightsIndices[index];
                index++;
            }

            DescriptiveStatistics stat = new DescriptiveStatistics(ArrayUtils.subarray(input, begin, end));
            double result = stat.getMean();

            resultMap.put(well, result);
        }

        for (WellInteger well : plate) {

            double result = Precision.round(resultMap.get(well), precision);
            double returned = Precision.round(returnedMap.get(well), precision);

            assertTrue(result == returned);
        }
    }
}

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

/**
 * Tests set calculation using indices./*from  ww  w . ja  va  2s .co m*/
 */
@Test
public void testSetIndices() {

    for (PlateInteger plate : arrayIndices) {

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

        Map<WellInteger, Double> resultMap = new TreeMap<WellInteger, Double>();
        Map<WellInteger, Double> returnedMap = mean.set(plate.dataSet(),
                ArrayUtils.subarray(weightsIndices, begin, end), begin, end - begin);

        for (WellInteger well : plate) {

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

            for (double db : well) {
                input[index] = db * weightsIndices[index];
                index++;
            }

            DescriptiveStatistics stat = new DescriptiveStatistics(ArrayUtils.subarray(input, begin, end));
            double result = stat.getMean();

            resultMap.put(well, result);
        }

        for (WellInteger well : plate) {

            double result = Precision.round(resultMap.get(well), precision);
            double returned = Precision.round(returnedMap.get(well), precision);

            assertTrue(result == returned);
        }
    }
}