@Test public void testUnitScale() { val data0 = new double[] { -3.0, 6.0, 0.0 }; val scaled0 = DataUtil.unitScale(data0); assertArrayEquals(new double[] { 0.0, 1.0, 0.333 }, scaled0, TOLERANCE); val data1 = new double[] { 25.0, 50.0, 75.0, 0.0, 100.0 }; val scaled1 = DataUtil.unitScale(data1); assertArrayEquals(new double[] { 0.25, 0.50, 0.75, 0.0, 1.0 }, scaled1, TOLERANCE); }
public static double[] unitScale(double[] data) { val summaryStats = Arrays.stream(data).summaryStatistics(); val min = summaryStats.getMin(); val max = summaryStats.getMax(); val range = max - min; val denom = (range == 0.0 ? 1.0 : range); return Arrays.stream(data) .map(value -> (value - min) / denom) .toArray(); }
DataUtil { public static double[] unitScale(double[] data) { val summaryStats = Arrays.stream(data).summaryStatistics(); val min = summaryStats.getMin(); val max = summaryStats.getMax(); val range = max - min; val denom = (range == 0.0 ? 1.0 : range); return Arrays.stream(data) .map(value -> (value - min) / denom) .toArray(); } }
DataUtil { public static double[] unitScale(double[] data) { val summaryStats = Arrays.stream(data).summaryStatistics(); val min = summaryStats.getMin(); val max = summaryStats.getMax(); val range = max - min; val denom = (range == 0.0 ? 1.0 : range); return Arrays.stream(data) .map(value -> (value - min) / denom) .toArray(); }  }
DataUtil { public static double[] unitScale(double[] data) { val summaryStats = Arrays.stream(data).summaryStatistics(); val min = summaryStats.getMin(); val max = summaryStats.getMax(); val range = max - min; val denom = (range == 0.0 ? 1.0 : range); return Arrays.stream(data) .map(value -> (value - min) / denom) .toArray(); }  static double[] unitScale(double[] data); }
DataUtil { public static double[] unitScale(double[] data) { val summaryStats = Arrays.stream(data).summaryStatistics(); val min = summaryStats.getMin(); val max = summaryStats.getMax(); val range = max - min; val denom = (range == 0.0 ? 1.0 : range); return Arrays.stream(data) .map(value -> (value - min) / denom) .toArray(); }  static double[] unitScale(double[] data);  }