Example usage for org.apache.commons.math4.stat.descriptive SummaryStatistics addValue

List of usage examples for org.apache.commons.math4.stat.descriptive SummaryStatistics addValue

Introduction

In this page you can find the example usage for org.apache.commons.math4.stat.descriptive SummaryStatistics addValue.

Prototype

public void addValue(double value) 

Source Link

Document

Add a value to the data

Usage

From source file:RealFunctionValidation.java

public static SummaryStatistics assessAccuracy(final Method method, final DataInputStream in,
        final DataOutputStream out)
        throws IOException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {

    if (method.getReturnType() != Double.TYPE) {
        throw new IllegalArgumentException("method must return a double");
    }/*ww w.  j  av  a 2  s  .c om*/

    final Class<?>[] types = method.getParameterTypes();
    for (int i = 0; i < types.length; i++) {
        if (!types[i].isPrimitive()) {
            final StringBuilder builder = new StringBuilder();
            builder.append("argument #").append(i + 1).append(" of method ").append(method.getName())
                    .append("must be of primitive of type");
            throw new IllegalArgumentException(builder.toString());
        }
    }

    final SummaryStatistics stat = new SummaryStatistics();
    final Object[] parameters = new Object[types.length];
    while (true) {
        try {
            for (int i = 0; i < parameters.length; i++) {
                parameters[i] = readAndWritePrimitiveValue(in, out, types[i]);
            }
            final double expected = in.readDouble();
            if (FastMath.abs(expected) > 1E-16) {
                final Object value = method.invoke(null, parameters);
                final double actual = ((Double) value).doubleValue();
                final double err = FastMath.abs(actual - expected);
                final double ulps = err / FastMath.ulp(expected);
                out.writeDouble(expected);
                out.writeDouble(actual);
                out.writeDouble(ulps);
                stat.addValue(ulps);
            }
        } catch (EOFException e) {
            break;
        }
    }
    return stat;
}