public double calculateError(DoubleVector y, DoubleVector hypothesis) {
double sum = 0d;
TIntHashSet visitedColumns = new TIntHashSet(y.getLength());
Iterator<DoubleVectorElement> iterateNonZero = hypothesis.iterateNonZero();
while (iterateNonZero.hasNext()) {
DoubleVectorElement next = iterateNonZero.next();
visitedColumns.add(next.getIndex());
if (next.getValue() > activationThreshold ^ y.get(next.getIndex()) == 1d) {
sum += 1d;
}
}
iterateNonZero = y.iterateNonZero();
while (iterateNonZero.hasNext()) {
DoubleVectorElement next = iterateNonZero.next();
if (!visitedColumns.contains(next.getIndex())) {
visitedColumns.add(next.getIndex());
if (hypothesis.get(next.getIndex()) > activationThreshold
^ next.getValue() == 1d) {
sum += 1d;
}
}
}
return sum / visitedColumns.size();