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

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

Introduction

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

Prototype

public double getPercentile(double p) throws MathIllegalStateException, MathIllegalArgumentException 

Source Link

Document

Returns an estimate for the pth percentile of the stored values.

Usage

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

private static String formatApproximateOutput(DescriptiveStatistics statistics, double confidence) {
    StringBuilder sb = new StringBuilder();
    double p = 100 * (1 + confidence) / 2.0;
    double upper = statistics.getPercentile(p);
    double lower = statistics.getPercentile(100 - p);
    sb.append((upper + lower) / 2.0);//from w  w w .  ja  v  a 2  s.  c o  m
    sb.append(" +/- ");
    double error = (upper - lower) / 2.0;
    checkState(error >= 0, "error is negative");
    sb.append(error);

    return sb.toString();
}

From source file:com.caseystella.analytics.distribution.Distribution.java

public static double getMadScore(Iterable<Double> vals, Double val) {
    DescriptiveStatistics stats = new DescriptiveStatistics();
    DescriptiveStatistics medianStats = new DescriptiveStatistics();
    for (Double v : vals) {
        stats.addValue(v);//from   w  w w.  jav  a  2  s . co  m
    }
    double median = stats.getPercentile(50);
    for (Double v : vals) {
        medianStats.addValue(Math.abs(v - median));
    }
    double mad = medianStats.getPercentile(50);
    return Math.abs(0.6745 * (val - median) / mad);
}

From source file:com.intuit.tank.service.impl.v1.report.SummaryReportRunner.java

/**
 * @param key/* w w w  . j  av a 2s  .  c om*/
 * @param value
 * @return
 */
private static SummaryData getSummaryData(int jobId, String key, DescriptiveStatistics stats) {
    SummaryData ret = SummaryDataBuilder.summaryData().withJobId(jobId)
            .withKurtosis(!Double.isNaN(stats.getKurtosis()) ? stats.getKurtosis() : 0).withMax(stats.getMax())
            .withMean(stats.getMean()).withMin(stats.getMin()).withPageId(key)
            .withPercentile10(stats.getPercentile(10)).withPercentile20(stats.getPercentile(20))
            .withPercentile30(stats.getPercentile(30)).withPercentile40(stats.getPercentile(40))
            .withPercentile50(stats.getPercentile(50)).withPercentile60(stats.getPercentile(60))
            .withPercentile70(stats.getPercentile(70)).withPercentile80(stats.getPercentile(80))
            .withPercentile90(stats.getPercentile(90)).withPercentile95(stats.getPercentile(95))
            .withPercentile99(stats.getPercentile(99)).withSampleSize((int) stats.getN())
            .withSkewness(!Double.isNaN(stats.getSkewness()) ? stats.getSkewness() : 0)
            .withSttDev(!Double.isNaN(stats.getStandardDeviation()) ? stats.getStandardDeviation() : 0)
            .withVarience(!Double.isNaN(stats.getVariance()) ? stats.getVariance() : 0).build();
    return ret;
}

From source file:com.github.aptd.simulation.core.statistic.local.CStatistic.java

/**
 * write data/*from  w w w . j a  v a2  s .  co  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:de.uniulm.omi.cloudiator.axe.aggregator.utils.Calc.java

public static Double PERCENTILE(List<Double> values, Double p) {
    DescriptiveStatistics ds = transform(values);

    return ds.getPercentile(p);
}

From source file:de.uniulm.omi.cloudiator.axe.aggregator.utils.Calc.java

public static Double MEDIAN(List<Double> values) {
    DescriptiveStatistics ds = transform(values);

    return ds.getPercentile(50.0);
}

From source file:de.uniulm.omi.cloudiator.axe.aggregator.utils.Calc.java

public static Double PERCENTILE(List<Double> values) {
    //TODO this semantics has to be defined better
    Double p = values.get(0);/*from  w  w w .j a  v a  2 s  .c  o m*/
    values.remove(0);
    DescriptiveStatistics ds = transform(values);

    return ds.getPercentile(p);
}

From source file:edu.ucsc.barrel.cdf_gen.CDF_Gen.java

public static void fill511Gaps() {
    int size = data.getSize("mod32"), step_size = 1, start = 0;
    double delta, std_dev, med;
    float m, b, //values used for interpolating data        
            fill = (Float) CDFVar.getIstpVal("FLOAT_FILL"), new_value = fill, last_value = fill;
    DescriptiveStatistics stats = new DescriptiveStatistics();

    //generate statistics on the 511 peak jump sizes
    for (int peak_i = 0; peak_i < (size - 1); peak_i++) {
        if (data.peak511_bin[peak_i] == fill) {
            continue;
        }/*from  w w w . j  av  a  2s . c  o  m*/
        if (data.peak511_bin[peak_i + 1] == fill) {
            continue;
        }

        delta = data.peak511_bin[peak_i + 1] - data.peak511_bin[peak_i];
        if (delta != 0) {
            stats.addValue(delta);
        }
    }
    std_dev = stats.getStandardDeviation();
    med = stats.getPercentile(50);

    //find first good value
    for (start = 0; start < size; start++) {
        if (data.peak511_bin[start] != fill) {
            new_value = data.peak511_bin[start];
            last_value = data.peak511_bin[start];
            break;
        }
    }

    //fill any missing data before the first point
    Arrays.fill(data.peak511_bin, 0, start, new_value);

    for (int filler_i = start + 1; filler_i < size; filler_i++) {
        if (data.peak511_bin[filler_i] == fill) {
            //temporarily fill the gap with the last good value 
            //this is done in case there is not another good value
            //to use for interpolation
            data.peak511_bin[filler_i] = last_value;
            step_size++;
        } else {
            //make sure jump size wasn't too big
            delta = data.peak511_bin[filler_i] - data.peak511_bin[filler_i - 1];
            // if(Math.abs(delta - med) > (std_dev * 3)){
            //    data.peak511_bin[filler_i] = last_value;
            //    step_size++;
            // }

            last_value = new_value;
            new_value = data.peak511_bin[filler_i];

            //fill any gaps
            if (step_size > 1) {
                m = (last_value - new_value) / step_size;
                b = new_value - (m * filler_i);

                for (int fill_i = filler_i - step_size; fill_i < filler_i; fill_i++) {
                    data.peak511_bin[fill_i] = m * fill_i + b;
                }

                step_size = 1;
            }
        }
    }
}

From source file:cc.kave.commons.pointsto.evaluation.runners.ProjectStoreRunner.java

private static void countRecvCallSites(Collection<ICoReTypeName> types, ProjectUsageStore store)
        throws IOException {
    DescriptiveStatistics statistics = new DescriptiveStatistics();
    for (ICoReTypeName type : types) {
        if (store.getProjects(type).size() < 10) {
            continue;
        }/* w  ww .ja  va 2s  .co  m*/

        int numDistinctRecvCallsite = store.load(type, new PointsToUsageFilter()).stream()
                .flatMap(usage -> usage.getReceiverCallsites().stream()).map(CallSite::getMethod)
                .collect(Collectors.toSet()).size();
        if (numDistinctRecvCallsite > 0) {
            statistics.addValue(numDistinctRecvCallsite);
            System.out.printf(Locale.US, "%s: %d\n", CoReNames.vm2srcQualifiedType(type),
                    numDistinctRecvCallsite);
        }
    }
    System.out.println();
    System.out.printf(Locale.US, "mean: %.3f, stddev: %.3f, median: %.1f\n", statistics.getMean(),
            statistics.getStandardDeviation(), statistics.getPercentile(50));
}

From source file:me.datamining.bandwidth.MesureOfSpread.java

public double bandWidth(double variance, int dimensions, DescriptiveStatistics data) {

    double q1 = data.getPercentile(q1_);
    double q3 = data.getPercentile(q3_);
    return 0.9 * Math.min(variance, (q3 - q1) / 1.34) * Math.pow(data.getN(), -(1.0 / 5.0));
}