Example usage for org.apache.commons.math3.stat.descriptive.rank Percentile Percentile

List of usage examples for org.apache.commons.math3.stat.descriptive.rank Percentile Percentile

Introduction

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

Prototype

public Percentile() 

Source Link

Document

Constructs a Percentile with a default quantile value of 50.0.

Usage

From source file:inflor.core.transforms.LogicleTransform.java

@Override
public void optimize(double[] rawData) {
    double newt = new Percentile().evaluate(rawData, LOGICLE_T_PERCENTILE);
    double neww = optimizeW(rawData);
    //TODO A and M.
    try {/*from  w  ww.  j av  a 2  s.  c o m*/
        this.logicle = new FastLogicle(newt, neww, logicle.M, logicle.A);
    } catch (Exception e) {
        //Ideally we catch this before hand but for now:
        Exception e2 = new RuntimeException("bad input parameters: T [1] w [2], M [3], A [4]"
                .replace("[1]", Double.toString(logicle.T)).replace("[2]", Double.toString(logicle.w))
                .replace("[3]", Double.toString(logicle.M)).replace("[4]", Double.toString(logicle.A)));
        e2.initCause(e);
    }
}

From source file:edu.cuny.qc.speech.AuToBI.PitchExtractor.java

/**
 * Calls getPitch with no paramters, automatically setting the min and max values for more precise estimation.
 * <p/>/*w  ww. j  a va2  s  .  c  o m*/
 * This is based on the DeLooze and Rauzy (Automatic Detection and Prediction of Topic Changes
 * Through Automatic Detection of Register variations and Pause Duration. De Looze and Rauzy. 2009)
 * It's usefulness was described by The importance of optimal parameter setting for pitch extraction. 2010. Acoustical
 * Society of America. Evanini, Lai and Zechner.
 */
public Contour soundToPitchTwoPass() throws AuToBIException {
    // initial min and max values.
    Contour c = soundToPitch(0.01, 50, 400);

    // identify relevant percentile values
    Percentile p = new Percentile();
    double[] values = new double[c.contentSize()];
    int i = 0;
    for (Pair<Double, Double> tvp : c) {
        values[i++] = tvp.second;
    }
    double q35 = p.evaluate(values, 35.);
    double q65 = p.evaluate(values, 65.);

    // run getPitch again
    return soundToPitch(0.01, q35 * 0.72 - 10, q65 * 1.9 + 10);
}

From source file:info.mikaelsvensson.devtools.analysis.shared.AbstractLog.java

public Percentile getPercentileCalculator(Collection<T> samples) {
    double[] responseTimes = toDurationDoubles(samples);
    Arrays.sort(responseTimes);// w  ww  .j  a  v  a2s .  co m
    Percentile percentile = new Percentile();
    percentile.setData(responseTimes);
    return percentile;
}

From source file:edu.umd.umiacs.clip.tools.classifier.ConfusionMatrix.java

public float getF1LowerBound() {
    Percentile percentile = new Percentile();
    percentile.setData(Stream.of(sampleFromPosterior()).parallel().mapToDouble(cm -> cm.getF1()).toArray());
    return (float) percentile.evaluate(100 * (1 - CONF_LEVEL));
}

From source file:edu.umd.umiacs.clip.tools.classifier.ConfusionMatrix.java

public Pair<Float, Float> getF1CI() {
    Percentile percentile = new Percentile();
    percentile.setData(Stream.of(sampleFromPosterior()).parallel().mapToDouble(cm -> cm.getF1()).toArray());
    double alpha = (1 - CONF_LEVEL) / 2;
    return Pair.of((float) percentile.evaluate(100 * alpha), (float) percentile.evaluate(100 * (1 - alpha)));
}

From source file:com.itemanalysis.psychometrics.histogram.Histogram.java

private void createHistogram(double[] x) {
    n = x.length;/*  w  ww .j ava2  s.c  o  m*/
    Min min = new Min();
    Max max = new Max();
    Mean mean = new Mean();
    StandardDeviation sd = new StandardDeviation();

    for (int i = 0; i < x.length; i++) {
        min.increment(x[i]);
        max.increment(x[i]);
        mean.increment(x[i]);
        sd.increment(x[i]);
    }

    double range = max.getResult() - min.getResult();
    double lowestBoundary = min.getResult() - range / 1000;
    double largestBoundary = max.getResult() + range / 1000;

    if (binCalculationType == BinCalculationType.SCOTT) {
        binCalc = new ScottBinCalculation(n, min.getResult(), max.getResult(), sd.getResult());
    } else if (binCalculationType == BinCalculationType.FREEDMAN_DIACONIS) {
        Percentile percentile = new Percentile();
        double q1 = percentile.evaluate(x, 25);
        double q3 = percentile.evaluate(x, 75);
        binCalc = new FreedmanDiaconisBinCalculation(n, min.getResult(), max.getResult(), q1, q3);
    } else if (binCalculationType == BinCalculationType.STURGES) {
        binCalc = new SturgesBinCalculation(n, min.getResult(), max.getResult());
    }

    numberOfBins = binCalc.numberOfBins();
    binWidth = binCalc.binWidth();

    //create bins
    createBins(lowestBoundary, largestBoundary);

    //count observations in each bin
    for (int i = 0; i < n; i++) {
        for (Bin b : bins) {
            b.increment(x[i]);
        }
    }
}

From source file:edu.umd.umiacs.clip.tools.classifier.ConfusionMatrix.java

public float getRecallLowerBound() {
    Percentile percentile = new Percentile();
    percentile.setData(Stream.of(sampleFromPosterior()).parallel().mapToDouble(cm -> cm.getRecall()).toArray());
    return (float) percentile.evaluate(100 * (1 - CONF_LEVEL));
}

From source file:edu.umd.umiacs.clip.tools.classifier.ConfusionMatrix.java

public Pair<Float, Float> getRecallCI() {
    Percentile percentile = new Percentile();
    percentile.setData(Stream.of(sampleFromPosterior()).parallel().mapToDouble(cm -> cm.getRecall()).toArray());
    double alpha = (1 - CONF_LEVEL) / 2;
    return Pair.of((float) percentile.evaluate(100 * alpha), (float) percentile.evaluate(100 * (1 - alpha)));
}

From source file:edu.umd.umiacs.clip.tools.classifier.ConfusionMatrix.java

public float getPrecisionLowerBound() {
    Percentile percentile = new Percentile();
    percentile.setData(//  w  ww .  j  av  a 2  s  .  c  o  m
            Stream.of(sampleFromPosterior()).parallel().mapToDouble(cm -> cm.getPrecision()).toArray());
    return (float) percentile.evaluate(100 * (1 - CONF_LEVEL));
}

From source file:com.mgmtp.perfload.perfalyzer.binning.MeasuringResponseTimesBinningStrategy.java

@Override
public void aggregateData(final ChannelManager channelManager) throws IOException {
    WritableByteChannel quantilesChannel = channelManager.getChannel("quantiles");
    writeQuantilesHeader(quantilesChannel);

    int i = 0;/*from w w w .  j a  va  2  s .  co m*/
    for (Entry<String, UriMeasurings> entry : measuringsMap.entrySet()) {
        UriMeasurings measurings = entry.getValue();
        String uri = measurings.uriAlias;
        if (measurings.responseTimes.isEmpty()) {
            continue;
        }

        Percentile percentile = new Percentile();
        double[] responseTimes = Doubles.toArray(measurings.responseTimes);
        percentile.setData(responseTimes);

        // each uri is mapped to a key which is simple a number that is left-padded for better sorting
        String mappingKey = leftPad(String.valueOf(i++), 3, '0');

        StrBuilder sb = new StrBuilder(150);
        appendEscapedAndQuoted(sb, DELIMITER, mappingKey);
        appendEscapedAndQuoted(sb, DELIMITER, measurings.type);
        appendEscapedAndQuoted(sb, DELIMITER, uri);
        appendEscapedAndQuoted(sb, DELIMITER, intNumberFormat.format(responseTimes.length));
        appendEscapedAndQuoted(sb, DELIMITER, intNumberFormat.format(measurings.errorCount));
        appendEscapedAndQuoted(sb, DELIMITER, intNumberFormat.format(Doubles.min(responseTimes)));
        appendEscapedAndQuoted(sb, DELIMITER, intNumberFormat.format(percentile.evaluate(10d)));
        appendEscapedAndQuoted(sb, DELIMITER, intNumberFormat.format(percentile.evaluate(50d)));
        appendEscapedAndQuoted(sb, DELIMITER, intNumberFormat.format(percentile.evaluate(90d)));
        appendEscapedAndQuoted(sb, DELIMITER, intNumberFormat.format(Doubles.max(responseTimes)));
        writeLineToChannel(quantilesChannel, sb.toString(), Charsets.UTF_8);

        // write response time distributions
        WritableByteChannel distributionChannel = channelManager.getChannel("distribution_" + mappingKey);
        writeDistributionHeader(distributionChannel);

        for (Entry<Long, MutableInt> e : measurings.responseDistributions.entrySet()) {
            sb = new StrBuilder();
            appendEscapedAndQuoted(sb, DELIMITER, e.getKey());
            appendEscapedAndQuoted(sb, DELIMITER, intNumberFormat.format(e.getValue()));
            writeLineToChannel(distributionChannel, sb.toString(), Charsets.UTF_8);
        }
    }

    writeExecutionAggregatedResponseTimesHeader(channelManager.getChannel("aggregatedResponseTimes"));
    if (!perExecutionResponseTimes.isEmpty()) {
        BinManager executionsPerMinuteBinManager = new BinManager(startOfFirstBin,
                PerfAlyzerConstants.BIN_SIZE_MILLIS_1_MINUTE);
        BinManager executionsPerTenMinutesBinManager = new BinManager(startOfFirstBin,
                PerfAlyzerConstants.BIN_SIZE_MILLIS_10_MINUTES);
        BinManager medianExecutionBinManager = new BinManager(startOfFirstBin,
                PerfAlyzerConstants.BIN_SIZE_MILLIS_30_SECONDS);

        List<ExecutionMeasurings> values = newArrayList(perExecutionResponseTimes.values());

        for (ExecutionMeasurings execMeasurings : values) {
            long timestampMillis = execMeasurings.timestampMillis;
            executionsPerMinuteBinManager.addValue(timestampMillis);
            executionsPerTenMinutesBinManager.addValue(timestampMillis);
            medianExecutionBinManager.addValue(timestampMillis,
                    execMeasurings.sumResponseTimes.doubleValue() / 1000);
        }

        executionsPerMinuteBinManager.toCsv(channelManager.getChannel("execMin"), "time", "count",
                intNumberFormat);
        executionsPerTenMinutesBinManager.toCsv(channelManager.getChannel("exec10Min"), "time", "count",
                intNumberFormat);
        medianExecutionBinManager.toCsv(channelManager.getChannel("executions"), "time", "median",
                intNumberFormat, AggregationType.MEDIAN);

        double[] sumResponseTimes = values.stream().mapToDouble(input -> input.sumResponseTimes.doubleValue())
                .toArray();

        StrBuilder sb = new StrBuilder(150);
        appendEscapedAndQuoted(sb, DELIMITER, intNumberFormat.format(Doubles.min(sumResponseTimes) / 1000));
        appendEscapedAndQuoted(sb, DELIMITER,
                intNumberFormat.format(StatUtils.percentile(sumResponseTimes, 50d) / 1000));
        appendEscapedAndQuoted(sb, DELIMITER, intNumberFormat.format(Doubles.max(sumResponseTimes) / 1000));
        writeLineToChannel(channelManager.getChannel("aggregatedResponseTimes"), sb.toString(), Charsets.UTF_8);
    }
}