Example usage for org.apache.commons.math3.stat StatUtils sumDifference

List of usage examples for org.apache.commons.math3.stat StatUtils sumDifference

Introduction

In this page you can find the example usage for org.apache.commons.math3.stat StatUtils sumDifference.

Prototype

public static double sumDifference(final double[] sample1, final double[] sample2)
        throws DimensionMismatchException, NoDataException 

Source Link

Document

Returns the sum of the (signed) differences between corresponding elements of the input arrays -- i.e., sum(sample1[i] - sample2[i]).

Usage

From source file:org.apache.solr.client.solrj.io.eval.SumDifferenceEvaluator.java

@Override
public Object doWork(Object first, Object second) throws IOException {
    if (null == first) {
        throw new IOException(String.format(Locale.ROOT,
                "Invalid expression %s - null found for the first value", toExpression(constructingFactory)));
    }/* w  w  w .  j av a2  s . c o m*/
    if (null == second) {
        throw new IOException(String.format(Locale.ROOT,
                "Invalid expression %s - null found for the second value", toExpression(constructingFactory)));
    }
    if (!(first instanceof List<?>)) {
        throw new IOException(String.format(Locale.ROOT,
                "Invalid expression %s - found type %s for the first value, expecting a list of numbers",
                toExpression(constructingFactory), first.getClass().getSimpleName()));
    }
    if (!(second instanceof List<?>)) {
        throw new IOException(String.format(Locale.ROOT,
                "Invalid expression %s - found type %s for the second value, expecting a list of numbers",
                toExpression(constructingFactory), first.getClass().getSimpleName()));
    }

    return StatUtils.sumDifference(
            ((List) first).stream().mapToDouble(value -> ((BigDecimal) value).doubleValue()).toArray(),
            ((List) second).stream().mapToDouble(value -> ((BigDecimal) value).doubleValue()).toArray());
}