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

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

Introduction

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

Prototype

public double[] getSortedValues() 

Source Link

Document

Returns the current set of values in an array of double primitives, sorted in ascending order.

Usage

From source file:de.fhg.igd.iva.explorer.main.CompareViewPanel.java

protected void updateSelection() {
    KnownColormap colormap = (KnownColormap) mapsCombo.getSelectedItem();

    cmView.setColormap(colormap);//from   w  w  w  .  j a  va 2s .c  o  m

    statsBars.removeAll();

    Map<ColormapQuality, Double> row = table.row(colormap);

    Insets insets = new Insets(0, 0, 0, 0);
    Insets insets5 = new Insets(0, 5, 0, 0);

    GridBagConstraints gbcName = new GridBagConstraints(0, 0, 1, 1, 0.0, 1.0, GridBagConstraints.LINE_START,
            GridBagConstraints.NONE, insets, 0, 0);
    GridBagConstraints gbcQual = new GridBagConstraints(1, 0, 1, 1, 0.0, 1.0, GridBagConstraints.LINE_END,
            GridBagConstraints.NONE, insets5, 0, 0);
    GridBagConstraints gbcRank = new GridBagConstraints(2, 0, 1, 1, 0.0, 1.0, GridBagConstraints.LINE_END,
            GridBagConstraints.NONE, insets5, 0, 0);
    GridBagConstraints gbcStatL = new GridBagConstraints(3, 0, 1, 1, 1.0, 1.0, GridBagConstraints.LINE_START,
            GridBagConstraints.NONE, insets5, 0, 0);
    GridBagConstraints gbcStatR = new GridBagConstraints(4, 0, 1, 1, 1.0, 1.0, GridBagConstraints.LINE_END,
            GridBagConstraints.NONE, insets5, 0, 0);
    GridBagConstraints gbcStat = new GridBagConstraints(3, 0, 2, 1, 1.0, 1.0, GridBagConstraints.LINE_START,
            GridBagConstraints.HORIZONTAL, insets5, 0, 0);

    statsBars.add(new JLabel("Name"), gbcName);
    statsBars.add(new JLabel("Score"), gbcQual);
    statsBars.add(new JLabel("Rank"), gbcRank);

    // maybe use a best/worst arrow down marker instead? unicode: \u2193
    statsBars.add(new JLabel("\u2190Worse"), gbcStatL);
    statsBars.add(new JLabel("Better\u2192"), gbcStatR);

    GridBagConstraints gbcSpace = new GridBagConstraints(0, 1, 5, 1, 1.0, 1.0, GridBagConstraints.LINE_START,
            GridBagConstraints.HORIZONTAL, new Insets(0, 0, 5, 0), 0, 0);
    JSeparator spacing = new JSeparator(SwingConstants.HORIZONTAL);
    statsBars.add(spacing, gbcSpace);

    int count = table.rowKeySet().size();

    int rowIdx = 2;
    for (ColormapQuality metric : row.keySet()) {
        double quality = row.get(metric);
        DescriptiveStatistics stats = computeStats(metric);
        int index = Arrays.binarySearch(stats.getSortedValues(), quality);

        int rank = metric.moreIsBetter() ? count - index : index + 1;

        gbcName = (GridBagConstraints) gbcName.clone();
        gbcQual = (GridBagConstraints) gbcQual.clone();
        gbcRank = (GridBagConstraints) gbcRank.clone();
        gbcStat = (GridBagConstraints) gbcStat.clone();

        gbcName.gridy = rowIdx;
        gbcQual.gridy = rowIdx;
        gbcRank.gridy = rowIdx;
        gbcStat.gridy = rowIdx;

        statsBars.add(new JLabel(metric.getName()), gbcName);
        statsBars.add(new JLabel(String.format("%.2f", quality)), gbcQual);
        statsBars.add(new JLabel(Integer.toString(rank)), gbcRank);
        statsBars.add(new JStatBar(metric, stats, quality), gbcStat);
        rowIdx++;
    }

    // I find it strange that both revalidate and repaint must be explicitly called here
    revalidate();
    repaint();
}

From source file:org.orbisgis.view.toc.actions.cui.legend.stats.Thresholds.java

/**
 * This method ://from  w  w  w.j a  v  a 2 s. c  o m
 * - Feeds the given SortedSet with the mean of the given statistics.
 * - Calls itself recursively on the two subset obtained by dividing the set around its mean, if lev > 0.
 * @param inpStat The input statistics
 * @param toFeed The SortedSet we want to feed
 * @param lev The remaining number of levels we have to process.
 */
private void computeBoxedMeans(DescriptiveStatistics inpStat, SortedSet<Double> toFeed, int lev) {
    double[] input = inpStat.getSortedValues();
    double mean = inpStat.getMean();
    toFeed.add(mean);
    if (lev > 0) {
        int i = Arrays.binarySearch(input, mean);
        int ind = i < 0 ? -i - 1 : i;
        double[] first = Arrays.copyOf(input, ind);
        double[] tail = Arrays.copyOfRange(input, ind, input.length);
        computeBoxedMeans(new DescriptiveStatistics(first), toFeed, lev - 1);
        computeBoxedMeans(new DescriptiveStatistics(tail), toFeed, lev - 1);
    }
}