@Test public void testApplyDivisionByZero() { double[][] data = new double[][]{{1.}, {1.}, {1.}, {1.}}; MinMaxScalerPreprocessor<Integer, double[]> preprocessor = new MinMaxScalerPreprocessor<>( new double[] {1.}, new double[] {1.}, new DoubleArrayVectorizer<>(0) ); double[][] standardData = new double[][]{{0.}, {0.}, {0.}, {0.}}; for (int i = 0; i < data.length; i++) assertArrayEquals(standardData[i], preprocessor.apply(i, data[i]).features().asArray(), 1e-8); }
@Override public LabeledVector apply(K k, V v) { LabeledVector res = basePreprocessor.apply(k, v); assert res.size() == min.length; assert res.size() == max.length; for (int i = 0; i < res.size(); i++) { double num = res.get(i) - min[i]; double denom = max[i] - min[i]; double scaled = num / denom; if (Double.isNaN(scaled)) res.set(i, num); else res.set(i, scaled); } return res; }
MinMaxScalerPreprocessor implements Preprocessor<K, V>, DeployableObject { @Override public LabeledVector apply(K k, V v) { LabeledVector res = basePreprocessor.apply(k, v); assert res.size() == min.length; assert res.size() == max.length; for (int i = 0; i < res.size(); i++) { double num = res.get(i) - min[i]; double denom = max[i] - min[i]; double scaled = num / denom; if (Double.isNaN(scaled)) res.set(i, num); else res.set(i, scaled); } return res; } }
MinMaxScalerPreprocessor implements Preprocessor<K, V>, DeployableObject { @Override public LabeledVector apply(K k, V v) { LabeledVector res = basePreprocessor.apply(k, v); assert res.size() == min.length; assert res.size() == max.length; for (int i = 0; i < res.size(); i++) { double num = res.get(i) - min[i]; double denom = max[i] - min[i]; double scaled = num / denom; if (Double.isNaN(scaled)) res.set(i, num); else res.set(i, scaled); } return res; } MinMaxScalerPreprocessor(double[] min, double[] max, Preprocessor<K, V> basePreprocessor); }
MinMaxScalerPreprocessor implements Preprocessor<K, V>, DeployableObject { @Override public LabeledVector apply(K k, V v) { LabeledVector res = basePreprocessor.apply(k, v); assert res.size() == min.length; assert res.size() == max.length; for (int i = 0; i < res.size(); i++) { double num = res.get(i) - min[i]; double denom = max[i] - min[i]; double scaled = num / denom; if (Double.isNaN(scaled)) res.set(i, num); else res.set(i, scaled); } return res; } MinMaxScalerPreprocessor(double[] min, double[] max, Preprocessor<K, V> basePreprocessor); @Override LabeledVector apply(K k, V v); double[] getMin(); double[] getMax(); @Override List<Object> getDependencies(); }
MinMaxScalerPreprocessor implements Preprocessor<K, V>, DeployableObject { @Override public LabeledVector apply(K k, V v) { LabeledVector res = basePreprocessor.apply(k, v); assert res.size() == min.length; assert res.size() == max.length; for (int i = 0; i < res.size(); i++) { double num = res.get(i) - min[i]; double denom = max[i] - min[i]; double scaled = num / denom; if (Double.isNaN(scaled)) res.set(i, num); else res.set(i, scaled); } return res; } MinMaxScalerPreprocessor(double[] min, double[] max, Preprocessor<K, V> basePreprocessor); @Override LabeledVector apply(K k, V v); double[] getMin(); double[] getMax(); @Override List<Object> getDependencies();  }