use of com.alibaba.alink.operator.stream.feature.OverCountWindowStreamOp in project Alink by alibaba.
the class AutoArimaStreamOpTest method test.
@Test
public void test() throws Exception {
List<Row> mTableData = Arrays.asList(Row.of(1, new Timestamp(1), 10.0), Row.of(1, new Timestamp(2), 11.0), Row.of(1, new Timestamp(3), 12.0), Row.of(1, new Timestamp(4), 13.0), Row.of(1, new Timestamp(5), 14.0), Row.of(1, new Timestamp(6), 15.0), Row.of(1, new Timestamp(7), 16.0), Row.of(1, new Timestamp(8), 17.0), Row.of(1, new Timestamp(9), 18.0), Row.of(1, new Timestamp(10), 19.0));
MemSourceStreamOp source = new MemSourceStreamOp(mTableData, new String[] { "id", "ts", "val" });
CollectSinkStreamOp resultOp = source.link(new OverCountWindowStreamOp().setPartitionCols("id").setTimeCol("ts").setPrecedingRows(5).setClause("mtable_agg_preceding(ts, val) as data")).link(new AutoArimaStreamOp().setValueCol("data").setPredictionCol("predict").setPredictNum(12)).link(new LookupValueInTimeSeriesStreamOp().setTimeCol("ts").setTimeSeriesCol("predict").setOutputCol("out")).link(new CollectSinkStreamOp());
StreamOperator.execute();
List<Row> sResult = resultOp.getAndRemoveValues();
sResult.sort(new RowComparator(1));
Assert.assertEquals(10, sResult.size());
Assert.assertEquals(11.0, (Double) sResult.get(2).getField(5), 10e-5);
}
use of com.alibaba.alink.operator.stream.feature.OverCountWindowStreamOp in project Alink by alibaba.
the class HoltWintersStreamOpTest method test.
@Test
public void test() throws Exception {
List<Row> mTableData = Arrays.asList(Row.of(1, new Timestamp(1), 10.0), Row.of(1, new Timestamp(2), 11.0), Row.of(1, new Timestamp(3), 12.0), Row.of(1, new Timestamp(4), 13.0), Row.of(1, new Timestamp(5), 14.0), Row.of(1, new Timestamp(6), 15.0), Row.of(1, new Timestamp(7), 16.0), Row.of(1, new Timestamp(8), 17.0), Row.of(1, new Timestamp(9), 18.0), Row.of(1, new Timestamp(10), 19.0));
MemSourceStreamOp source = new MemSourceStreamOp(mTableData, new String[] { "id", "ts", "val" });
CollectSinkStreamOp resultOp = source.link(new OverCountWindowStreamOp().setPartitionCols("id").setTimeCol("ts").setPrecedingRows(5).setClause("mtable_agg_preceding(ts, val) as data")).link(new HoltWintersStreamOp().setValueCol("data").setPredictionCol("predict").setPredictNum(12)).link(new LookupValueInTimeSeriesStreamOp().setTimeCol("ts").setTimeSeriesCol("predict").setOutputCol("out")).link(new CollectSinkStreamOp());
StreamOperator.execute();
List<Row> sResult = resultOp.getAndRemoveValues();
sResult.sort(new RowComparator(1));
Assert.assertEquals(10, sResult.size());
Assert.assertEquals(12.0000, (Double) sResult.get(3).getField(5), 10e-5);
}
use of com.alibaba.alink.operator.stream.feature.OverCountWindowStreamOp in project Alink by alibaba.
the class ShiftStreamOpTest method test.
@Test
public void test() throws Exception {
List<Row> mTableData = Arrays.asList(Row.of(1, new Timestamp(1), 10.0), Row.of(1, new Timestamp(2), 11.0), Row.of(1, new Timestamp(3), 12.0), Row.of(1, new Timestamp(4), 13.0), Row.of(1, new Timestamp(5), 14.0), Row.of(1, new Timestamp(6), 15.0), Row.of(1, new Timestamp(7), 16.0), Row.of(1, new Timestamp(8), 17.0), Row.of(1, new Timestamp(9), 18.0), Row.of(1, new Timestamp(10), 19.0));
MemSourceStreamOp source = new MemSourceStreamOp(mTableData, new String[] { "id", "ts", "val" });
CollectSinkStreamOp resultOp = source.link(new OverCountWindowStreamOp().setPartitionCols("id").setTimeCol("ts").setPrecedingRows(5).setClause("mtable_agg_preceding(ts, val) as data")).link(new ShiftStreamOp().setValueCol("data").setShiftNum(7).setPredictNum(12).setPredictionCol("predict")).link(new LookupValueInTimeSeriesStreamOp().setTimeCol("ts").setTimeSeriesCol("predict").setOutputCol("out").setReservedCols("ts")).link(new CollectSinkStreamOp());
StreamOperator.execute();
List<Row> sResult = resultOp.getAndRemoveValues();
sResult.sort(new RowComparator(1));
Assert.assertEquals(10, sResult.size());
Assert.assertEquals("10.0", sResult.get(1).getField(1).toString());
}
use of com.alibaba.alink.operator.stream.feature.OverCountWindowStreamOp in project Alink by alibaba.
the class DeepARPredictStreamOpTest method testDeepARTrainBatchOp.
@Test
public void testDeepARTrainBatchOp() 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"), 100.0), Row.of(0, Timestamp.valueOf("2021-11-03 00:00:00"), 100.0), Row.of(0, Timestamp.valueOf("2021-11-04 00:00:00"), 100.0), Row.of(0, Timestamp.valueOf("2021-11-05 00:00:00"), 100.0));
MemSourceBatchOp memSourceBatchOp = new MemSourceBatchOp(data, "id int, ts timestamp, series double");
MemSourceStreamOp memSourceStreamOp = new MemSourceStreamOp(data, "id int, ts timestamp, series double");
DeepARTrainBatchOp deepARTrainBatchOp = new DeepARTrainBatchOp().setTimeCol("ts").setSelectedCol("series").setNumEpochs(10).setWindow(2).setStride(1).linkFrom(memSourceBatchOp);
OverCountWindowStreamOp overCountWindowStreamOp = new OverCountWindowStreamOp().setClause("MTABLE_AGG_PRECEDING(ts, series) as mtable_agg_series").setTimeCol("ts").setPrecedingRows(2);
DeepARPredictStreamOp deepARPredictStreamOp = new DeepARPredictStreamOp(deepARTrainBatchOp).setPredictNum(2).setPredictionCol("pred").setValueCol("mtable_agg_series");
deepARPredictStreamOp.linkFrom(overCountWindowStreamOp.linkFrom(memSourceStreamOp).filter("ts = TO_TIMESTAMP('2021-11-05 00:00:00')")).print();
StreamOperator.execute();
}
use of com.alibaba.alink.operator.stream.feature.OverCountWindowStreamOp 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();
}
Aggregations