Example usage for org.apache.commons.math3.stat.descriptive.rank Median evaluate

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

Introduction

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

Prototype

public double evaluate() throws MathIllegalArgumentException 

Source Link

Document

Returns the result of evaluating the statistic over the stored data.

Usage

From source file:com.moto.miletus.application.ble.neardevice.NearDeviceHolder.java

/**
 * whoWins/*  w  ww  . j  a  v a  2  s.com*/
 */
private void whoWins() {
    if (list.isEmpty() || list.size() == 1) {
        broadcastDeviceRoom(null);
        setNearDevice(null);
        return;
    }

    Set<BluetoothDevice> devices = new HashSet<>();
    for (Pair<BluetoothDevice, Double> pair : list) {
        devices.add(pair.first);
    }

    Set<Pair<BluetoothDevice, Double>> medians = new HashSet<>(devices.size());
    for (BluetoothDevice device : devices) {
        List<Double> rssi = new ArrayList<>();
        for (Pair<BluetoothDevice, Double> pair : list) {
            if (pair.first.equals(device)) {
                rssi.add(pair.second);
            }
        }

        Median median = new Median();
        median.setData(ArrayUtils.toPrimitive(rssi.toArray(new Double[rssi.size()])));
        medians.add(new Pair<>(device, median.evaluate()));
    }

    Pair<BluetoothDevice, Double> winner = new Pair<>(null, -999999d);
    for (Pair<BluetoothDevice, Double> median : medians) {
        if (median.second > winner.second) {
            winner = median;
        }
    }

    broadcastDeviceRoom(winner.first);
    setNearDevice(winner.first);
}

From source file:plugin.trackmate.tram.trackanalyzer.TrAM.java

/**
 * Computes the median absolute difference between adjacent values within
 * each data vector.//  w w  w . jav  a 2s .c  om
 * 
 * @param timeSeries
 *            a staggered array whose rows are each independent time series.
 * @return the median absolute difference between adjacent values within all
 *         time series.
 */
public static double computeMedianAbsoluteDifference(final double[][] timeSeries) {
    if (timeSeries.length < 1)
        throw new IllegalArgumentException("Must have at least one data vector.");

    // where we accumulate all the absolute differences
    final ArrayDoubleList accum = new ArrayDoubleList();

    // compute absolute differences for each time series
    for (final double[] vals : timeSeries) {
        for (int i = 0; i < vals.length - 1; ++i)
            accum.add(Math.abs(vals[i + 1] - vals[i]));
    }

    final Median m = new Median();
    m.setData(accum.toArray());

    return m.evaluate();
}