LogLikelihood { public static double entropy(int... elements) { double sum = 0.0; double result = 0.0; for (int element : elements) { if (element < 0) { throw new IllegalArgumentException("Should not have negative count for entropy computation: (" + element + ')'); } if (element > 0) { result += element * Math.log(element); sum += element; } } result -= sum * Math.log(sum); return -result; } private  LogLikelihood(); static double entropy(int... elements); static double logLikelihoodRatio(int k11, int k12, int k21, int k22); static double rootLogLikelihoodRatio(int k11, int k12, int k21, int k22);  }
@Test public void testEntropy() throws Exception { assertEquals(1.386294, LogLikelihood.entropy(1, 1), 0.0001); assertEquals(0.0, LogLikelihood.entropy(1), 0.0); try { LogLikelihood.entropy(-1, -1); fail(); } catch (IllegalArgumentException e) { } }