use of com.alibaba.alink.operator.stream.sink.CollectSinkStreamOp 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.sink.CollectSinkStreamOp 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);
}
use of com.alibaba.alink.operator.stream.sink.CollectSinkStreamOp in project Alink by alibaba.
the class GeoKMeansTest method testGeoKmeans.
@Test
public void testGeoKmeans() throws Exception {
GeoKMeans geoKMeans = new GeoKMeans().setLatitudeCol("f0").setLongitudeCol("f1").setPredictionCol("pred").setPredictionDistanceCol("distance").setK(2);
PipelineModel model = new Pipeline().add(geoKMeans).fit(inputBatchOp);
BatchOperator<?> batchPredOp = model.transform(inputBatchOp);
verifyPredResult(batchPredOp.collect());
CollectSinkStreamOp streamPredOp = model.transform(inputStreamOp).link(new CollectSinkStreamOp());
StreamOperator.execute();
verifyPredResult(streamPredOp.getAndRemoveValues());
}
use of com.alibaba.alink.operator.stream.sink.CollectSinkStreamOp in project Alink by alibaba.
the class IndexToStringTest method testIndexToString.
@Test
public void testIndexToString() throws Exception {
BatchOperator data = new MemSourceBatchOp(Arrays.asList(rows), new String[] { "id", "feature" });
StringIndexer stringIndexer = new StringIndexer().setModelName("string_indexer_model").setSelectedCol("feature").setOutputCol("feature_indexed").setStringOrderType("frequency_asc");
BatchOperator indexed = stringIndexer.fit(data).transform(data);
IndexToString indexToString = new IndexToString().setModelName("string_indexer_model").setSelectedCol("feature_indexed").setOutputCol("feature_indxed_unindexed");
List<Row> unindexed = indexToString.transform(indexed).collect();
unindexed.sort(new RowComparator(0));
assertEquals(unindexed.get(0).getField(2), 2L);
assertEquals(unindexed.get(3).getField(2), 1L);
assertEquals(unindexed.get(5).getField(2), 0L);
unindexed.forEach(row -> {
Assert.assertEquals(row.getField(1), row.getField(3));
});
StreamOperator streamData = new MemSourceStreamOp(Arrays.asList(rows), new String[] { "id", "feature" });
CollectSinkStreamOp collectSinkStreamOp = new CollectSinkStreamOp().linkFrom(indexToString.transform(stringIndexer.fit(data).transform(streamData)));
StreamOperator.execute();
List<Row> result = collectSinkStreamOp.getAndRemoveValues();
result.sort(new RowComparator(0));
assertEquals(result.get(0).getField(2), 2L);
assertEquals(result.get(3).getField(2), 1L);
assertEquals(result.get(5).getField(2), 0L);
result.forEach(row -> {
Assert.assertEquals(row.getField(1), row.getField(3));
});
}
use of com.alibaba.alink.operator.stream.sink.CollectSinkStreamOp in project Alink by alibaba.
the class MaxAbsScalerTest method testPipelineI.
private static void testPipelineI() throws Exception {
BatchOperator batchData = (BatchOperator) getMultiTypeData(true);
StreamOperator streamData = (StreamOperator) getMultiTypeData(false);
String[] selectedColNames = new String[] { "f0", "f1" };
MaxAbsScaler scaler3 = new MaxAbsScaler().setSelectedCols(selectedColNames);
MaxAbsScalerModel model = scaler3.fit(batchData);
BatchOperator res = model.transform(batchData);
List<Row> rows = res.getDataSet().collect();
rows.sort(new RowComparator(0));
assertEquals(rows.get(0).getField(1), 0.25);
assertEquals(rows.get(0).getField(2), 0.6666666666666666);
assertEquals(rows.get(1).getField(1), -0.25);
assertEquals(rows.get(1).getField(2), -1.0);
assertEquals(rows.get(2).getField(1), 1.0);
assertEquals(rows.get(2).getField(2), 0.6666666666666666);
assertEquals(rows.get(3).getField(1), null);
assertEquals(rows.get(3).getField(2), null);
CollectSinkStreamOp collectSinkStreamOp = new CollectSinkStreamOp().linkFrom(model.transform(streamData));
StreamOperator.execute();
List<Row> result = collectSinkStreamOp.getAndRemoveValues();
result.sort(new RowComparator(0));
assertEquals(rows.get(0).getField(1), 0.25);
assertEquals(rows.get(0).getField(2), 0.6666666666666666);
assertEquals(rows.get(1).getField(1), -0.25);
assertEquals(rows.get(1).getField(2), -1.0);
assertEquals(rows.get(2).getField(1), 1.0);
assertEquals(rows.get(2).getField(2), 0.6666666666666666);
assertEquals(rows.get(3).getField(1), null);
assertEquals(rows.get(3).getField(2), null);
}
Aggregations