List of usage examples for org.apache.commons.math3.linear SparseRealMatrix walkInOptimizedOrder
double walkInOptimizedOrder(RealMatrixChangingVisitor visitor);
From source file:edu.byu.nlp.crowdsourcing.ArbiterVote.java
@Override protected List<Integer> labelsForNonEmpty(SparseRealMatrix annotations) { int numAnnotations = (int) Math.round(SparseRealMatrices.sum(annotations)); if (numAnnotations == 0) { throw new IllegalStateException("Should have at least one annotation"); }/* ww w.ja v a 2s .c o m*/ if (numAnnotations > 3) { throw new IllegalStateException("There should be at most three annotations: " + annotations); } // Search for the arbiter's annotation. final Counter<Integer> numArbiterAnnotations = new DenseCounter(1); // only has one entry final MutableInteger label = Integers.MutableInteger.from(null); annotations.walkInOptimizedOrder(new AbstractRealMatrixPreservingVisitor() { @Override public void visit(int annotator, int annval, double value) { if (arbiters.contains(annotator)) { numArbiterAnnotations.incrementCount(0, 1); if (numArbiterAnnotations.getCount(0) > 1) { throw new IllegalStateException("Got more than one arbiter annotation"); } label.setValue(annval); } } }); if (label.getValue() != null) { return Collections.singletonList(label.getValue()); } // There was no arbiter, so back off to majority vote return majorityVoteDelegate.labelsFor(annotations); }