@Test(expected=IllegalArgumentException.class) public void testCalcSampleVarianceWithIllegalArgument() { final double[] x = { 1.0 }; FunctionUtil.calcSampleVariance(x); }
public static double calcSampleVariance(final double[] x) { final int n = x.length; if (n < 2) throw new IllegalArgumentException("can't calculate a variance with fewer than 2 values."); final double[] xSquared = new double[n]; for (int i = 0; i < n; ++i) xSquared[i] = x[i] * x[i]; final double sumOfX = numericallySafeSum(x); final double sumOfXSquared = numericallySafeSum(xSquared); return (sumOfXSquared - (sumOfX * sumOfX) / (double)n) / (double)(n - 1); }
FunctionUtil { public static double calcSampleVariance(final double[] x) { final int n = x.length; if (n < 2) throw new IllegalArgumentException("can't calculate a variance with fewer than 2 values."); final double[] xSquared = new double[n]; for (int i = 0; i < n; ++i) xSquared[i] = x[i] * x[i]; final double sumOfX = numericallySafeSum(x); final double sumOfXSquared = numericallySafeSum(xSquared); return (sumOfXSquared - (sumOfX * sumOfX) / (double)n) / (double)(n - 1); } }
FunctionUtil { public static double calcSampleVariance(final double[] x) { final int n = x.length; if (n < 2) throw new IllegalArgumentException("can't calculate a variance with fewer than 2 values."); final double[] xSquared = new double[n]; for (int i = 0; i < n; ++i) xSquared[i] = x[i] * x[i]; final double sumOfX = numericallySafeSum(x); final double sumOfXSquared = numericallySafeSum(xSquared); return (sumOfXSquared - (sumOfX * sumOfX) / (double)n) / (double)(n - 1); } private  FunctionUtil(); }
FunctionUtil { public static double calcSampleVariance(final double[] x) { final int n = x.length; if (n < 2) throw new IllegalArgumentException("can't calculate a variance with fewer than 2 values."); final double[] xSquared = new double[n]; for (int i = 0; i < n; ++i) xSquared[i] = x[i] * x[i]; final double sumOfX = numericallySafeSum(x); final double sumOfXSquared = numericallySafeSum(xSquared); return (sumOfXSquared - (sumOfX * sumOfX) / (double)n) / (double)(n - 1); } private  FunctionUtil(); static double getArgAsDouble(final Object arg); static String getArgAsString(final Object arg); static long getArgAsLong(final Object arg); static boolean getArgAsBoolean(final Object arg); static double numericallySafeSum(final double a[]); static String getOrdinal(final int i); static double calcSampleVariance(final double[] x); static double[] listToArray(final List<Double> a); static boolean isScalarArgType(final Class type); static boolean isTypeOfList(final Class listClassCandidate); static void addScalarArgumentTypes(final List<Class> argTypes); static double[] getDoubles(final Object[] args); static long[] getLongs(final Object[] args); static String[] getStrings(final Object[] args); static boolean[] getBooleans(final Object[] args); static Object translateObjectType(final Object input); }
FunctionUtil { public static double calcSampleVariance(final double[] x) { final int n = x.length; if (n < 2) throw new IllegalArgumentException("can't calculate a variance with fewer than 2 values."); final double[] xSquared = new double[n]; for (int i = 0; i < n; ++i) xSquared[i] = x[i] * x[i]; final double sumOfX = numericallySafeSum(x); final double sumOfXSquared = numericallySafeSum(xSquared); return (sumOfXSquared - (sumOfX * sumOfX) / (double)n) / (double)(n - 1); } private  FunctionUtil(); static double getArgAsDouble(final Object arg); static String getArgAsString(final Object arg); static long getArgAsLong(final Object arg); static boolean getArgAsBoolean(final Object arg); static double numericallySafeSum(final double a[]); static String getOrdinal(final int i); static double calcSampleVariance(final double[] x); static double[] listToArray(final List<Double> a); static boolean isScalarArgType(final Class type); static boolean isTypeOfList(final Class listClassCandidate); static void addScalarArgumentTypes(final List<Class> argTypes); static double[] getDoubles(final Object[] args); static long[] getLongs(final Object[] args); static String[] getStrings(final Object[] args); static boolean[] getBooleans(final Object[] args); static Object translateObjectType(final Object input);  }