MathUtils { public static double logSumExp(double[] scores) { double[] weights = new double[scores.length]; Arrays.fill(weights, 1.0); return weightedLogSumExp(weights, scores); } private  MathUtils(); static long binomialCoeff(int n, int k); static double logSumExp(double[] scores); static double logWeightedGeometricMean(double[] weights, double[] logScores); static double weightedArithmeticMean(double[] weights, double[] scores); static double weightedGeometricMean(double[] weights, double[] scores); static double weightedLogSumExp(double[] weights, double[] scores); static double logprob(double input); static double clamp(double input, double min, double max); static double sigmoid(double t);  }
@Test public void testLogSumExp() throws Exception { double val = MathUtils.logSumExp(new double[] { Math.log(2), Math.log(3) }); assertEquals(Math.log(5), val, 0.1); assertEquals(Math.log(9), MathUtils.logSumExp(new double[] { Math.log(2), Math.log(3), Math.log(4) }), 0.1); }