IGNITE-8907: [ML] Using vectors in featureExtractor
[ignite.git] / modules / ml / src / test / java / org / apache / ignite / ml / preprocessing / binarization / BinarizationPreprocessorTest.java
1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18 package org.apache.ignite.ml.preprocessing.binarization;
19
20 import org.apache.ignite.ml.math.VectorUtils;
21 import org.junit.Test;
22
23 import static org.junit.Assert.assertArrayEquals;
24
25 /**
26 * Tests for {@link BinarizationPreprocessor}.
27 */
28 public class BinarizationPreprocessorTest {
29 /** Tests {@code apply()} method. */
30 @Test
31 public void testApply() {
32 double[][] data = new double[][]{
33 {1, 2, 3},
34 {1, 4, 8},
35 {1, 8, 16},
36 };
37
38 BinarizationPreprocessor<Integer, double[]> preprocessor = new BinarizationPreprocessor<>(
39 7,
40 (k, v) -> VectorUtils.of(v)
41 );
42
43 double[][] postProcessedData = new double[][]{
44 {0, 0, 0},
45 {0, 0, 1},
46 {0, 1, 1}
47 };
48
49 for (int i = 0; i < data.length; i++)
50 assertArrayEquals(postProcessedData[i], preprocessor.apply(i, data[i]).asArray(), 1e-8);
51 }
52 }