use of com.alibaba.alink.operator.stream.feature.OverCountWindowStreamOp 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();
}
use of com.alibaba.alink.operator.stream.feature.OverCountWindowStreamOp in project Alink by alibaba.
the class ProphetPredictStreamOpTest method testModel.
@Test
public void testModel() throws Exception {
Row[] rowsData = new Row[] { Row.of("1", new Timestamp(117, 11, 1, 0, 0, 0, 0), 9.59076113897809), Row.of("1", new Timestamp(117, 11, 2, 0, 0, 0, 0), 8.51959031601596), Row.of("2", new Timestamp(117, 11, 3, 0, 0, 0, 0), 9.59076113897809), Row.of("1", new Timestamp(117, 11, 4, 0, 0, 0, 0), 8.18367658262066), Row.of("2", new Timestamp(117, 11, 5, 0, 0, 0, 0), 8.51959031601596), Row.of("1", new Timestamp(117, 11, 6, 0, 0, 0, 0), 8.07246736935477), Row.of("2", new Timestamp(117, 11, 7, 0, 0, 0, 0), 8.18367658262066), Row.of("2", new Timestamp(117, 11, 8, 0, 0, 0, 0), 8.18367658262066), Row.of("2", new Timestamp(117, 11, 9, 0, 0, 0, 0), 8.18367658262066), Row.of("2", new Timestamp(117, 11, 10, 0, 0, 0, 0), 8.18367658262066), Row.of("2", new Timestamp(117, 11, 11, 0, 0, 0, 0), 8.18367658262066), Row.of("2", new Timestamp(117, 11, 12, 0, 0, 0, 0), 8.18367658262066), Row.of("2", new Timestamp(117, 11, 13, 0, 0, 0, 0), 8.18367658262066) };
String[] colNames = new String[] { "id", "ds1", "y1" };
// train batch model.
MemSourceBatchOp source = new MemSourceBatchOp(Arrays.asList(rowsData), colNames);
ProphetTrainBatchOp model = new ProphetTrainBatchOp().setTimeCol("ds1").setValueCol("y1");
// .setPythonCmdPath("/Library/Frameworks/Python.framework/Versions/3.7/bin/python3");
source.link(model);
MemSourceStreamOp streamSource = new MemSourceStreamOp(Arrays.asList(rowsData), colNames);
OverCountWindowStreamOp over = new OverCountWindowStreamOp().setTimeCol("ds1").setPrecedingRows(4).setClause("mtable_agg_preceding(ds1,y1) as tensor");
ProphetPredictStreamOp streamPred = new ProphetPredictStreamOp(model).setValueCol("tensor").setPredictNum(1).setPredictionCol("pred").setPredictionDetailCol("pred_detail");
LookupVectorInTimeSeriesStreamOp valueOp = new LookupVectorInTimeSeriesStreamOp().setTimeSeriesCol("pred").setTimeCol("ds1").setReservedCols("ds1", "tensor", "pred").setOutputCol("y_hat");
streamSource.link(over).link(streamPred).link(valueOp).print();
StreamOperator.execute();
}
use of com.alibaba.alink.operator.stream.feature.OverCountWindowStreamOp in project Alink by alibaba.
the class ArimaStreamOpTest 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 ArimaStreamOp().setValueCol("data").setOrder(new int[] { 1, 0, 1 }).setPredictNum(12).setPredictionCol("predict")).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(13.9992, (Double) sResult.get(4).getField(5), 10e-5);
}
use of com.alibaba.alink.operator.stream.feature.OverCountWindowStreamOp in project Alink by alibaba.
the class AutoGarchStreamOpTest 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 AutoGarchStreamOp().setValueCol("data").setIcType("AIC").setPredictNum(10).setMaxOrder(4).setIfGARCH11(true).setMinusMean(false).setPredictionCol("predict")).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.0893, (Double) sResult.get(4).getField(5), 10e-5);
}
use of com.alibaba.alink.operator.stream.feature.OverCountWindowStreamOp in project Alink by alibaba.
the class LookupVectorInTimeSeriesStreamOpTest method test.
@Test
public void test() throws Exception {
List<Row> mTableData = Arrays.asList(Row.of(new Timestamp(1), "10.0 21.0"), Row.of(new Timestamp(2), "11.0 22.0"), Row.of(new Timestamp(3), "12.0 23.0"), Row.of(new Timestamp(4), "13.0 24.0"), Row.of(new Timestamp(5), "14.0 25.0"), Row.of(new Timestamp(6), "15.0 26.0"), Row.of(new Timestamp(7), "16.0 27.0"), Row.of(new Timestamp(8), "17.0 28.0"), Row.of(new Timestamp(9), "18.0 29.0"), Row.of(new Timestamp(10), "19.0 30.0"));
MemSourceStreamOp source = new MemSourceStreamOp(mTableData, new String[] { "ts", "val" });
CollectSinkStreamOp resultOp = source.link(new OverCountWindowStreamOp().setTimeCol("ts").setPrecedingRows(5).setClause("mtable_agg(ts, val) as data")).link(new ShiftStreamOp().setValueCol("data").setShiftNum(7).setPredictNum(12).setPredictionCol("predict")).link(new LookupVectorInTimeSeriesStreamOp().setTimeCol("ts").setTimeSeriesCol("predict").setOutputCol("out").setReservedCols("ts")).link(new CollectSinkStreamOp());
StreamOperator.execute();
List<Row> expectRows = Arrays.asList(Row.of(new Timestamp(1), null), Row.of(new Timestamp(2), VectorUtil.getVector("10.0 21.0")), Row.of(new Timestamp(3), VectorUtil.getVector("10.0 21.0")), Row.of(new Timestamp(4), VectorUtil.getVector("10.0 21.0")), Row.of(new Timestamp(5), VectorUtil.getVector("10.0 21.0")), Row.of(new Timestamp(6), VectorUtil.getVector("10.0 21.0")), Row.of(new Timestamp(7), VectorUtil.getVector("11.0 22.0")), Row.of(new Timestamp(8), VectorUtil.getVector("12.0 23.0")), Row.of(new Timestamp(9), VectorUtil.getVector("13.0 24.0")), Row.of(new Timestamp(10), VectorUtil.getVector("14.0 25.0")));
assertListRowEqual(expectRows, resultOp.getAndRemoveValues(), 0);
}
Aggregations