Search in sources :

Example 6 with TableSourceBatchOp

use of com.alibaba.alink.operator.batch.source.TableSourceBatchOp in project Alink by alibaba.

the class VectorMinMaxTest method test.

@Test
public void test() throws Exception {
    BatchOperator batchData = new TableSourceBatchOp(GenerateData.getDenseBatch());
    StreamOperator streamData = new TableSourceStreamOp(GenerateData.getDenseStream());
    VectorMinMaxScalerTrainBatchOp op = new VectorMinMaxScalerTrainBatchOp().setSelectedCol("vec").linkFrom(batchData);
    List<Row> rows = new VectorMinMaxScalerPredictBatchOp().linkFrom(op, batchData).collect();
    assertEquals(rows.get(0).getField(0), new DenseVector(new double[] { 0.4, 1.0 }));
    assertEquals(rows.get(1), Row.of(new DenseVector(new double[] { 0., 0.0 })));
    assertEquals(rows.get(2), Row.of(new DenseVector(new double[] { 1.0, 1.0 })));
    new VectorMinMaxScalerPredictStreamOp(op).linkFrom(streamData).print();
    StreamOperator.execute();
}
Also used : VectorMinMaxScalerPredictStreamOp(com.alibaba.alink.operator.stream.dataproc.vector.VectorMinMaxScalerPredictStreamOp) TableSourceStreamOp(com.alibaba.alink.operator.stream.source.TableSourceStreamOp) Row(org.apache.flink.types.Row) TableSourceBatchOp(com.alibaba.alink.operator.batch.source.TableSourceBatchOp) StreamOperator(com.alibaba.alink.operator.stream.StreamOperator) BatchOperator(com.alibaba.alink.operator.batch.BatchOperator) DenseVector(com.alibaba.alink.common.linalg.DenseVector) Test(org.junit.Test)

Example 7 with TableSourceBatchOp

use of com.alibaba.alink.operator.batch.source.TableSourceBatchOp in project Alink by alibaba.

the class VectorMinMaxTest method testModelInfo.

@Test
public void testModelInfo() {
    BatchOperator batchData = new TableSourceBatchOp(GenerateData.getDenseBatch());
    VectorMinMaxScalerTrainBatchOp trainOp = new VectorMinMaxScalerTrainBatchOp().setSelectedCol("vec").linkFrom(batchData);
    VectorMinMaxScalerModelInfo modelInfo = trainOp.getModelInfoBatchOp().collectModelInfo();
    System.out.println(modelInfo.getMaxs().length);
    System.out.println(modelInfo.getMins().length);
    System.out.println(modelInfo.toString());
}
Also used : TableSourceBatchOp(com.alibaba.alink.operator.batch.source.TableSourceBatchOp) BatchOperator(com.alibaba.alink.operator.batch.BatchOperator) VectorMinMaxScalerModelInfo(com.alibaba.alink.operator.common.dataproc.vector.VectorMinMaxScalerModelInfo) Test(org.junit.Test)

Example 8 with TableSourceBatchOp

use of com.alibaba.alink.operator.batch.source.TableSourceBatchOp in project Alink by alibaba.

the class SampleBatchOpTest method test.

@Test
public void test() throws Exception {
    TableSourceBatchOp tableSourceBatchOp = new TableSourceBatchOp(getBatchTable());
    long cnt = tableSourceBatchOp.link(new SampleBatchOp(0.5, false)).count();
    assert cnt >= 0 && cnt <= 10;
}
Also used : TableSourceBatchOp(com.alibaba.alink.operator.batch.source.TableSourceBatchOp) Test(org.junit.Test)

Example 9 with TableSourceBatchOp

use of com.alibaba.alink.operator.batch.source.TableSourceBatchOp in project Alink by alibaba.

the class SqliteCatalogTest method sinkBatch.

@Test
public void sinkBatch() throws Exception {
    Row[] rows = new Row[] { Row.of(new byte[] { 0, 1 }, new BigDecimal("0.00"), (byte) 0, (short) 0, 0, 0.0f, 0.0, 0, new Date(0), new Time(0), new Timestamp(0), "string", "string", new byte[] { 0, 1 }, "s", new byte[] { 0, 1 }, false, 0L) };
    MemSourceBatchOp memSourceBatchOp = new MemSourceBatchOp(Arrays.asList(rows), new TableSchema(new String[] { "col_bit", "col_decimal", "col_tinyint", "col_smallint", "col_int", "col_float", "col_double", "col_mediumint", "col_date", "col_time", "col_timestamp", "col_text", "col_varchar", "col_varbinary", "col_char", "col_binary", "col_boolean", "col_long" }, new TypeInformation<?>[] { Types.PRIMITIVE_ARRAY(Types.BYTE), Types.BIG_DEC, Types.BYTE, Types.SHORT, Types.INT, Types.FLOAT, Types.DOUBLE, Types.INT, Types.SQL_DATE, Types.SQL_TIME, Types.SQL_TIMESTAMP, Types.STRING, Types.STRING, Types.PRIMITIVE_ARRAY(Types.BYTE), Types.STRING, Types.PRIMITIVE_ARRAY(Types.BYTE), Types.BOOLEAN, Types.LONG }));
    sqlite.sinkBatch(new ObjectPath(SQLITE_DB, SQLITE_DB_TABLE_1), memSourceBatchOp.getOutputTable(), new Params().set(HasOverwriteSink.OVERWRITE_SINK, true), memSourceBatchOp.getMLEnvironmentId());
    BatchOperator.execute();
    Assert.assertFalse(new TableSourceBatchOp(sqlite.sourceBatch(new ObjectPath(SQLITE_DB, SQLITE_DB_TABLE_1), new Params(), MLEnvironmentFactory.DEFAULT_ML_ENVIRONMENT_ID)).collect().isEmpty());
}
Also used : ObjectPath(org.apache.flink.table.catalog.ObjectPath) TableSchema(org.apache.flink.table.api.TableSchema) Params(org.apache.flink.ml.api.misc.param.Params) Time(java.sql.Time) Timestamp(java.sql.Timestamp) TableSourceBatchOp(com.alibaba.alink.operator.batch.source.TableSourceBatchOp) BigDecimal(java.math.BigDecimal) Date(java.sql.Date) TypeInformation(org.apache.flink.api.common.typeinfo.TypeInformation) MemSourceBatchOp(com.alibaba.alink.operator.batch.source.MemSourceBatchOp) Row(org.apache.flink.types.Row) Test(org.junit.Test)

Example 10 with TableSourceBatchOp

use of com.alibaba.alink.operator.batch.source.TableSourceBatchOp in project Alink by alibaba.

the class IsotonicRegressionTest method testIsotonicReg.

@Test
public void testIsotonicReg() throws Exception {
    Table data = MLEnvironmentFactory.getDefault().createBatchTable(rows, new String[] { "id", "feature", "label" });
    Table dataStream = MLEnvironmentFactory.getDefault().createStreamTable(rows, new String[] { "id", "feature", "label" });
    IsotonicRegression op = new IsotonicRegression().setFeatureCol("feature").setLabelCol("label").setPredictionCol("result");
    PipelineModel model = new Pipeline().add(op).fit(data);
    BatchOperator<?> res = model.transform(new TableSourceBatchOp(data));
    List<Row> list = res.select(new String[] { "id", "result" }).collect();
    double[] actual = new double[] { 0.66, 0.75, 0.75, 0.75, 0.5, 0.5, 0.75, 0.66, 0.66, 0.75, 0.5, 0.5, 0.5, 0.5, 0.75 };
    for (int i = 0; i < actual.length; i++) {
        Assert.assertEquals((Double) list.get(i).getField(1), actual[(int) list.get(i).getField(0)], 0.01);
    }
// StreamOperator<?> resStream = model.transform(new TableSourceStreamOp(dataStream));
// resStream.print();
// MLEnvironmentFactory.getDefault().getStreamExecutionEnvironment().execute();
}
Also used : Table(org.apache.flink.table.api.Table) Row(org.apache.flink.types.Row) TableSourceBatchOp(com.alibaba.alink.operator.batch.source.TableSourceBatchOp) PipelineModel(com.alibaba.alink.pipeline.PipelineModel) Pipeline(com.alibaba.alink.pipeline.Pipeline) Test(org.junit.Test)

Aggregations

TableSourceBatchOp (com.alibaba.alink.operator.batch.source.TableSourceBatchOp)39 Row (org.apache.flink.types.Row)29 BatchOperator (com.alibaba.alink.operator.batch.BatchOperator)22 Test (org.junit.Test)18 TypeInformation (org.apache.flink.api.common.typeinfo.TypeInformation)12 TableSourceStreamOp (com.alibaba.alink.operator.stream.source.TableSourceStreamOp)10 Params (org.apache.flink.ml.api.misc.param.Params)10 List (java.util.List)8 Tuple2 (org.apache.flink.api.java.tuple.Tuple2)8 StreamOperator (com.alibaba.alink.operator.stream.StreamOperator)6 ArrayList (java.util.ArrayList)6 TableSchema (org.apache.flink.table.api.TableSchema)6 MemSourceBatchOp (com.alibaba.alink.operator.batch.source.MemSourceBatchOp)5 Comparator (java.util.Comparator)4 HashMap (java.util.HashMap)4 MapFunction (org.apache.flink.api.common.functions.MapFunction)4 DataSet (org.apache.flink.api.java.DataSet)4 Mapper (com.alibaba.alink.common.mapper.Mapper)3 ModelMapper (com.alibaba.alink.common.mapper.ModelMapper)3 PipelineModelMapper (com.alibaba.alink.common.mapper.PipelineModelMapper)3