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.intuit.tank.persistence.databases.BucketDataItemTest.java

/**
 * Run the DescriptiveStatistics getStats() method test.
 * // w  w w . ja  v a  2  s  .co  m
 * @throws Exception
 * 
 * @generatedBy CodePro at 9/10/14 10:32 AM
 */
@Test
public void testGetStats_1() throws Exception {
    BucketDataItem fixture = new BucketDataItem(1, new Date(), new DescriptiveStatistics());

    DescriptiveStatistics result = fixture.getStats();

    assertNotNull(result);
    assertEquals(
            "DescriptiveStatistics:\nn: 0\nmin: NaN\nmax: NaN\nmean: NaN\nstd dev: NaN\nmedian: NaN\nskewness: NaN\nkurtosis: NaN\n",
            result.toString());
    assertEquals(Double.NaN, result.getMax(), 1.0);
    assertEquals(Double.NaN, result.getVariance(), 1.0);
    assertEquals(Double.NaN, result.getMean(), 1.0);
    assertEquals(-1, result.getWindowSize());
    assertEquals(0.0, result.getSumsq(), 1.0);
    assertEquals(Double.NaN, result.getKurtosis(), 1.0);
    assertEquals(0.0, result.getSum(), 1.0);
    assertEquals(Double.NaN, result.getSkewness(), 1.0);
    assertEquals(Double.NaN, result.getPopulationVariance(), 1.0);
    assertEquals(Double.NaN, result.getStandardDeviation(), 1.0);
    assertEquals(Double.NaN, result.getGeometricMean(), 1.0);
    assertEquals(0L, result.getN());
    assertEquals(Double.NaN, result.getMin(), 1.0);
}

From source file:de.tudarmstadt.ukp.dkpro.core.performance.ThroughputTestAE.java

public String getPerformanceaAnalysis() {
    StringBuilder sb = new StringBuilder();

    long sumMillis = 0;
    for (double timeValue : times) {
        sumMillis += timeValue;//  w  ww.ja  v  a2 s.  c o m
    }

    DescriptiveStatistics statTimes = new DescriptiveStatistics();
    for (Long timeValue : times) {
        statTimes.addValue((double) timeValue / 1000);
    }

    sb.append("Estimate after processing " + times.size() + " documents.");
    sb.append(LF);

    Formatter formatter = new Formatter(sb, Locale.US);

    formatter.format("Time / Document:       %,.3f (%,.3f)\n", statTimes.getMean(),
            statTimes.getStandardDeviation());
    formatter.format("Time / 10^4 Token:     %,.3f\n", getNormalizedTime(sumMillis, nrofTokens, 1000));
    formatter.format("Time / 10^4 Sentences: %,.3f\n", getNormalizedTime(sumMillis, nrofSentences, 1000));

    formatter.close();

    return sb.toString();
}

From source file:com.facebook.stats.cardinality.TestHyperLogLog.java

@Test(groups = "slow")
public void testError() throws Exception {
    DescriptiveStatistics stats = new DescriptiveStatistics();
    int buckets = 2048;
    for (int i = 0; i < 10000; ++i) {
        HyperLogLog estimator = new HyperLogLog(buckets);
        Set<Long> randomSet = makeRandomSet(5 * buckets);
        for (Long value : randomSet) {
            estimator.add(value);/* w ww .j a  v  a 2 s. c o m*/
        }

        double error = (estimator.estimate() - randomSet.size()) * 1.0 / randomSet.size();
        stats.addValue(error);
    }

    assertTrue(stats.getMean() < 1e-2);
    assertTrue(stats.getStandardDeviation() < 1.04 / Math.sqrt(buckets));
}

From source file:info.financialecology.finance.utilities.datastruct.DoubleTimeSeries.java

public double mean() {
    DescriptiveStatistics stats = new DescriptiveStatistics();

    for (int i = 0; i < this.values.size(); i++)
        stats.addValue(this.values.get(i));

    return stats.getMean();
}

From source file:com.duy.pascal.interperter.libraries.math.MathLib.java

@PascalMethod(description = "")
public double Mean(double... arr) {
    DescriptiveStatistics descriptiveStatistics1 = new DescriptiveStatistics(arr);
    return descriptiveStatistics1.getMean();
}

From source file:main.java.repartition.SimpleTr.java

static double getDeltaLb(Cluster cluster, SimpleTr t, MigrationPlan m) {

    // Before migration
    DescriptiveStatistics current_server_data = new DescriptiveStatistics();
    for (Server s : cluster.getServers())
        if (t.serverDataSet.containsKey(s.getServer_id()))
            current_server_data.addValue(s.getServer_total_data());

    // After migration      
    DescriptiveStatistics expected_server_data = new DescriptiveStatistics();
    for (Server s : cluster.getServers()) {
        if (t.serverDataSet.containsKey(s.getServer_id())) {

            if (m.fromSet.contains(s.getServer_id())) {
                int data_count = s.getServer_total_data() - t.serverDataSet.get(s.getServer_id()).size();
                expected_server_data.addValue(data_count);

            } else if (m.to == s.getServer_id()) {
                int data_count = s.getServer_total_data() + t.serverDataSet.get(s.getServer_id()).size();
                expected_server_data.addValue(data_count);
            }//  www.  j a v  a  2 s.  com
        }
    }

    // Calculate total lb
    double variance = current_server_data.getVariance() - expected_server_data.getVariance();

    // Calculate delta lb
    double mu = current_server_data.getMean();
    double delta_lb = (double) (variance / (mu * Math.sqrt(Global.servers - 1)));

    return delta_lb;
    //return ((double) delta_lb/m.req_data_mgr);
}

From source file:com.fpuna.preproceso.PreprocesoTS.java

private static void calculoFeatures(Registro[] muestras, String activity) {

    DescriptiveStatistics stats_x = new DescriptiveStatistics();
    DescriptiveStatistics stats_y = new DescriptiveStatistics();
    DescriptiveStatistics stats_z = new DescriptiveStatistics();
    //DescriptiveStatistics stats_m1 = new DescriptiveStatistics();
    //DescriptiveStatistics stats_m2 = new DescriptiveStatistics();
    double[] fft_x;
    double[] fft_y;
    double[] fft_z;
    double[] AR_4;

    for (int i = 0; i < muestras.length; i++) {
        stats_x.addValue(muestras[i].getValor_x());
        stats_y.addValue(muestras[i].getValor_y());
        stats_z.addValue(muestras[i].getValor_z());
    }// www.j  a  v  a  2 s  . c  o m

    //********* FFT *********
    fft_x = Util.transform(stats_x.getValues());
    fft_y = Util.transform(stats_y.getValues());
    fft_z = Util.transform(stats_z.getValues());

    //******************* Eje X *******************//
    //mean(s) - Arithmetic mean
    System.out.print(stats_x.getMean() + ",");
    //std(s) - Standard deviation
    System.out.print(stats_x.getStandardDeviation() + ",");
    //mad(s) - Median absolute deviation
    //
    //max(s) - Largest values in array
    System.out.print(stats_x.getMax() + ",");
    //min(s) - Smallest value in array
    System.out.print(stats_x.getMin() + ",");
    //skewness(s) - Frequency signal Skewness
    System.out.print(stats_x.getSkewness() + ",");
    //kurtosis(s) - Frequency signal Kurtosis
    System.out.print(stats_x.getKurtosis() + ",");
    //energy(s) - Average sum of the squares
    System.out.print(stats_x.getSumsq() / stats_x.getN() + ",");
    //entropy(s) - Signal Entropy
    System.out.print(Util.calculateShannonEntropy(fft_x) + ",");
    //iqr (s) Interquartile range
    System.out.print(stats_x.getPercentile(75) - stats_x.getPercentile(25) + ",");
    try {
        //autoregression (s) -4th order Burg Autoregression coefficients
        AR_4 = AutoRegression.calculateARCoefficients(stats_x.getValues(), 4, true);
        System.out.print(AR_4[0] + ",");
        System.out.print(AR_4[1] + ",");
        System.out.print(AR_4[2] + ",");
        System.out.print(AR_4[3] + ",");
    } catch (Exception ex) {
        Logger.getLogger(PreprocesoTS.class.getName()).log(Level.SEVERE, null, ex);
    }
    //meanFreq(s) - Frequency signal weighted average
    System.out.print(Util.meanFreq(fft_x, stats_x.getValues()) + ",");

    //******************* Eje Y *******************//
    //mean(s) - Arithmetic mean
    System.out.print(stats_y.getMean() + ",");
    //std(s) - Standard deviation
    System.out.print(stats_y.getStandardDeviation() + ",");
    //mad(s) - Median absolute deviation
    //
    //max(s) - Largest values in array
    System.out.print(stats_y.getMax() + ",");
    //min(s) - Smallest value in array
    System.out.print(stats_y.getMin() + ",");
    //skewness(s) - Frequency signal Skewness
    System.out.print(stats_y.getSkewness() + ",");
    //kurtosis(s) - Frequency signal Kurtosis
    System.out.print(stats_y.getKurtosis() + ",");
    //energy(s) - Average sum of the squares
    System.out.print(stats_y.getSumsq() / stats_y.getN() + ",");
    //entropy(s) - Signal Entropy
    System.out.print(Util.calculateShannonEntropy(fft_y) + ",");
    //iqr (s) Interquartile range
    System.out.print(stats_y.getPercentile(75) - stats_y.getPercentile(25) + ",");
    try {
        //autoregression (s) -4th order Burg Autoregression coefficients
        AR_4 = AutoRegression.calculateARCoefficients(stats_y.getValues(), 4, true);
        System.out.print(AR_4[0] + ",");
        System.out.print(AR_4[1] + ",");
        System.out.print(AR_4[2] + ",");
        System.out.print(AR_4[3] + ",");
    } catch (Exception ex) {
        Logger.getLogger(PreprocesoTS.class.getName()).log(Level.SEVERE, null, ex);
    }
    //meanFreq(s) - Frequency signal weighted average
    System.out.print(Util.meanFreq(fft_y, stats_y.getValues()) + ",");

    //******************* Eje Z *******************//
    //mean(s) - Arithmetic mean
    System.out.print(stats_z.getMean() + ",");
    //std(s) - Standard deviation
    System.out.print(stats_z.getStandardDeviation() + ",");
    //mad(s) - Median absolute deviation
    //
    //max(s) - Largest values in array
    System.out.print(stats_z.getMax() + ",");
    //min(s) - Smallest value in array
    System.out.print(stats_z.getMin() + ",");
    //skewness(s) - Frequency signal Skewness
    System.out.print(stats_z.getSkewness() + ",");
    //kurtosis(s) - Frequency signal Kurtosis
    System.out.print(stats_z.getKurtosis() + ",");
    //energy(s) - Average sum of the squares
    System.out.print(stats_z.getSumsq() / stats_z.getN() + ",");
    //entropy(s) - Signal Entropy
    System.out.print(Util.calculateShannonEntropy(fft_z) + ",");
    //iqr (s) Interquartile range
    System.out.print(stats_z.getPercentile(75) - stats_z.getPercentile(25) + ",");
    try {
        //autoregression (s) -4th order Burg Autoregression coefficients
        AR_4 = AutoRegression.calculateARCoefficients(stats_z.getValues(), 4, true);
        System.out.print(AR_4[0] + ",");
        System.out.print(AR_4[1] + ",");
        System.out.print(AR_4[2] + ",");
        System.out.print(AR_4[3] + ",");
    } catch (Exception ex) {
        Logger.getLogger(PreprocesoTS.class.getName()).log(Level.SEVERE, null, ex);
    }
    //meanFreq(s) - Frequency signal weighted average
    System.out.print(Util.meanFreq(fft_z, stats_z.getValues()) + ",");

    //******************* Feature combinados *******************/
    //sma(s1; s2; s3) - Signal magnitude area
    System.out.print(Util.sma(stats_x.getValues(), stats_y.getValues(), stats_z.getValues()) + ",");
    //correlation(s1; s2) - Pearson Correlation coefficient
    System.out.print(new PearsonsCorrelation().correlation(stats_x.getValues(), stats_y.getValues()) + ",");
    System.out.print(new PearsonsCorrelation().correlation(stats_x.getValues(), stats_z.getValues()) + ",");
    System.out.print(new PearsonsCorrelation().correlation(stats_y.getValues(), stats_z.getValues()) + ",");

    //******************* Actividad *******************/
    System.out.print(activity);
    System.out.print("\n");
}

From source file:com.caseystella.analytics.util.DistributionUtil.java

public void summary(String title, DescriptiveStatistics statistics, PrintStream pw) {
    pw.println(title + ": " + "\n\tMin: " + statistics.getMin() + "\n\t1th: " + statistics.getPercentile(1)
            + "\n\t5th: " + statistics.getPercentile(5) + "\n\t10th: " + statistics.getPercentile(10)
            + "\n\t25th: " + statistics.getPercentile(25) + "\n\t50th: " + statistics.getPercentile(50)
            + "\n\t90th: " + statistics.getPercentile(90) + "\n\t95th: " + statistics.getPercentile(95)
            + "\n\t99th: " + statistics.getPercentile(99) + "\n\tMax: " + statistics.getMax() + "\n\tMean: "
            + statistics.getMean() + "\n\tStdDev: " + statistics.getStandardDeviation());
}

From source file:com.facebook.presto.operator.aggregation.AbstractTestApproximateCountDistinct.java

@Test(dataProvider = "provideStandardErrors")
public void testMultiplePositions(double maxStandardError) throws Exception {
    DescriptiveStatistics stats = new DescriptiveStatistics();

    for (int i = 0; i < 500; ++i) {
        int uniques = ThreadLocalRandom.current().nextInt(20000) + 1;

        List<Object> values = createRandomSample(uniques, (int) (uniques * 1.5));

        long actual = estimateGroupByCount(values, maxStandardError);
        double error = (actual - uniques) * 1.0 / uniques;

        stats.addValue(error);//  w w  w.  ja  va 2s. c  o  m
    }

    assertLessThan(stats.getMean(), 1.0e-2);
    assertLessThan(Math.abs(stats.getStandardDeviation() - maxStandardError), 1.0e-2);
}

From source file:knop.psfj.heatmap.FractionnedSpace.java

/**
 * Gets the mean number of beads.// w  ww .  ja va  2s . c o m
 *
 * @return the mean number of beads
 */
public double getMeanNumberOfBeads() {
    DescriptiveStatistics stats = new DescriptiveStatistics();

    for (Fraction f : this) {
        stats.addValue(f.size());
    }
    return stats.getMean();
}