Auc { public Matrix entropy() { if (!hasScore) { double p = (0.5 + confusion.get(1, 1)) / (1 + confusion.get(0, 0) + confusion.get(1, 1)); entropy.set(0, 0, confusion.get(0, 0) * Math.log1p(-p)); entropy.set(0, 1, confusion.get(0, 1) * Math.log(p)); entropy.set(1, 0, confusion.get(1, 0) * Math.log1p(-p)); entropy.set(1, 1, confusion.get(1, 1) * Math.log(p)); } return entropy; } Auc(double threshold);  Auc(); void add(int trueValue, double score); void add(int trueValue, int predictedClass); double auc(); Matrix confusion(); Matrix entropy(); void setMaxBufferSize(int maxBufferSize); boolean isProbabilityScore(); void setProbabilityScore(boolean probabilityScore);  }
@Test public void testEntropy() { Auc auc = new Auc(); Random gen = RandomUtils.getRandom(); Normal n0 = new Normal(-1, 1, gen); Normal n1 = new Normal(1, 1, gen); for (int i=0; i<100000; i++) { double score = n0.nextDouble(); double p = n1.pdf(score) / (n0.pdf(score) + n1.pdf(score)); auc.add(0, p); score = n1.nextDouble(); p = n1.pdf(score) / (n0.pdf(score) + n1.pdf(score)); auc.add(1, p); } Matrix m = auc.entropy(); assertEquals(-0.35, m.get(0, 0), 0.02); assertEquals(-2.36, m.get(0, 1), 0.02); assertEquals(-2.36, m.get(1, 0), 0.02); assertEquals(-0.35, m.get(1, 1), 0.02); }