Search in sources :

Example 1 with LSTNetPredictStreamOp

use of com.alibaba.alink.operator.stream.timeseries.LSTNetPredictStreamOp in project Alink by alibaba.

the class LSTNetPredictStreamOpTest method testLSTNetTrainBatchOp.

@Test
public void testLSTNetTrainBatchOp() throws Exception {
    BatchOperator.setParallelism(1);
    List<Row> data = Arrays.asList(Row.of(0, Timestamp.valueOf("2021-11-01 00:00:00"), 100.0), Row.of(0, Timestamp.valueOf("2021-11-02 00:00:00"), 200.0), Row.of(0, Timestamp.valueOf("2021-11-03 00:00:00"), 300.0), Row.of(0, Timestamp.valueOf("2021-11-04 00:00:00"), 400.0), Row.of(0, Timestamp.valueOf("2021-11-06 00:00:00"), 500.0), Row.of(0, Timestamp.valueOf("2021-11-07 00:00:00"), 600.0), Row.of(0, Timestamp.valueOf("2021-11-08 00:00:00"), 700.0), Row.of(0, Timestamp.valueOf("2021-11-09 00:00:00"), 800.0), Row.of(0, Timestamp.valueOf("2021-11-10 00:00:00"), 900.0), Row.of(0, Timestamp.valueOf("2021-11-11 00:00:00"), 800.0), Row.of(0, Timestamp.valueOf("2021-11-12 00:00:00"), 700.0), Row.of(0, Timestamp.valueOf("2021-11-13 00:00:00"), 600.0), Row.of(0, Timestamp.valueOf("2021-11-14 00:00:00"), 500.0), Row.of(0, Timestamp.valueOf("2021-11-15 00:00:00"), 400.0), Row.of(0, Timestamp.valueOf("2021-11-16 00:00:00"), 300.0), Row.of(0, Timestamp.valueOf("2021-11-17 00:00:00"), 200.0), Row.of(0, Timestamp.valueOf("2021-11-18 00:00:00"), 100.0), Row.of(0, Timestamp.valueOf("2021-11-19 00:00:00"), 200.0), Row.of(0, Timestamp.valueOf("2021-11-20 00:00:00"), 300.0), Row.of(0, Timestamp.valueOf("2021-11-21 00:00:00"), 400.0), Row.of(0, Timestamp.valueOf("2021-11-22 00:00:00"), 500.0), Row.of(0, Timestamp.valueOf("2021-11-23 00:00:00"), 600.0), Row.of(0, Timestamp.valueOf("2021-11-24 00:00:00"), 700.0), Row.of(0, Timestamp.valueOf("2021-11-25 00:00:00"), 800.0), Row.of(0, Timestamp.valueOf("2021-11-26 00:00:00"), 900.0), Row.of(0, Timestamp.valueOf("2021-11-27 00:00:00"), 800.0), Row.of(0, Timestamp.valueOf("2021-11-28 00:00:00"), 700.0), Row.of(0, Timestamp.valueOf("2021-11-29 00:00:00"), 600.0), Row.of(0, Timestamp.valueOf("2021-11-30 00:00:00"), 500.0), Row.of(0, Timestamp.valueOf("2021-12-01 00:00:00"), 400.0), Row.of(0, Timestamp.valueOf("2021-12-02 00:00:00"), 300.0), Row.of(0, Timestamp.valueOf("2021-12-03 00:00:00"), 200.0));
    MemSourceBatchOp memSourceBatchOp = new MemSourceBatchOp(data, "id int, ts timestamp, series double");
    MemSourceStreamOp memSourceStreamOp = new MemSourceStreamOp(data, "id int, ts timestamp, series double");
    LSTNetTrainBatchOp lstNetTrainBatchOp = new LSTNetTrainBatchOp().setTimeCol("ts").setSelectedCol("series").setNumEpochs(10).setWindow(24).setHorizon(1).linkFrom(memSourceBatchOp);
    OverCountWindowStreamOp overCountWindowStreamOp = new OverCountWindowStreamOp().setClause("MTABLE_AGG_PRECEDING(ts, series) as mtable_agg_series").setTimeCol("ts").setPrecedingRows(24);
    LSTNetPredictStreamOp lstNetPredictStreamOp = new LSTNetPredictStreamOp(lstNetTrainBatchOp).setPredictNum(1).setPredictionCol("pred").setReservedCols().setValueCol("mtable_agg_series");
    lstNetPredictStreamOp.linkFrom(overCountWindowStreamOp.linkFrom(memSourceStreamOp).filter("ts = TO_TIMESTAMP('2021-12-03 00:00:00')")).print();
    StreamOperator.execute();
}
Also used : MemSourceBatchOp(com.alibaba.alink.operator.batch.source.MemSourceBatchOp) MemSourceStreamOp(com.alibaba.alink.operator.stream.source.MemSourceStreamOp) OverCountWindowStreamOp(com.alibaba.alink.operator.stream.feature.OverCountWindowStreamOp) Row(org.apache.flink.types.Row) LSTNetPredictStreamOp(com.alibaba.alink.operator.stream.timeseries.LSTNetPredictStreamOp) Test(org.junit.Test)

Example 2 with LSTNetPredictStreamOp

use of com.alibaba.alink.operator.stream.timeseries.LSTNetPredictStreamOp in project Alink by alibaba.

the class LSTNetTrainBatchOpTest method testStreamMultiVar.

@Test
public void testStreamMultiVar() throws Exception {
    BatchOperator.setParallelism(1);
    final int numCols = 10;
    final String timeColName = "ts";
    final String vecColName = "vec";
    final String selectClause = "TO_TIMESTAMP(" + timeColName + ") as " + timeColName + ", " + vecColName;
    BatchOperator<?> source = new RandomTableSourceBatchOp().setNumRows(1000L).setNumCols(numCols);
    String[] selectedColNames = source.getColNames();
    AppendIdBatchOp appendIdBatchOp = new AppendIdBatchOp().setIdCol(timeColName).linkFrom(source);
    ColumnsToVectorBatchOp columnsToVectorBatchOp = new ColumnsToVectorBatchOp().setSelectedCols(selectedColNames).setVectorCol(vecColName).linkFrom(appendIdBatchOp);
    BatchOperator<?> timeBatchOp = new SelectBatchOp().setClause(selectClause).linkFrom(columnsToVectorBatchOp);
    LSTNetTrainBatchOp trainOp = new LSTNetTrainBatchOp().setVectorCol(vecColName).setTimeCol(timeColName).setWindow(24 * 7).setHorizon(12).setNumEpochs(1).linkFrom(timeBatchOp);
    StreamOperator<?> sourceStreamOp = new RandomTableSourceStreamOp().setNumCols(numCols).setMaxRows(1000L);
    ColumnsToVectorStreamOp columnsToVectorStreamOp = new ColumnsToVectorStreamOp().setSelectedCols(selectedColNames).setVectorCol(vecColName).linkFrom(sourceStreamOp);
    AppendIdStreamOp appendIdStreamOp = new AppendIdStreamOp().setIdCol(timeColName).linkFrom(columnsToVectorStreamOp);
    StreamOperator<?> timestampStreamOp = new SelectStreamOp().setClause(selectClause).linkFrom(appendIdStreamOp);
    OverCountWindowStreamOp overCountWindowStreamOp = new OverCountWindowStreamOp().setClause("MTABLE_AGG_PRECEDING(" + timeColName + ", " + vecColName + ") as col_agg").setTimeCol(timeColName).setPrecedingRows(24 * 7).linkFrom(timestampStreamOp);
    LSTNetPredictStreamOp predictStreamOp = new LSTNetPredictStreamOp(trainOp).setValueCol("col_agg").setPredictionCol("pred").setReservedCols(timeColName).linkFrom(overCountWindowStreamOp);
    FilePath tmpAkFile = new FilePath(new Path(folder.getRoot().getPath(), "lstnet_test_stream_multi_var_result.ak"));
    predictStreamOp.link(new AkSinkStreamOp().setOverwriteSink(true).setFilePath(tmpAkFile));
    StreamOperator.execute();
}
Also used : FilePath(com.alibaba.alink.common.io.filesystem.FilePath) Path(org.apache.flink.core.fs.Path) FilePath(com.alibaba.alink.common.io.filesystem.FilePath) AkSinkStreamOp(com.alibaba.alink.operator.stream.sink.AkSinkStreamOp) AppendIdStreamOp(com.alibaba.alink.operator.stream.dataproc.AppendIdStreamOp) SelectBatchOp(com.alibaba.alink.operator.batch.sql.SelectBatchOp) RandomTableSourceBatchOp(com.alibaba.alink.operator.batch.source.RandomTableSourceBatchOp) ColumnsToVectorStreamOp(com.alibaba.alink.operator.stream.dataproc.format.ColumnsToVectorStreamOp) AppendIdBatchOp(com.alibaba.alink.operator.batch.dataproc.AppendIdBatchOp) RandomTableSourceStreamOp(com.alibaba.alink.operator.stream.source.RandomTableSourceStreamOp) SelectStreamOp(com.alibaba.alink.operator.stream.sql.SelectStreamOp) OverCountWindowStreamOp(com.alibaba.alink.operator.stream.feature.OverCountWindowStreamOp) ColumnsToVectorBatchOp(com.alibaba.alink.operator.batch.dataproc.format.ColumnsToVectorBatchOp) LSTNetPredictStreamOp(com.alibaba.alink.operator.stream.timeseries.LSTNetPredictStreamOp) Test(org.junit.Test)

Example 3 with LSTNetPredictStreamOp

use of com.alibaba.alink.operator.stream.timeseries.LSTNetPredictStreamOp in project Alink by alibaba.

the class LSTNetTrainBatchOpTest method testStreamSingleVar.

@Test
public void testStreamSingleVar() throws Exception {
    BatchOperator.setParallelism(1);
    final int numCols = 1;
    final String timeColName = "ts";
    BatchOperator<?> source = new RandomTableSourceBatchOp().setNumRows(1000L).setNumCols(numCols);
    String colName = source.getColNames()[0];
    final String selectClause = "TO_TIMESTAMP(" + timeColName + ") as " + timeColName + ", " + colName;
    AppendIdBatchOp appendIdBatchOp = new AppendIdBatchOp().setIdCol(timeColName).linkFrom(source);
    BatchOperator<?> timeBatchOp = new SelectBatchOp().setClause(selectClause).linkFrom(appendIdBatchOp);
    LSTNetTrainBatchOp trainOp = new LSTNetTrainBatchOp().setSelectedCol(colName).setTimeCol(timeColName).setWindow(24 * 7).setHorizon(12).setNumEpochs(1).linkFrom(timeBatchOp);
    StreamOperator<?> sourceStreamOp = new RandomTableSourceStreamOp().setNumCols(numCols).setMaxRows(6000L);
    AppendIdStreamOp appendIdStreamOp = new AppendIdStreamOp().setIdCol(timeColName).linkFrom(sourceStreamOp);
    StreamOperator<?> timestampStreamOp = new SelectStreamOp().setClause(selectClause).linkFrom(appendIdStreamOp);
    OverCountWindowStreamOp overTimeWindowStreamOp = new OverCountWindowStreamOp().setClause("MTABLE_AGG_PRECEDING(" + timeColName + ", " + colName + ") as col_agg").setTimeCol(timeColName).setPrecedingRows(24 * 7).linkFrom(timestampStreamOp);
    LSTNetPredictStreamOp predictStreamOp = new LSTNetPredictStreamOp(trainOp).setValueCol("col_agg").setPredictionCol("pred").setReservedCols(timeColName).setNumThreads(4).linkFrom(overTimeWindowStreamOp);
    FilePath tmpAkFile = new FilePath(new Path(folder.getRoot().getPath(), "lstnet_test_stream_single_var_result.ak"));
    predictStreamOp.link(new AkSinkStreamOp().setOverwriteSink(true).setFilePath(tmpAkFile));
    StreamOperator.execute();
}
Also used : FilePath(com.alibaba.alink.common.io.filesystem.FilePath) Path(org.apache.flink.core.fs.Path) FilePath(com.alibaba.alink.common.io.filesystem.FilePath) AkSinkStreamOp(com.alibaba.alink.operator.stream.sink.AkSinkStreamOp) AppendIdStreamOp(com.alibaba.alink.operator.stream.dataproc.AppendIdStreamOp) SelectBatchOp(com.alibaba.alink.operator.batch.sql.SelectBatchOp) RandomTableSourceBatchOp(com.alibaba.alink.operator.batch.source.RandomTableSourceBatchOp) AppendIdBatchOp(com.alibaba.alink.operator.batch.dataproc.AppendIdBatchOp) RandomTableSourceStreamOp(com.alibaba.alink.operator.stream.source.RandomTableSourceStreamOp) SelectStreamOp(com.alibaba.alink.operator.stream.sql.SelectStreamOp) OverCountWindowStreamOp(com.alibaba.alink.operator.stream.feature.OverCountWindowStreamOp) LSTNetPredictStreamOp(com.alibaba.alink.operator.stream.timeseries.LSTNetPredictStreamOp) Test(org.junit.Test)

Aggregations

OverCountWindowStreamOp (com.alibaba.alink.operator.stream.feature.OverCountWindowStreamOp)3 LSTNetPredictStreamOp (com.alibaba.alink.operator.stream.timeseries.LSTNetPredictStreamOp)3 Test (org.junit.Test)3 FilePath (com.alibaba.alink.common.io.filesystem.FilePath)2 AppendIdBatchOp (com.alibaba.alink.operator.batch.dataproc.AppendIdBatchOp)2 RandomTableSourceBatchOp (com.alibaba.alink.operator.batch.source.RandomTableSourceBatchOp)2 SelectBatchOp (com.alibaba.alink.operator.batch.sql.SelectBatchOp)2 AppendIdStreamOp (com.alibaba.alink.operator.stream.dataproc.AppendIdStreamOp)2 AkSinkStreamOp (com.alibaba.alink.operator.stream.sink.AkSinkStreamOp)2 RandomTableSourceStreamOp (com.alibaba.alink.operator.stream.source.RandomTableSourceStreamOp)2 SelectStreamOp (com.alibaba.alink.operator.stream.sql.SelectStreamOp)2 Path (org.apache.flink.core.fs.Path)2 ColumnsToVectorBatchOp (com.alibaba.alink.operator.batch.dataproc.format.ColumnsToVectorBatchOp)1 MemSourceBatchOp (com.alibaba.alink.operator.batch.source.MemSourceBatchOp)1 ColumnsToVectorStreamOp (com.alibaba.alink.operator.stream.dataproc.format.ColumnsToVectorStreamOp)1 MemSourceStreamOp (com.alibaba.alink.operator.stream.source.MemSourceStreamOp)1 Row (org.apache.flink.types.Row)1