use of com.alibaba.alink.common.linalg.SparseVector in project Alink by alibaba.
the class VectorImputerMapperTest method testValue.
@Test
public void testValue() throws Exception {
Row[] rows = new Row[] { Row.of(0L, "{\"selectedCol\":\"\\\"vec\\\"\",\"fillValue\":\"\\\"-7.0\\\"\",\"strategy\":\"\\\"VALUE\\\"\"}", null) };
List<Row> model = Arrays.asList(rows);
TableSchema dataSchema = new TableSchema(new String[] { "vec" }, new TypeInformation<?>[] { Types.STRING });
Params params = new Params();
VectorImputerModelMapper mapper = new VectorImputerModelMapper(modelSchema, dataSchema, params);
mapper.loadModel(model);
assertEquals(mapper.map(Row.of(new SparseVector(3, new int[] { 0, 2 }, new double[] { 1.0, Double.NaN }))).getField(0), new SparseVector(3, new int[] { 0, 2 }, new double[] { 1.0, -7.0 }));
}
use of com.alibaba.alink.common.linalg.SparseVector in project Alink by alibaba.
the class VectorImputerMapperTest method testSparseMax.
@Test
public void testSparseMax() throws Exception {
Row[] rows = new Row[] { Row.of(0L, "{\"selectedCol\":\"\\\"vec\\\"\",\"strategy\":\"\\\"max\\\"\"}", null), Row.of(1048576L, "[1.3333333333333333,0.0,2.0]", null) };
List<Row> model = Arrays.asList(rows);
TableSchema dataSchema = new TableSchema(new String[] { "vec" }, new TypeInformation<?>[] { Types.STRING });
Params params = new Params();
VectorImputerModelMapper mapper = new VectorImputerModelMapper(modelSchema, dataSchema, params);
mapper.loadModel(model);
assertEquals(mapper.map(Row.of(new SparseVector(3, new int[] { 0, 2 }, new double[] { 1.0, Double.NaN }))).getField(0), new SparseVector(3, new int[] { 0, 2 }, new double[] { 1.0, 2.0 }));
}
use of com.alibaba.alink.common.linalg.SparseVector in project Alink by alibaba.
the class VectorMinMaxScalerMapperTest method testSparse.
@Test
public void testSparse() throws Exception {
Row[] rows = new Row[] { Row.of(0L, "{\"selectedCol\":\"\\\"vec\\\"\",\"min\":\"0.0\",\"max\":\"1.0\"}", null), Row.of(1048576L, "[-1.0,0,-3.0]", null), Row.of(2097152L, "[4.0,0,2.0]", null) };
List<Row> model = Arrays.asList(rows);
TableSchema dataSchema = new TableSchema(new String[] { "vec" }, new TypeInformation<?>[] { Types.STRING });
Params params = new Params();
VectorMinMaxScalerModelMapper mapper = new VectorMinMaxScalerModelMapper(modelSchema, dataSchema, params);
mapper.loadModel(model);
mapper.open();
assertEquals(mapper.map(Row.of(new SparseVector(3, new int[] { 0, 2 }, new double[] { 1.0, 2.0 }))).getField(0), new DenseVector(new double[] { 0.4, 0.5, 1.0 }));
mapper.close();
}
use of com.alibaba.alink.common.linalg.SparseVector in project Alink by alibaba.
the class VectorStandardScalerMapperTest method testSparse.
@Test
public void testSparse() throws Exception {
Row[] rows = new Row[] { Row.of(0L, "{\"withMean\":\"true\",\"selectedCol\":\"\\\"vec\\\"\",\"withStd\":\"true\"}", null), Row.of(1048576L, "[1.3333333333333333,1.0,0.3333333333333333]", null), Row.of(2097152L, "[2.5166114784235836,1.0,2.886751345948129]", null) };
List<Row> model = Arrays.asList(rows);
TableSchema dataSchema = new TableSchema(new String[] { "vec" }, new TypeInformation<?>[] { Types.STRING });
Params params = new Params();
VectorStandardScalerModelMapper mapper = new VectorStandardScalerModelMapper(modelSchema, dataSchema, params);
mapper.loadModel(model);
assertEquals(mapper.map(Row.of(new SparseVector(3, new int[] { 0, 2 }, new double[] { 1.0, 2.0 }))).getField(0), new DenseVector(new double[] { -0.13245323570650433, -1.0, 0.5773502691896257 }));
}
use of com.alibaba.alink.common.linalg.SparseVector in project Alink by alibaba.
the class OneHotModelMapperTest method testDropLast.
@Test
public void testDropLast() throws Exception {
TableSchema dataSchema = new TableSchema(new String[] { "docid", "word", "cnt" }, new TypeInformation<?>[] { Types.STRING, Types.STRING, Types.LONG });
Params params = new Params().set(OneHotPredictParams.ENCODE, HasEncodeWithoutWoe.Encode.VECTOR).set(OneHotPredictParams.SELECTED_COLS, new String[] { "cnt", "word", "docid" }).set(OneHotPredictParams.DROP_LAST, true);
OneHotModelMapper mapper = new OneHotModelMapper(modelSchema, dataSchema, params);
mapper.loadModel(model);
assertEquals(mapper.map(Row.of("doc0", "天", 4L)), Row.of(new SparseVector(4), new SparseVector(8, new int[] { 5 }, new double[] { 1.0 }), new SparseVector(6, new int[] { 2 }, new double[] { 1.0 })));
assertEquals(mapper.map(nullElseRow), Row.of(new SparseVector(4, new int[] { 2 }, new double[] { 1.0 }), new SparseVector(8, new int[] { 7 }, new double[] { 1.0 }), new SparseVector(6, new int[] { 2 }, new double[] { 1.0 })));
}
Aggregations