Accuracy implements Metric<L> { @Override public double score(Iterator<LabelPair<L>> iter) { long totalCnt = 0; long correctCnt = 0; while (iter.hasNext()) { LabelPair<L> e = iter.next(); L prediction = e.getPrediction(); L truth = e.getTruth(); if (prediction.equals(truth)) correctCnt++; totalCnt++; } return 1.0 * correctCnt / totalCnt; }  @Override double score(Iterator<LabelPair<L>> iter); @Override String name();  }
@Test public void testScore() { Metric<Integer> scoreCalculator = new Accuracy<>(); LabelPairCursor<Integer> cursor = new TestLabelPairCursor<>( Arrays.asList(1, 1, 1, 1), Arrays.asList(1, 1, 0, 1) ); double score = scoreCalculator.score(cursor.iterator()); assertEquals(0.75, score, 1e-12); }