/** * Returns the sum of an array of doubles. */ public static double sum(double[] a) { return sum(a,0,a.length); }
/** Return the mean of an array of int. */ public static double mean(int[] a) { return ((double) sum(a)) / a.length; }
public static double average(double[] a) { double total = ArrayMath.sum(a); return total / a.length; }
public static double mean(double[] a) { return sum(a) / a.length; }
public static double klDivergence(double[] from, double[] to) { double kl = 0.0; double tot = sum(from); double tot2 = sum(to); // System.out.println("tot is " + tot + " tot2 is " + tot2); for (int i = 0; i < from.length; i++) { if (from[i] == 0.0) { continue; } double num = from[i] / tot; double num2 = to[i] / tot2; // System.out.println("num is " + num + " num2 is " + num2); kl += num * (Math.log(num / num2) / Math.log(2.0)); } return kl; }
/** * Makes the values in this array sum to 1.0. Does it in place. * If the total is 0.0 or NaN, throws an RuntimeException. */ public static void normalize(float[] a) { float total = sum(a); if (total == 0.0f || Double.isNaN(total)) { throw new RuntimeException("Can't normalize an array with sum 0.0 or NaN"); } multiplyInPlace(a, 1.0f/total); // divide each value by total } public static void L2normalize(float[] a) {
/** * Makes the values in this array sum to 1.0. Does it in place. * If the total is 0.0 or NaN, throws an RuntimeException. */ public static void normalize(double[] a) { double total = sum(a); if (total == 0.0 || Double.isNaN(total)) { throw new RuntimeException("Can't normalize an array with sum 0.0 or NaN: " + Arrays.toString(a)); } multiplyInPlace(a, 1.0/total); // divide each value by total }
double sum = ArrayMath.sum(matrix[i]); for (int j = 0; j < matrix[i].length; j++) {
for(int f = 0; f < dataset.numFeatures(); f++){ int maxF = ArrayMath.max(feature2label[f]); int total = ArrayMath.sum(feature2label[f]); double precision = ((double)maxF)/total; F feature = dataset.featureIndex.get(f);
/** * Returns the sum of an array of doubles. */ public static double sum(double[] a) { return sum(a,0,a.length); }
/** * Returns the sum of an array of numbers. */ public static double sum(double[] a) { return sum(a,0,a.length); }
/** * Returns the sum of an array of doubles. */ public static double sum(double[] a) { return sum(a,0,a.length); }
/** * Returns the sum of an array of numbers. */ public static double sum(double[] a) { return sum(a,0,a.length); }
/** * Makes the values in this array sum to 1.0. Does it in place. * If the total is 0.0 or NaN, throws an RuntimeException. */ public static void normalize(double[] a) { double total = sum(a); if (total == 0.0 || Double.isNaN(total)) { throw new RuntimeException("Can't normalize an array with sum 0.0 or NaN: " + Arrays.toString(a)); } multiplyInPlace(a, 1.0/total); // divide each value by total }
/** * Makes the values in this array sum to 1.0. Does it in place. * If the total is 0.0 or NaN, throws an RuntimeException. */ public static void normalize(float[] a) { float total = sum(a); if (total == 0.0f || Double.isNaN(total)) { throw new RuntimeException("Can't normalize an array with sum 0.0 or NaN"); } multiplyInPlace(a, 1.0f/total); // divide each value by total } public static void L2normalize(float[] a) {
/** * Makes the values in this array sum to 1.0. Does it in place. * If the total is 0.0 or NaN, throws an RuntimeException. */ public static void normalize(double[] a) { double total = sum(a); if (total == 0.0 || Double.isNaN(total)) { throw new RuntimeException("Can't normalize an array with sum 0.0 or NaN: " + Arrays.toString(a)); } multiplyInPlace(a, 1.0/total); // divide each value by total }
/** * Makes the values in this array sum to 1.0. Does it in place. * If the total is 0.0 or NaN, throws an RuntimeException. */ public static void normalize(float[] a) { float total = sum(a); if (total == 0.0f || Double.isNaN(total)) { throw new RuntimeException("Can't normalize an array with sum 0.0 or NaN"); } multiplyInPlace(a, 1.0f/total); // divide each value by total } public static void L2normalize(float[] a) {
/** * Makes the values in this array sum to 1.0. Does it in place. * If the total is 0.0 or NaN, throws an RuntimeException. */ public static void normalize(float[] a) { float total = sum(a); if (total == 0.0 || Double.isNaN(total)) { throw new RuntimeException("Can't normalize an array with sum 0.0 or NaN"); } multiplyInPlace(a, 1.0/total); // divide each value by total }
/** * Makes the values in this array sum to 1.0. Does it in place. * If the total is 0.0 or NaN, throws an RuntimeException. */ public static void normalize(double[] a) { double total = sum(a); if (total == 0.0 || Double.isNaN(total)) { throw new RuntimeException("Can't normalize an array with sum 0.0 or NaN: " + Arrays.toString(a)); } multiplyInPlace(a, 1.0/total); // divide each value by total }
/** * Makes the values in this array sum to 1.0. Does it in place. * If the total is 0.0 or NaN, throws an RuntimeException. */ public static void normalize(float[] a) { float total = sum(a); if (total == 0.0f || Double.isNaN(total)) { throw new RuntimeException("Can't normalize an array with sum 0.0 or NaN"); } multiplyInPlace(a, 1.0f/total); // divide each value by total }