BinarizationPreprocessor implements Preprocessor<K, V>, DeployableObject { @Override public LabeledVector apply(K k, V v) { LabeledVector res = basePreprocessor.apply(k, v); for (int i = 0; i < res.size(); i++) { if (res.get(i) > threshold) res.set(i, 1.0); else res.set(i, 0.0); } return res; } BinarizationPreprocessor(double threshold, Preprocessor<K, V> basePreprocessor); @Override LabeledVector apply(K k, V v); double getThreshold(); @Override List<Object> getDependencies();  }
@Test public void testApply() { double[][] data = new double[][]{ {1, 2, 3}, {1, 4, 8}, {1, 8, 16}, }; Vectorizer<Integer, double[], Integer, Double> vectorizer = new DoubleArrayVectorizer<>(0, 1, 2); BinarizationPreprocessor<Integer, double[]> preprocessor = new BinarizationPreprocessor<>( 7, vectorizer ); double[][] postProcessedData = new double[][]{ {0, 0, 0}, {0, 0, 1}, {0, 1, 1} }; for (int i = 0; i < data.length; i++) assertArrayEquals(postProcessedData[i], preprocessor.apply(i, data[i]).features().asArray(), 1e-8); }