@Test public void testLogSumExpSimple() { final double log2prob = -1000; assertEquals(StatsUtil.log2SumOfExponentials(log2prob, log2prob), -999, 10E-100); final double log2prob2 = -10000; assertEquals(StatsUtil.log2SumOfExponentials(log2prob2, log2prob2), -9999, 10E-100); assertEquals(StatsUtil.log2SumOfExponentials(log2prob, log2prob2), -1000, 10E-10); }
public static double log2SumOfExponentials(final Collection<Double> values) { if (values.size() == 1) { return values.iterator().next(); } final double max = max(values); double sum = 0.0; for (final double value : values) { if (value != Double.NEGATIVE_INFINITY) { sum += Math.pow(2, value - max); } } return max + DoubleMath.log2(sum); }
StatsUtil { public static double log2SumOfExponentials(final Collection<Double> values) { if (values.size() == 1) { return values.iterator().next(); } final double max = max(values); double sum = 0.0; for (final double value : values) { if (value != Double.NEGATIVE_INFINITY) { sum += Math.pow(2, value - max); } } return max + DoubleMath.log2(sum); } }
StatsUtil { public static double log2SumOfExponentials(final Collection<Double> values) { if (values.size() == 1) { return values.iterator().next(); } final double max = max(values); double sum = 0.0; for (final double value : values) { if (value != Double.NEGATIVE_INFINITY) { sum += Math.pow(2, value - max); } } return max + DoubleMath.log2(sum); }  }
StatsUtil { public static double log2SumOfExponentials(final Collection<Double> values) { if (values.size() == 1) { return values.iterator().next(); } final double max = max(values); double sum = 0.0; for (final double value : values) { if (value != Double.NEGATIVE_INFINITY) { sum += Math.pow(2, value - max); } } return max + DoubleMath.log2(sum); }  static Optional<Integer> argmax(final double[] array); static Optional<T> argmax(final Map<T, Double> valuedObjects); static double[] divideArrayElements(final int[] array,
			final int divisor); static double log2SumOfExponentials(final Collection<Double> values); static double log2SumOfExponentials(final double... values); static double log2SumOfExponentials(final double log2Prob1,
			final double log2Prob2); static double max(final double... array); static Double max(final Iterable<Double> values); static double mean(final Collection<Double> values); static double median(final List<Double> values); static double min(final Collection<Double> xs); static double min(final double... array); static double mode(final Collection<Double> values); static double norm(final double... array); static void normalizeLog2Probs(final double[] log2prob); static void normalizeLog2Probs(final Map<T, Double> log2prob); static double sum(final double... array); static double sum(final Iterable<Double> values); }
StatsUtil { public static double log2SumOfExponentials(final Collection<Double> values) { if (values.size() == 1) { return values.iterator().next(); } final double max = max(values); double sum = 0.0; for (final double value : values) { if (value != Double.NEGATIVE_INFINITY) { sum += Math.pow(2, value - max); } } return max + DoubleMath.log2(sum); }  static Optional<Integer> argmax(final double[] array); static Optional<T> argmax(final Map<T, Double> valuedObjects); static double[] divideArrayElements(final int[] array,
			final int divisor); static double log2SumOfExponentials(final Collection<Double> values); static double log2SumOfExponentials(final double... values); static double log2SumOfExponentials(final double log2Prob1,
			final double log2Prob2); static double max(final double... array); static Double max(final Iterable<Double> values); static double mean(final Collection<Double> values); static double median(final List<Double> values); static double min(final Collection<Double> xs); static double min(final double... array); static double mode(final Collection<Double> values); static double norm(final double... array); static void normalizeLog2Probs(final double[] log2prob); static void normalizeLog2Probs(final Map<T, Double> log2prob); static double sum(final double... array); static double sum(final Iterable<Double> values);  }