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

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

Introduction

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

Prototype

public double getGeometricMean() 

Source Link

Document

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

Usage

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

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

    for (PlateBigDecimal plate : arrayIndices) {

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

        Map<WellBigDecimal, BigDecimal> resultMap = new TreeMap<WellBigDecimal, BigDecimal>();
        Map<WellBigDecimal, BigDecimal> returnedMap = mean.set(plate.dataSet(), 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();
            }

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

            BigDecimal result = new BigDecimal(resultDouble);

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

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

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

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

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

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

    for (WellSetBigDecimal set : collection) {

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

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

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

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

    for (PlateBigInteger plate : arrayIndices) {

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

        Map<WellBigInteger, BigDecimal> resultMap = new TreeMap<WellBigInteger, BigDecimal>();
        Map<WellBigInteger, BigDecimal> returnedMap = mean.plate(plate, 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();
            }

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

            BigDecimal result = new BigDecimal(resultDouble);

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

/**
 * Tests set calculation using indices./*from  w w w.  jav a2  s.  c  om*/
 */
@Test
public void testSetIndices() {

    for (PlateBigInteger plate : arrayIndices) {

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

        Map<WellBigInteger, BigDecimal> resultMap = new TreeMap<WellBigInteger, BigDecimal>();
        Map<WellBigInteger, BigDecimal> returnedMap = mean.set(plate.dataSet(), 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();
            }

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

            BigDecimal result = new BigDecimal(resultDouble);

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

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

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

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

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

    Map<WellSetBigInteger, BigDecimal> aggregatedReturnedMap = mean.setsAggregated(collection, 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) {
            resultList.addAll(well.toBigDecimal().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.getGeometricMean();

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

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

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

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

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

    WellSetBigDecimal[] array = collection.toArray(new WellSetBigDecimal[collection.size()]);

    Map<WellSetBigDecimal, BigDecimal> aggregatedReturnedMap = mean.setsAggregated(array, begin, end - begin,
            mc);
    Map<WellSetBigDecimal, BigDecimal> aggregatedResultMap = new TreeMap<WellSetBigDecimal, BigDecimal>();

    for (WellSetBigDecimal set : array) {

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

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

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

    for (WellSetBigDecimal set : array) {

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

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

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

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

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

    WellSetBigInteger[] array = collection.toArray(new WellSetBigInteger[collection.size()]);

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

    for (WellSetBigInteger set : array) {

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

        for (WellBigInteger well : set) {
            resultList.addAll(well.toBigDecimal().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.getGeometricMean();

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

    for (WellSetBigInteger set : array) {

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

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

From source file:com.loadtesting.core.data.TimeSerieData.java

public TimeSerieData(String name, List<TimeSample> samples, CapturerConfig config) {
    this.name = name;
    this.unit = config.getUnit();
    this.volume = samples.size();
    if (volume > 0) {
        TimeSample first = samples.get(0);
        this.unit = first.getTimeUnit();
        this.opening = first.getTime(unit);
        TimeSample last = samples.get(volume - 1);
        this.closing = last.getTime(unit);
        this.samples = config.getFilter().filter(samples);

        DescriptiveStatistics stats = new DescriptiveStatistics(volume);
        for (TimeSample timeSample : samples) {
            stats.addValue(timeSample.getTime(unit));
        }/*from   www . ja v  a2  s.  c o  m*/
        this.high = stats.getMax();
        this.low = stats.getMin();
        this.median = (high + low) / 2;
        this.typical = (high + low + closing) / 3;
        this.weightedClose = (high + low + closing + closing) / 4;
        this.sma = stats.getMean();
        this.variance = stats.getVariance();
        this.sd = stats.getStandardDeviation();
        this.sum = stats.getSum();
        this.sumsq = stats.getSumsq();
        this.skewness = stats.getSkewness();
        this.kurtosis = stats.getKurtosis();
        this.geometricMean = stats.getGeometricMean();
        this.populationVariance = stats.getPopulationVariance();
    } else {
        this.samples = samples;
    }
}

From source file:com.facebook.presto.tests.AbstractTestQueries.java

@Test
public void testTableSamplePoissonized() throws Exception {
    DescriptiveStatistics stats = new DescriptiveStatistics();

    long total = (long) computeExpected("SELECT COUNT(*) FROM orders", ImmutableList.of(BIGINT))
            .getMaterializedRows().get(0).getField(0);

    for (int i = 0; i < 100; i++) {
        String value = (String) computeActual(
                "SELECT COUNT(*) FROM orders TABLESAMPLE POISSONIZED (50) APPROXIMATE AT 95 CONFIDENCE")
                        .getMaterializedRows().get(0).getField(0);
        stats.addValue(Long.parseLong(value.split(" ")[0]) * 1.0 / total);
    }/* w  w w.  j  a  v  a 2  s .c  o  m*/

    double mean = stats.getGeometricMean();
    assertTrue(mean > 0.45 && mean < 0.55, format("Expected mean sampling rate to be ~0.5, but was %s", mean));
}

From source file:com.facebook.presto.tests.AbstractTestQueries.java

@Test
public void testTableSampleBernoulli() throws Exception {
    DescriptiveStatistics stats = new DescriptiveStatistics();

    int total = computeExpected("SELECT orderkey FROM orders", ImmutableList.of(BIGINT)).getMaterializedRows()
            .size();//from   www. j  a v  a 2s .  co  m

    for (int i = 0; i < 100; i++) {
        List<MaterializedRow> values = computeActual("SELECT orderkey FROM ORDERS TABLESAMPLE BERNOULLI (50)")
                .getMaterializedRows();

        assertEquals(values.size(), ImmutableSet.copyOf(values).size(), "TABLESAMPLE produced duplicate rows");
        stats.addValue(values.size() * 1.0 / total);
    }

    double mean = stats.getGeometricMean();
    assertTrue(mean > 0.45 && mean < 0.55, format("Expected mean sampling rate to be ~0.5, but was %s", mean));
}