@Test void evaluate() throws EvaluationException { Tensor tensor = Tensor.fromData(DataType.FLOAT, new Float[]{null, 17.0F, 27.5F}); TensorIO input = new TensorIO(Map.of("value", tensor)); TensorIO io = standardScaler.evaluate(input, new EvaluationContext()); assertEquals(3, io.getBatchSize()); assertEquals(Set.of("scaled_value"), io.tensorsNames()); assertArrayEquals(new Double[]{null, 5.0, 10.25}, (Double[]) io.getTensor("scaled_value").getData()); tensor = Tensor.fromData(DataType.INTEGER, new Integer[]{null, 17, 27}); input = new TensorIO(Map.of("value", tensor)); io = standardScaler.evaluate(input, new EvaluationContext()); assertEquals(3, io.getBatchSize()); assertEquals(Set.of("scaled_value"), io.tensorsNames()); assertArrayEquals(new Double[]{null, 5.0, 10.0}, (Double[]) io.getTensor("scaled_value").getData()); }
@Override public TensorIO evaluate(TensorIO io, EvaluationContext evaluationContext) throws EvaluationException { Table table = io.intoTable(); TableUtils.allFieldPresentAndCompatible(table, inputs); Map<String, Tensor> output = new HashMap<>(); IntStream.range(0, getInputs().size()).boxed().forEach(index -> { String inputName = inputs.get(index).getName(); String outputName = outputs.get(index).getName(); NumberColumn numberColumn = TableUtils.getNumberColumn(inputName, table).get(); MeanStd meanStd = meanStdMap.get(inputName); Column<?> newColumn = numberColumn .subtract(meanStd.getMean()) .divide(meanStd.getStd()) .setName(outputName); Tensor columnTensor = Tensor.fromData(DataType.DOUBLE, newColumn.asObjectArray()); output.put(newColumn.name(), columnTensor); }); evaluationContext.incEvaluation(); return new TensorIO(output); }
StandardScaler implements Evaluator { @Override public TensorIO evaluate(TensorIO io, EvaluationContext evaluationContext) throws EvaluationException { Table table = io.intoTable(); TableUtils.allFieldPresentAndCompatible(table, inputs); Map<String, Tensor> output = new HashMap<>(); IntStream.range(0, getInputs().size()).boxed().forEach(index -> { String inputName = inputs.get(index).getName(); String outputName = outputs.get(index).getName(); NumberColumn numberColumn = TableUtils.getNumberColumn(inputName, table).get(); MeanStd meanStd = meanStdMap.get(inputName); Column<?> newColumn = numberColumn .subtract(meanStd.getMean()) .divide(meanStd.getStd()) .setName(outputName); Tensor columnTensor = Tensor.fromData(DataType.DOUBLE, newColumn.asObjectArray()); output.put(newColumn.name(), columnTensor); }); evaluationContext.incEvaluation(); return new TensorIO(output); } }
StandardScaler implements Evaluator { @Override public TensorIO evaluate(TensorIO io, EvaluationContext evaluationContext) throws EvaluationException { Table table = io.intoTable(); TableUtils.allFieldPresentAndCompatible(table, inputs); Map<String, Tensor> output = new HashMap<>(); IntStream.range(0, getInputs().size()).boxed().forEach(index -> { String inputName = inputs.get(index).getName(); String outputName = outputs.get(index).getName(); NumberColumn numberColumn = TableUtils.getNumberColumn(inputName, table).get(); MeanStd meanStd = meanStdMap.get(inputName); Column<?> newColumn = numberColumn .subtract(meanStd.getMean()) .divide(meanStd.getStd()) .setName(outputName); Tensor columnTensor = Tensor.fromData(DataType.DOUBLE, newColumn.asObjectArray()); output.put(newColumn.name(), columnTensor); }); evaluationContext.incEvaluation(); return new TensorIO(output); } StandardScaler(List<Field> inputs, List<Field> outputs, Map<String, MeanStd> meanStdMap); }
StandardScaler implements Evaluator { @Override public TensorIO evaluate(TensorIO io, EvaluationContext evaluationContext) throws EvaluationException { Table table = io.intoTable(); TableUtils.allFieldPresentAndCompatible(table, inputs); Map<String, Tensor> output = new HashMap<>(); IntStream.range(0, getInputs().size()).boxed().forEach(index -> { String inputName = inputs.get(index).getName(); String outputName = outputs.get(index).getName(); NumberColumn numberColumn = TableUtils.getNumberColumn(inputName, table).get(); MeanStd meanStd = meanStdMap.get(inputName); Column<?> newColumn = numberColumn .subtract(meanStd.getMean()) .divide(meanStd.getStd()) .setName(outputName); Tensor columnTensor = Tensor.fromData(DataType.DOUBLE, newColumn.asObjectArray()); output.put(newColumn.name(), columnTensor); }); evaluationContext.incEvaluation(); return new TensorIO(output); } StandardScaler(List<Field> inputs, List<Field> outputs, Map<String, MeanStd> meanStdMap); static StandardScaler create(StandardScalerManifest manifest, String path); @Override TensorIO evaluate(TensorIO io, EvaluationContext evaluationContext); @Override List<Field> getInputs(); @Override List<Field> getOutputs(); }
StandardScaler implements Evaluator { @Override public TensorIO evaluate(TensorIO io, EvaluationContext evaluationContext) throws EvaluationException { Table table = io.intoTable(); TableUtils.allFieldPresentAndCompatible(table, inputs); Map<String, Tensor> output = new HashMap<>(); IntStream.range(0, getInputs().size()).boxed().forEach(index -> { String inputName = inputs.get(index).getName(); String outputName = outputs.get(index).getName(); NumberColumn numberColumn = TableUtils.getNumberColumn(inputName, table).get(); MeanStd meanStd = meanStdMap.get(inputName); Column<?> newColumn = numberColumn .subtract(meanStd.getMean()) .divide(meanStd.getStd()) .setName(outputName); Tensor columnTensor = Tensor.fromData(DataType.DOUBLE, newColumn.asObjectArray()); output.put(newColumn.name(), columnTensor); }); evaluationContext.incEvaluation(); return new TensorIO(output); } StandardScaler(List<Field> inputs, List<Field> outputs, Map<String, MeanStd> meanStdMap); static StandardScaler create(StandardScalerManifest manifest, String path); @Override TensorIO evaluate(TensorIO io, EvaluationContext evaluationContext); @Override List<Field> getInputs(); @Override List<Field> getOutputs();  }