test_class.file: modules/ml/src/test/java/org/apache/ignite/ml/preprocessing/maxabsscaling/MaxAbsScalerTrainerTest.java
test_class.identifier: MaxAbsScalerTrainerTest
test_class.superclass: extends TrainerTest
test_case.body: @Test
      public void testFit() {
          Map<Integer, Vector> data = new HashMap<>();
          data.put(1, VectorUtils.of(2, -4, 1));
          data.put(2, VectorUtils.of(1, -8, 22));
          data.put(3, VectorUtils.of(-4, 10, 100));
          data.put(4, VectorUtils.of(0, 22, 300));
  
          DatasetBuilder<Integer, Vector> datasetBuilder = new LocalDatasetBuilder<>(data, parts);
  
          final Vectorizer<Integer, Vector, Integer, Double> vectorizer = new DummyVectorizer<>(0, 1, 2);
  
          MaxAbsScalerTrainer<Integer, Vector> standardizationTrainer = new MaxAbsScalerTrainer<>();
  
          MaxAbsScalerPreprocessor<Integer, Vector> preprocessor = standardizationTrainer.fit(
              TestUtils.testEnvBuilder(),
              datasetBuilder,
              vectorizer
          );
  
          assertArrayEquals(new double[] {4, 22, 300}, preprocessor.getMaxAbs(), 1e-8);
      }
test_case.class_method_signature: MaxAbsScalerTrainerTest.testFit()
test_case.full_signature: @Test public void testFit()
test_case.identifier: testFit
test_case.invocations: put of put of put of put of fit testEnvBuilder assertArrayEquals getMaxAbs
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void testFit()
focal_class.file: modules/ml/src/main/java/org/apache/ignite/ml/preprocessing/maxabsscaling/MaxAbsScalerTrainer.java
focal_class.identifier: MaxAbsScalerTrainer
focal_class.interfaces: implements PreprocessingTrainer<K, V>
focal_class.class_method_signature: MaxAbsScalerTrainer.fit(
          LearningEnvironmentBuilder envBuilder,
          DatasetBuilder<K, V> datasetBuilder,
          Preprocessor<K, V> basePreprocessor)
focal_class.full_signature: @Override public MaxAbsScalerPreprocessor<K, V> fit(
          LearningEnvironmentBuilder envBuilder,
          DatasetBuilder<K, V> datasetBuilder,
          Preprocessor<K, V> basePreprocessor)
focal_class.identifier: fit
focal_class.modifiers: @Override public
focal_class.parameters: (
          LearningEnvironmentBuilder envBuilder,
          DatasetBuilder<K, V> datasetBuilder,
          Preprocessor<K, V> basePreprocessor)
focal_class.return: MaxAbsScalerPreprocessor<K, V>
focal_class.signature: MaxAbsScalerPreprocessor<K, V> fit(
          LearningEnvironmentBuilder envBuilder,
          DatasetBuilder<K, V> datasetBuilder,
          Preprocessor<K, V> basePreprocessor)
focal_method.body: @Override public MaxAbsScalerPreprocessor<K, V> fit(
          LearningEnvironmentBuilder envBuilder,
          DatasetBuilder<K, V> datasetBuilder,
          Preprocessor<K, V> basePreprocessor) {
          try (Dataset<EmptyContext, MaxAbsScalerPartitionData> dataset = datasetBuilder.build(
              envBuilder,
              (env, upstream, upstreamSize) -> new EmptyContext(),
              (env, upstream, upstreamSize, ctx) -> {
                  double[] maxAbs = null;
  
                  while (upstream.hasNext()) {
                      UpstreamEntry<K, V> entity = upstream.next();
                      LabeledVector row = basePreprocessor.apply(entity.getKey(), entity.getValue());
  
                      if (maxAbs == null) {
                          maxAbs = new double[row.size()];
                          for (int i = 0; i < maxAbs.length; i++)
                              maxAbs[i] = .0;
                      }
                      else
                          assert maxAbs.length == row.size() : "Base preprocessor must return exactly " + maxAbs.length
                              + " features";
  
                      for (int i = 0; i < row.size(); i++) {
                          if (Math.abs(row.get(i)) > Math.abs(maxAbs[i]))
                              maxAbs[i] = Math.abs(row.get(i));
                      }
                  }
                  return new MaxAbsScalerPartitionData(maxAbs);
              }, learningEnvironment(basePreprocessor)
          )) {
              double[] maxAbs = dataset.compute(MaxAbsScalerPartitionData::getMaxAbs,
                  (a, b) -> {
                      if (a == null)
                          return b;
  
                      if (b == null)
                          return a;
  
                      double[] res = new double[a.length];
  
                      for (int i = 0; i < res.length; i++)
                          res[i] = Math.max(Math.abs(a[i]), Math.abs(b[i]));
  
                      return res;
                  });
              return new MaxAbsScalerPreprocessor<>(maxAbs, basePreprocessor);
          }
          catch (Exception e) {
              throw new RuntimeException(e);
          }
      }
focal_method.class_method_signature: MaxAbsScalerTrainer.fit(
          LearningEnvironmentBuilder envBuilder,
          DatasetBuilder<K, V> datasetBuilder,
          Preprocessor<K, V> basePreprocessor)
focal_method.full_signature: @Override public MaxAbsScalerPreprocessor<K, V> fit(
          LearningEnvironmentBuilder envBuilder,
          DatasetBuilder<K, V> datasetBuilder,
          Preprocessor<K, V> basePreprocessor)
focal_method.identifier: fit
focal_method.invocations: build hasNext next apply getKey getValue size size size abs get abs abs get learningEnvironment compute max abs abs
focal_method.modifiers: @Override public
focal_method.parameters: (
          LearningEnvironmentBuilder envBuilder,
          DatasetBuilder<K, V> datasetBuilder,
          Preprocessor<K, V> basePreprocessor)
focal_method.return: MaxAbsScalerPreprocessor<K, V>
focal_method.signature: MaxAbsScalerPreprocessor<K, V> fit(
          LearningEnvironmentBuilder envBuilder,
          DatasetBuilder<K, V> datasetBuilder,
          Preprocessor<K, V> basePreprocessor)