MathUtils { public static double weightedGeometricMean(double[] weights, double[] scores) { if(weights.length == 0) throw new IllegalArgumentException("Not clear what geometric mean should do with empty arguments"); if(weights.length != scores.length) throw new IllegalArgumentException("weights and scores must be of the same length"); double product = 1; for (int i = 0; i < weights.length; i++) { product *= weights[i]*scores[i]; } return Math.pow(product, 1.0/weights.length); } 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 testWeightedGeometricMean() { assertEquals(4.0, MathUtils.weightedGeometricMean(new double[] {2,1}, new double[] { 2, 4 }), 0.1); }