Source:
private TargetCounter[] updateTargetCountersForNextRow(LabeledVector row, TargetCounter[] targetCounters) { if (targetCounters == null) targetCounters = initializeTargetCounters(row); else assert targetCounters.length == row.size() : "Base preprocessor must return exactly " + targetCounters.length + " features"; double targetValue = row.features().get(targetLabelIndex); for (int i = 0; i < targetCounters.length; i++) { if (handledIndices.contains(i)) { String strVal; Object featureVal = row.features().getRaw(i); if (featureVal.equals(Double.NaN)) { strVal = EncoderPreprocessor.KEY_FOR_NULL_VALUES; row.features().setRaw(i, strVal); } else if (featureVal instanceof String) strVal = (String)featureVal; else if (featureVal instanceof Double) strVal = String.valueOf(featureVal); else throw new RuntimeException("The type " + featureVal.getClass() + " is not supported for the feature values."); TargetCounter targetCounter = targetCounters[i]; targetCounter.setTargetCount(targetCounter.getTargetCount() + 1); targetCounter.setTargetSum(targetCounter.getTargetSum() + targetValue); Map<String, Long> categoryCounts = targetCounter.getCategoryCounts(); if (categoryCounts.containsKey(strVal)) { categoryCounts.put(strVal, categoryCounts.get(strVal) + 1); } else { categoryCounts.put(strVal, 1L); } Map<String, Double> categoryTargetSum = targetCounter.getCategoryTargetSum(); if (categoryTargetSum.containsKey(strVal)) { categoryTargetSum.put(strVal, categoryTargetSum.get(strVal) + targetValue); } else { categoryTargetSum.put(strVal, targetValue); } } } return targetCounters; }

Target:
private TargetCounter[] updateTargetCountersForNextRow(LabeledVector row, TargetCounter[] targetCounters) { if (targetCounters == null) targetCounters = initializeTargetCounters(row); else assert targetCounters.length == row.size() : "Base preprocessor must return exactly " + targetCounters.length + " features"; double targetValue = row.features().get(targetLabelIndex); for (int i = 0; i < targetCounters.length; i++) { if (handledIndices.contains(i)) { String strVal; Object featureVal = row.features().getRaw(i); if (featureVal.equals(Double.NaN)) { strVal = EncoderPreprocessor.KEY_FOR_NULL_VALUES; row.features().setRaw(i, strVal); } else if (featureVal instanceof String) strVal = (String)featureVal; else if (featureVal instanceof Number) strVal = String.valueOf(featureVal); else if (featureVal instanceof Boolean) strVal = String.valueOf(featureVal); else throw new RuntimeException("The type " + featureVal.getClass() + " is not supported for the feature values."); TargetCounter targetCounter = targetCounters[i]; targetCounter.setTargetCount(targetCounter.getTargetCount() + 1); targetCounter.setTargetSum(targetCounter.getTargetSum() + targetValue); Map<String, Long> categoryCounts = targetCounter.getCategoryCounts(); if (categoryCounts.containsKey(strVal)) { categoryCounts.put(strVal, categoryCounts.get(strVal) + 1); } else { categoryCounts.put(strVal, 1L); } Map<String, Double> categoryTargetSum = targetCounter.getCategoryTargetSum(); if (categoryTargetSum.containsKey(strVal)) { categoryTargetSum.put(strVal, categoryTargetSum.get(strVal) + targetValue); } else { categoryTargetSum.put(strVal, targetValue); } } } return targetCounters; }