List of usage examples for org.apache.commons.math4.stat.descriptive SummaryStatistics SummaryStatistics
public SummaryStatistics()
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"); }/* w w w. ja va 2s. c o m*/ 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; }