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.aptd.simulation.core.statistic.local.CStatistic.java

/**
 * write data/*from www  .  j a v a 2 s  .c o  m*/
 *
 * @param p_writer writer instance
 * @param p_name section name
 * @param p_statistic statistic value
 */
private static void apply(final IWriter p_writer, final String p_name,
        final DescriptiveStatistics p_statistic) {
    p_writer.section(1, p_name);

    p_writer.value("geometricmean", p_statistic.getGeometricMean());
    p_writer.value("kurtosis", p_statistic.getKurtosis());
    p_writer.value("max", p_statistic.getMax());
    p_writer.value("min", p_statistic.getMin());
    p_writer.value("mean", p_statistic.getMean());
    p_writer.value("count", p_statistic.getN());
    p_writer.value("25-percentile", p_statistic.getPercentile(0.25));
    p_writer.value("75-percentile", p_statistic.getPercentile(0.75));
    p_writer.value("populationvariance", p_statistic.getPopulationVariance());
    p_writer.value("quadraticmean", p_statistic.getQuadraticMean());
    p_writer.value("standdeviation", p_statistic.getStandardDeviation());
    p_writer.value("skewness", p_statistic.getSkewness());
    p_writer.value("sum", p_statistic.getSum());
    p_writer.value("sumsequared", p_statistic.getSumsq());
    p_writer.value("variance", p_statistic.getVariance());
}

From source file:com.joptimizer.algebra.CholeskyDecompositionTest.java

/**
 * poor decomposition.//  ww w.ja  v a 2 s  .  c  o m
 * rescaling can help in doing it better
 */
public void testDecomposition2() throws Exception {
    log.debug("testDecomposition2");
    RealMatrix P1 = new Array2DRowRealMatrix(new double[][] { { 8.185301256666552E9, 1.5977225251367908E9 },
            { 1.5977225251367908E9, 3.118660129093004E8 } });
    CholeskyDecomposition cFact1 = new CholeskyDecomposition(P1);
    log.debug("L: " + cFact1.getL());
    log.debug("LT: " + cFact1.getLT());
    // check L.LT-Q=0
    double norm1 = cFact1.getL().multiply(cFact1.getLT()).subtract(P1).getNorm();
    log.debug("norm1: " + norm1);
    assertTrue(norm1 < 1.E-5);

    //poor precision, try to make it better

    //geometric eigenvalues mean
    DescriptiveStatistics ds = new DescriptiveStatistics(new double[] { 8.5E9, 0.00572 });
    RealMatrix P2 = P1.scalarMultiply(1. / ds.getGeometricMean());
    CholeskyDecomposition cFact2 = new CholeskyDecomposition(P2);
    log.debug("L: " + cFact2.getL());
    log.debug("LT: " + cFact2.getLT());
    // check L.LT-Q=0
    double norm2 = cFact2.getL().multiply(cFact2.getLT()).subtract(P2).getNorm();
    log.debug("norm2: " + norm2);
    assertTrue(norm2 < Utils.getDoubleMachineEpsilon());
}

From source file:com.joptimizer.solvers.CholeskyTest.java

/**
 * poor decomposition./*from ww w  . j  a va2s . c  om*/
 * rescaling can help in doing it better
 */
public void testDecomposition2() throws Exception {
    log.debug("testDecomposition2");
    RealMatrix P1 = new Array2DRowRealMatrix(new double[][] { { 8.185301256666552E9, 1.5977225251367908E9 },
            { 1.5977225251367908E9, 3.118660129093004E8 } });
    CholeskyDecomposition cFact1 = new CholeskyDecomposition(P1);
    log.debug("L: " + cFact1.getL());
    log.debug("LT: " + cFact1.getLT());
    // check L.LT-Q=0
    double norm1 = cFact1.getL().multiply(cFact1.getLT()).subtract(P1).getNorm();
    log.debug("norm1: " + norm1);
    assertTrue(norm1 < 1.E-5);

    //poor precision, try to make it better

    //geometric eigenvalues mean
    DescriptiveStatistics ds = new DescriptiveStatistics(new double[] { 8.5E9, 0.00572 });
    RealMatrix P2 = P1.scalarMultiply(1. / ds.getGeometricMean());
    CholeskyDecomposition cFact2 = new CholeskyDecomposition(P2);
    log.debug("L: " + cFact2.getL());
    log.debug("LT: " + cFact2.getLT());
    // check L.LT-Q=0
    double norm2 = cFact2.getL().multiply(cFact2.getLT()).subtract(P2).getNorm();
    log.debug("norm2: " + norm2);
    assertTrue(norm2 < 1.E-9);
}

From source file:com.insightml.models.meta.VoteModel.java

private double resolve(final DescriptiveStatistics stats) {
    switch (strategy) {
    case AVERAGE:
        return stats.getMean();
    case MEDIAN:/*from   w w  w  .j  a va 2  s.  co  m*/
        return stats.getPercentile(50);
    case GEOMETRIC:
        return stats.getGeometricMean();
    case HARMONIC:
        double sum = 0;
        for (final double value : stats.getValues()) {
            sum += 1 / value;
        }
        return stats.getN() * 1.0 / sum;
    default:
        throw new IllegalStateException();
    }
}

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

/**
 * Tests the plate statistics method./*from   w  w w  . j a  v  a  2s  . co  m*/
 */
@Test
public void testPlate() {

    for (Plate plate : array) {

        Map<Well, Double> resultMap = new TreeMap<Well, Double>();
        Map<Well, Double> returnedMap = mean.plate(plate);

        for (Well well : plate) {

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

            for (double bd : well) {
                input[index++] = bd;
                ;
            }

            DescriptiveStatistics stat = new DescriptiveStatistics(input);
            double result = stat.getGeometricMean();

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

/**
 * Tests the plate statistics method./* w  ww .  ja va 2s .  c  om*/
 */
@Test
public void testPlate() {

    for (PlateDouble plate : array) {

        Map<WellDouble, Double> resultMap = new TreeMap<WellDouble, Double>();
        Map<WellDouble, Double> returnedMap = mean.plate(plate);

        for (WellDouble well : plate) {

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

            for (double bd : well) {
                input[index++] = bd;
                ;
            }

            DescriptiveStatistics stat = new DescriptiveStatistics(input);
            double result = stat.getGeometricMean();

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

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

    for (PlateInteger plate : array) {

        Map<WellInteger, Double> resultMap = new TreeMap<WellInteger, Double>();
        Map<WellInteger, Double> returnedMap = mean.plate(plate);

        for (WellInteger well : plate) {

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

            for (double bd : well) {
                input[index++] = bd;
                ;
            }

            DescriptiveStatistics stat = new DescriptiveStatistics(input);
            double result = stat.getGeometricMean();

            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.microflexdouble.stat.GeometricMeanTest.java

/**
 * Tests set calculation.//from   w w  w.  j a  v  a 2s.  c  o  m
 */
@Test
public void testSet() {

    for (Plate plate : array) {

        Map<Well, Double> resultMap = new TreeMap<Well, Double>();
        Map<Well, Double> returnedMap = mean.set(plate.dataSet());

        for (Well well : plate) {

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

            for (double bd : well) {
                input[index++] = bd;
                ;
            }

            DescriptiveStatistics stat = new DescriptiveStatistics(input);
            double result = stat.getGeometricMean();

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

/**
 * Tests set calculation./* w  w  w . j  a va 2s  .  c om*/
 */
@Test
public void testSet() {

    for (PlateDouble plate : array) {

        Map<WellDouble, Double> resultMap = new TreeMap<WellDouble, Double>();
        Map<WellDouble, Double> returnedMap = mean.set(plate.dataSet());

        for (WellDouble well : plate) {

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

            for (double bd : well) {
                input[index++] = bd;
                ;
            }

            DescriptiveStatistics stat = new DescriptiveStatistics(input);
            double result = stat.getGeometricMean();

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

/**
 * Tests set calculation./*from   w w  w  .j  a v  a  2  s .c  o m*/
 */
@Test
public void testSet() {

    for (PlateInteger plate : array) {

        Map<WellInteger, Double> resultMap = new TreeMap<WellInteger, Double>();
        Map<WellInteger, Double> returnedMap = mean.set(plate.dataSet());

        for (WellInteger well : plate) {

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

            for (double bd : well) {
                input[index++] = bd;
                ;
            }

            DescriptiveStatistics stat = new DescriptiveStatistics(input);
            double result = stat.getGeometricMean();

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

}