use of com.alibaba.alink.operator.stream.source.MemSourceStreamOp in project Alink by alibaba.
the class Chap01 method c_5_3.
static void c_5_3() throws Exception {
MemSourceStreamOp pred_set = new MemSourceStreamOp(new Integer[] { 2018, 2019 }, "x");
BatchOperator<?> lr_model = new AkSourceBatchOp().setFilePath(DATA_DIR + "gmv_reg.model");
LinearRegPredictStreamOp predictor = new LinearRegPredictStreamOp(lr_model).setPredictionCol("pred");
pred_set.select("x, x*x AS x2").link(predictor).print();
StreamOperator.execute();
}
use of com.alibaba.alink.operator.stream.source.MemSourceStreamOp in project Alink by alibaba.
the class UDFStreamOpTest method testEmptyFunc.
@Test(expected = IllegalArgumentException.class)
public void testEmptyFunc() throws Exception {
MemSourceStreamOp src = new MemSourceStreamOp(new Object[][] { new Object[] { "1", "a", 1L }, new Object[] { "2", "b33", 2L } }, new String[] { "c0", "c1", "c2" });
UDFStreamOp udfOp = new UDFStreamOp().setSelectedCols("c1", "c2").setReservedCols(new String[] {}).setOutputCol("c2");
udfOp.linkFrom(src);
}
use of com.alibaba.alink.operator.stream.source.MemSourceStreamOp in project Alink by alibaba.
the class UDTFStreamOpTest method testUdtf.
@Test
public void testUdtf() throws Exception {
MemSourceStreamOp src = new MemSourceStreamOp(new Object[][] { new Object[] { "1", "a b", 1L }, new Object[] { "2", "b33 bb44", 2L }, new Object[] { "3", "", 3L } }, new String[] { "c0", "c1", "c2" });
UDTFStreamOp udtfOp = new UDTFStreamOp().setFunc(new Split(" ")).setSelectedCols("c1", "c2").setReservedCols(new String[] { "c1", "c2" }).setOutputCols("c1", "length");
udtfOp.linkFrom(src);
Assert.assertArrayEquals(new String[] { "c2", "c1", "length" }, udtfOp.getColNames());
udtfOp.print();
StreamOperator.execute();
}
use of com.alibaba.alink.operator.stream.source.MemSourceStreamOp in project Alink by alibaba.
the class SoftmaxTest method pipelineTest.
@Test
public void pipelineTest() throws Exception {
BatchOperator<?> vecdata = new MemSourceBatchOp(Arrays.asList(vecrows), veccolNames);
StreamOperator<?> svecdata = new MemSourceStreamOp(Arrays.asList(vecrows), veccolNames);
Pipeline pl = new Pipeline().add(softmax).add(vsoftmax).add(svsoftmax).add(vssoftmax);
PipelineModel model = pl.fit(vecdata);
BatchOperator<?> result = model.transform(vecdata).select(new String[] { "label", "predLr", "vpredLr", "svpredLr" });
List<Row> data = result.lazyPrint(100).collect();
for (Row row : data) {
for (int i = 1; i < 3; ++i) {
Assert.assertEquals(row.getField(0), row.getField(i));
}
}
// below is stream test code
// below is stream test code.
CollectSinkStreamOp sop = model.transform(svecdata).select(new String[] { "label", "predLr", "vpredLr", "svpredLr" }).link(new CollectSinkStreamOp());
StreamOperator.execute();
List<Row> rows = sop.getAndRemoveValues();
for (Row row : rows) {
for (int i = 1; i < 3; ++i) {
Assert.assertEquals(row.getField(0), row.getField(i));
}
}
}
use of com.alibaba.alink.operator.stream.source.MemSourceStreamOp in project Alink by alibaba.
the class StreamingKMeansStreamOpTest method before.
@Before
public void before() {
Row[] trainDataArray = new Row[] { Row.of(0, "0 0 0"), Row.of(1, "0.1 0.1 0.1"), Row.of(2, "0.2 0.2 0.2"), Row.of(3, "9 9 9"), Row.of(4, "9.1 9.1 9.1"), Row.of(5, "9.2 9.2 9.2") };
Row[] predictDataArray = new Row[numElementsToPredict];
for (int i = 0; i < predictDataArray.length; i++) {
predictDataArray[i] = Row.of(DenseVector.rand(3));
}
trainDataBatchOp = new MemSourceBatchOp(Arrays.asList(trainDataArray), new String[] { "id", "vec" });
predictDataStreamOp = new MemSourceStreamOp(Arrays.asList(predictDataArray), new String[] { "vec" });
}
Aggregations