@Test public void testLogSumOfExps() throws Exception { Assert.assertEquals(0, ArrayMath.logSumOfExps(new double[] {0}), 0); Assert.assertEquals(1, ArrayMath.logSumOfExps(new double[] {1}), 0); Assert.assertEquals(2.048587, ArrayMath.logSumOfExps(new double[] {-1, 2}), 0.001); Assert.assertEquals(1.472216, ArrayMath.logSumOfExps(new double[] {-0.1, 0.2, -0.3, 0.4}), 0.001); }
public static double logSumOfExps(double[] x) { double max = max(x); double sum = 0.0; for (int i = 0; i < x.length; i++) { if (x[i] != Double.NEGATIVE_INFINITY) sum += StrictMath.exp(x[i] - max); } return max + StrictMath.log(sum); }
ArrayMath { public static double logSumOfExps(double[] x) { double max = max(x); double sum = 0.0; for (int i = 0; i < x.length; i++) { if (x[i] != Double.NEGATIVE_INFINITY) sum += StrictMath.exp(x[i] - max); } return max + StrictMath.log(sum); } }
ArrayMath { public static double logSumOfExps(double[] x) { double max = max(x); double sum = 0.0; for (int i = 0; i < x.length; i++) { if (x[i] != Double.NEGATIVE_INFINITY) sum += StrictMath.exp(x[i] - max); } return max + StrictMath.log(sum); }  }
ArrayMath { public static double logSumOfExps(double[] x) { double max = max(x); double sum = 0.0; for (int i = 0; i < x.length; i++) { if (x[i] != Double.NEGATIVE_INFINITY) sum += StrictMath.exp(x[i] - max); } return max + StrictMath.log(sum); }  static double innerProduct(double[] vecA, double[] vecB); static double l1norm(double[] v); static double l2norm(double[] v); static double invL2norm(double[] v); static double logSumOfExps(double[] x); static double max(double[] x); static int argmax(double[] x); static void sumFeatures(Context[] context, float[] values, double[] prior); static double[] toDoubleArray(List<Double> list); static int[] toIntArray(List<Integer> list); }
ArrayMath { public static double logSumOfExps(double[] x) { double max = max(x); double sum = 0.0; for (int i = 0; i < x.length; i++) { if (x[i] != Double.NEGATIVE_INFINITY) sum += StrictMath.exp(x[i] - max); } return max + StrictMath.log(sum); }  static double innerProduct(double[] vecA, double[] vecB); static double l1norm(double[] v); static double l2norm(double[] v); static double invL2norm(double[] v); static double logSumOfExps(double[] x); static double max(double[] x); static int argmax(double[] x); static void sumFeatures(Context[] context, float[] values, double[] prior); static double[] toDoubleArray(List<Double> list); static int[] toIntArray(List<Integer> list);  }