lindong28 commented on code in PR #100: URL: https://github.com/apache/flink-ml/pull/100#discussion_r874368648
########## flink-ml-benchmark/src/main/java/org/apache/flink/ml/benchmark/datagenerator/common/LabeledPointWithWeightGenerator.java: ########## @@ -0,0 +1,202 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.flink.ml.benchmark.datagenerator.common; + +import org.apache.flink.api.common.functions.RichMapFunction; +import org.apache.flink.api.common.typeinfo.BasicTypeInfo; +import org.apache.flink.api.common.typeinfo.TypeInformation; +import org.apache.flink.api.common.typeinfo.Types; +import org.apache.flink.api.java.tuple.Tuple2; +import org.apache.flink.api.java.typeutils.RowTypeInfo; +import org.apache.flink.configuration.Configuration; +import org.apache.flink.ml.benchmark.datagenerator.InputDataGenerator; +import org.apache.flink.ml.benchmark.datagenerator.param.HasVectorDim; +import org.apache.flink.ml.common.datastream.TableUtils; +import org.apache.flink.ml.common.param.HasFeaturesCol; +import org.apache.flink.ml.common.param.HasLabelCol; +import org.apache.flink.ml.common.param.HasWeightCol; +import org.apache.flink.ml.linalg.Vectors; +import org.apache.flink.ml.linalg.typeinfo.DenseVectorTypeInfo; +import org.apache.flink.ml.param.IntParam; +import org.apache.flink.ml.param.Param; +import org.apache.flink.ml.param.ParamValidators; +import org.apache.flink.ml.util.ParamUtils; +import org.apache.flink.streaming.api.datastream.DataStream; +import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment; +import org.apache.flink.table.api.Table; +import org.apache.flink.table.api.bridge.java.StreamTableEnvironment; +import org.apache.flink.types.Row; +import org.apache.flink.util.NumberSequenceIterator; + +import java.util.HashMap; +import java.util.Map; +import java.util.Random; + +/** A DataGenerator which creates a table of features, label and weight. */ +public class LabeledPointWithWeightGenerator + implements InputDataGenerator<LabeledPointWithWeightGenerator>, + HasFeaturesCol<LabeledPointWithWeightGenerator>, + HasWeightCol<LabeledPointWithWeightGenerator>, + HasLabelCol<LabeledPointWithWeightGenerator>, + HasVectorDim<LabeledPointWithWeightGenerator> { + private final Map<Param<?>, Object> paramMap = new HashMap<>(); + + public static final Param<Integer> LABEL_ARITY = + new IntParam( + "labelArity", + "Arity of label. " + + "If set to positive value, label would be a positive integer between 0 and arity - 1. " + + "If set to zero, label would be continuous double value.", + 2, + ParamValidators.gtEq(0)); + + public int getLabelArity() { + return get(LABEL_ARITY); + } + + public LabeledPointWithWeightGenerator setLabelArity(int value) { + return set(LABEL_ARITY, value); + } + + public static final Param<Integer> FEATURES_ARITY = Review Comment: nits: can we order feature/label/weight consistently across the code? For example, RandomLabeledPointWithWeightGenerator(...) has these fields in the order of feature, label, and weight. ########## flink-ml-benchmark/src/main/java/org/apache/flink/ml/benchmark/datagenerator/common/LabeledPointWithWeightGenerator.java: ########## @@ -0,0 +1,202 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.flink.ml.benchmark.datagenerator.common; + +import org.apache.flink.api.common.functions.RichMapFunction; +import org.apache.flink.api.common.typeinfo.BasicTypeInfo; +import org.apache.flink.api.common.typeinfo.TypeInformation; +import org.apache.flink.api.common.typeinfo.Types; +import org.apache.flink.api.java.tuple.Tuple2; +import org.apache.flink.api.java.typeutils.RowTypeInfo; +import org.apache.flink.configuration.Configuration; +import org.apache.flink.ml.benchmark.datagenerator.InputDataGenerator; +import org.apache.flink.ml.benchmark.datagenerator.param.HasVectorDim; +import org.apache.flink.ml.common.datastream.TableUtils; +import org.apache.flink.ml.common.param.HasFeaturesCol; +import org.apache.flink.ml.common.param.HasLabelCol; +import org.apache.flink.ml.common.param.HasWeightCol; +import org.apache.flink.ml.linalg.Vectors; +import org.apache.flink.ml.linalg.typeinfo.DenseVectorTypeInfo; +import org.apache.flink.ml.param.IntParam; +import org.apache.flink.ml.param.Param; +import org.apache.flink.ml.param.ParamValidators; +import org.apache.flink.ml.util.ParamUtils; +import org.apache.flink.streaming.api.datastream.DataStream; +import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment; +import org.apache.flink.table.api.Table; +import org.apache.flink.table.api.bridge.java.StreamTableEnvironment; +import org.apache.flink.types.Row; +import org.apache.flink.util.NumberSequenceIterator; + +import java.util.HashMap; +import java.util.Map; +import java.util.Random; + +/** A DataGenerator which creates a table of features, label and weight. */ +public class LabeledPointWithWeightGenerator + implements InputDataGenerator<LabeledPointWithWeightGenerator>, + HasFeaturesCol<LabeledPointWithWeightGenerator>, + HasWeightCol<LabeledPointWithWeightGenerator>, + HasLabelCol<LabeledPointWithWeightGenerator>, + HasVectorDim<LabeledPointWithWeightGenerator> { + private final Map<Param<?>, Object> paramMap = new HashMap<>(); + + public static final Param<Integer> LABEL_ARITY = + new IntParam( + "labelArity", + "Arity of label. " + + "If set to positive value, label would be a positive integer between 0 and arity - 1. " Review Comment: If the arity is 3, I suppose we would like label values to be 0, 1, or 2. Then the label value might not be a positive integer. The random double value is in range [0, 1). It is probably useful to explicitly mention this. ########## flink-ml-benchmark/src/main/resources/benchmark-conf-kmeans.json: ########## @@ -0,0 +1,23 @@ +{ + "version": 1, Review Comment: Would it be better to rename these two files as `kmeans-benchmark.json` and `naivebayes-benchmark.json`, so that the file names are a bit more concise, and it is a bit easier to spot the key differentiator (i.e. algorithm name) between these files? How about we rename `benchmark-conf.json` as `benchmark-demo.json` to clarify the difference between this file and other files? ########## flink-ml-benchmark/src/main/resources/benchmark-conf-kmeans.json: ########## @@ -0,0 +1,23 @@ +{ Review Comment: Can you add the Apache license header to this file and similar files in the repo? Feel free to see [1] for example. [1] https://github.com/apache/kafka/blob/trunk/metadata/src/main/resources/common/metadata/TopicRecord.json ########## flink-ml-benchmark/src/main/java/org/apache/flink/ml/benchmark/datagenerator/common/LabeledPointWithWeightGenerator.java: ########## @@ -0,0 +1,202 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.flink.ml.benchmark.datagenerator.common; + +import org.apache.flink.api.common.functions.RichMapFunction; +import org.apache.flink.api.common.typeinfo.BasicTypeInfo; +import org.apache.flink.api.common.typeinfo.TypeInformation; +import org.apache.flink.api.common.typeinfo.Types; +import org.apache.flink.api.java.tuple.Tuple2; +import org.apache.flink.api.java.typeutils.RowTypeInfo; +import org.apache.flink.configuration.Configuration; +import org.apache.flink.ml.benchmark.datagenerator.InputDataGenerator; +import org.apache.flink.ml.benchmark.datagenerator.param.HasVectorDim; +import org.apache.flink.ml.common.datastream.TableUtils; +import org.apache.flink.ml.common.param.HasFeaturesCol; +import org.apache.flink.ml.common.param.HasLabelCol; +import org.apache.flink.ml.common.param.HasWeightCol; +import org.apache.flink.ml.linalg.Vectors; +import org.apache.flink.ml.linalg.typeinfo.DenseVectorTypeInfo; +import org.apache.flink.ml.param.IntParam; +import org.apache.flink.ml.param.Param; +import org.apache.flink.ml.param.ParamValidators; +import org.apache.flink.ml.util.ParamUtils; +import org.apache.flink.streaming.api.datastream.DataStream; +import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment; +import org.apache.flink.table.api.Table; +import org.apache.flink.table.api.bridge.java.StreamTableEnvironment; +import org.apache.flink.types.Row; +import org.apache.flink.util.NumberSequenceIterator; + +import java.util.HashMap; +import java.util.Map; +import java.util.Random; + +/** A DataGenerator which creates a table of features, label and weight. */ +public class LabeledPointWithWeightGenerator + implements InputDataGenerator<LabeledPointWithWeightGenerator>, + HasFeaturesCol<LabeledPointWithWeightGenerator>, + HasWeightCol<LabeledPointWithWeightGenerator>, + HasLabelCol<LabeledPointWithWeightGenerator>, + HasVectorDim<LabeledPointWithWeightGenerator> { + private final Map<Param<?>, Object> paramMap = new HashMap<>(); + + public static final Param<Integer> LABEL_ARITY = Review Comment: In Java, we typically put final static variables declarations before other non-final non-static variables. How about we define all Param variables first. And move their helper methods (e.g. setXXX and getXXX) to be after these definitions? Maybe check `StandardScalerParams` for example. And can you help update `StandardScalerParams` as well for consistency? ########## flink-ml-benchmark/src/main/java/org/apache/flink/ml/benchmark/datagenerator/common/LabeledPointWithWeightGenerator.java: ########## @@ -0,0 +1,202 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.flink.ml.benchmark.datagenerator.common; + +import org.apache.flink.api.common.functions.RichMapFunction; +import org.apache.flink.api.common.typeinfo.BasicTypeInfo; +import org.apache.flink.api.common.typeinfo.TypeInformation; +import org.apache.flink.api.common.typeinfo.Types; +import org.apache.flink.api.java.tuple.Tuple2; +import org.apache.flink.api.java.typeutils.RowTypeInfo; +import org.apache.flink.configuration.Configuration; +import org.apache.flink.ml.benchmark.datagenerator.InputDataGenerator; +import org.apache.flink.ml.benchmark.datagenerator.param.HasVectorDim; +import org.apache.flink.ml.common.datastream.TableUtils; +import org.apache.flink.ml.common.param.HasFeaturesCol; +import org.apache.flink.ml.common.param.HasLabelCol; +import org.apache.flink.ml.common.param.HasWeightCol; +import org.apache.flink.ml.linalg.Vectors; +import org.apache.flink.ml.linalg.typeinfo.DenseVectorTypeInfo; +import org.apache.flink.ml.param.IntParam; +import org.apache.flink.ml.param.Param; +import org.apache.flink.ml.param.ParamValidators; +import org.apache.flink.ml.util.ParamUtils; +import org.apache.flink.streaming.api.datastream.DataStream; +import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment; +import org.apache.flink.table.api.Table; +import org.apache.flink.table.api.bridge.java.StreamTableEnvironment; +import org.apache.flink.types.Row; +import org.apache.flink.util.NumberSequenceIterator; + +import java.util.HashMap; +import java.util.Map; +import java.util.Random; + +/** A DataGenerator which creates a table of features, label and weight. */ +public class LabeledPointWithWeightGenerator + implements InputDataGenerator<LabeledPointWithWeightGenerator>, + HasFeaturesCol<LabeledPointWithWeightGenerator>, + HasWeightCol<LabeledPointWithWeightGenerator>, + HasLabelCol<LabeledPointWithWeightGenerator>, + HasVectorDim<LabeledPointWithWeightGenerator> { + private final Map<Param<?>, Object> paramMap = new HashMap<>(); + + public static final Param<Integer> LABEL_ARITY = + new IntParam( + "labelArity", + "Arity of label. " + + "If set to positive value, label would be a positive integer between 0 and arity - 1. " + + "If set to zero, label would be continuous double value.", + 2, + ParamValidators.gtEq(0)); + + public int getLabelArity() { + return get(LABEL_ARITY); + } + + public LabeledPointWithWeightGenerator setLabelArity(int value) { + return set(LABEL_ARITY, value); + } + + public static final Param<Integer> FEATURES_ARITY = + new IntParam( + "featuresArity", + "Arity of features. " + + "If set to positive value, features would be a positive integer between 0 and arity - 1. " + + "If set to zero, features would be continuous double value.\"", + 2, + ParamValidators.gtEq(0)); + + public int getFeaturesArity() { + return get(FEATURES_ARITY); + } + + public LabeledPointWithWeightGenerator setFeaturesArity(int value) { + return set(FEATURES_ARITY, value); + } + + public static final Param<Integer> WEIGHT_ARITY = + new IntParam( + "weightArity", + "Arity of weight. " + + "If set to positive value, weight would be a positive integer between 1 and arity. " + + "If set to zero, weight would be continuous double value.\"", + 1, + ParamValidators.gtEq(0)); + + public int getWeightArity() { + return get(WEIGHT_ARITY); + } + + public LabeledPointWithWeightGenerator setWeightArity(int value) { + return set(WEIGHT_ARITY, value); + } + + public LabeledPointWithWeightGenerator() { + ParamUtils.initializeMapWithDefaultValues(paramMap, this); + } + + @Override + public Table[] getData(StreamTableEnvironment tEnv) { + StreamExecutionEnvironment env = TableUtils.getExecutionEnvironment(tEnv); + + DataStream<Row> dataStream = + env.fromParallelCollection( + new NumberSequenceIterator(1L, getNumValues()), + BasicTypeInfo.LONG_TYPE_INFO) + .map( + new RandomLabeledPointWithWeightGenerator( + getSeed(), + getVectorDim(), + getFeaturesArity(), + getLabelArity(), + getWeightArity()), + new RowTypeInfo( + new TypeInformation[] { + DenseVectorTypeInfo.INSTANCE, Types.DOUBLE, Types.DOUBLE + }, + new String[] { + getFeaturesCol(), getLabelCol(), getWeightCol() + })); + + Table dataTable = tEnv.fromDataStream(dataStream); + + return new Table[] {dataTable}; + } + + @Override + public Map<Param<?>, Object> getParamMap() { + return paramMap; + } + + private static class RandomLabeledPointWithWeightGenerator extends RichMapFunction<Long, Row> { + private final long initSeed; + private final int vectorDim; + private final int featuresArity; + private final int labelArity; + private final int weightArity; + private Random random; + + private RandomLabeledPointWithWeightGenerator( + long initSeed, int vectorDim, int featuresArity, int labelArity, int weightArity) { + this.initSeed = initSeed; + this.vectorDim = vectorDim; + this.featuresArity = featuresArity; + this.labelArity = labelArity; + this.weightArity = weightArity; + } + + @Override + public void open(Configuration parameters) throws Exception { + super.open(parameters); + int index = getRuntimeContext().getIndexOfThisSubtask(); + random = new Random(Tuple2.of(initSeed, index).hashCode()); + } + + @Override + public Row map(Long aLong) { + double[] values = new double[vectorDim]; + if (featuresArity > 0) { + for (int i = 0; i < vectorDim; i++) { + values[i] = random.nextInt(featuresArity); Review Comment: It is probably simpler to add the following method instead of repeating this code for values, label, and weight. ``` private double getValue(int arity, Random random) { if (arity > 0) { return random.nextInt(arity); } return random.nextDouble(); } ``` ########## flink-ml-benchmark/src/main/java/org/apache/flink/ml/benchmark/datagenerator/common/LabeledPointWithWeightGenerator.java: ########## @@ -0,0 +1,202 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.flink.ml.benchmark.datagenerator.common; + +import org.apache.flink.api.common.functions.RichMapFunction; +import org.apache.flink.api.common.typeinfo.BasicTypeInfo; +import org.apache.flink.api.common.typeinfo.TypeInformation; +import org.apache.flink.api.common.typeinfo.Types; +import org.apache.flink.api.java.tuple.Tuple2; +import org.apache.flink.api.java.typeutils.RowTypeInfo; +import org.apache.flink.configuration.Configuration; +import org.apache.flink.ml.benchmark.datagenerator.InputDataGenerator; +import org.apache.flink.ml.benchmark.datagenerator.param.HasVectorDim; +import org.apache.flink.ml.common.datastream.TableUtils; +import org.apache.flink.ml.common.param.HasFeaturesCol; +import org.apache.flink.ml.common.param.HasLabelCol; +import org.apache.flink.ml.common.param.HasWeightCol; +import org.apache.flink.ml.linalg.Vectors; +import org.apache.flink.ml.linalg.typeinfo.DenseVectorTypeInfo; +import org.apache.flink.ml.param.IntParam; +import org.apache.flink.ml.param.Param; +import org.apache.flink.ml.param.ParamValidators; +import org.apache.flink.ml.util.ParamUtils; +import org.apache.flink.streaming.api.datastream.DataStream; +import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment; +import org.apache.flink.table.api.Table; +import org.apache.flink.table.api.bridge.java.StreamTableEnvironment; +import org.apache.flink.types.Row; +import org.apache.flink.util.NumberSequenceIterator; + +import java.util.HashMap; +import java.util.Map; +import java.util.Random; + +/** A DataGenerator which creates a table of features, label and weight. */ +public class LabeledPointWithWeightGenerator + implements InputDataGenerator<LabeledPointWithWeightGenerator>, + HasFeaturesCol<LabeledPointWithWeightGenerator>, + HasWeightCol<LabeledPointWithWeightGenerator>, + HasLabelCol<LabeledPointWithWeightGenerator>, + HasVectorDim<LabeledPointWithWeightGenerator> { + private final Map<Param<?>, Object> paramMap = new HashMap<>(); + + public static final Param<Integer> LABEL_ARITY = + new IntParam( + "labelArity", + "Arity of label. " + + "If set to positive value, label would be a positive integer between 0 and arity - 1. " + + "If set to zero, label would be continuous double value.", + 2, + ParamValidators.gtEq(0)); + + public int getLabelArity() { + return get(LABEL_ARITY); + } + + public LabeledPointWithWeightGenerator setLabelArity(int value) { + return set(LABEL_ARITY, value); + } + + public static final Param<Integer> FEATURES_ARITY = + new IntParam( + "featuresArity", Review Comment: `features` is a dense vector. `featuresArity` might be confused with the rank of this dense vector. How about renaming this parameter as `featureArity`, since it is the arity of each individual feature value? ########## flink-ml-benchmark/src/main/java/org/apache/flink/ml/benchmark/datagenerator/common/LabeledPointWithWeightGenerator.java: ########## @@ -0,0 +1,202 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.flink.ml.benchmark.datagenerator.common; + +import org.apache.flink.api.common.functions.RichMapFunction; +import org.apache.flink.api.common.typeinfo.BasicTypeInfo; +import org.apache.flink.api.common.typeinfo.TypeInformation; +import org.apache.flink.api.common.typeinfo.Types; +import org.apache.flink.api.java.tuple.Tuple2; +import org.apache.flink.api.java.typeutils.RowTypeInfo; +import org.apache.flink.configuration.Configuration; +import org.apache.flink.ml.benchmark.datagenerator.InputDataGenerator; +import org.apache.flink.ml.benchmark.datagenerator.param.HasVectorDim; +import org.apache.flink.ml.common.datastream.TableUtils; +import org.apache.flink.ml.common.param.HasFeaturesCol; +import org.apache.flink.ml.common.param.HasLabelCol; +import org.apache.flink.ml.common.param.HasWeightCol; +import org.apache.flink.ml.linalg.Vectors; +import org.apache.flink.ml.linalg.typeinfo.DenseVectorTypeInfo; +import org.apache.flink.ml.param.IntParam; +import org.apache.flink.ml.param.Param; +import org.apache.flink.ml.param.ParamValidators; +import org.apache.flink.ml.util.ParamUtils; +import org.apache.flink.streaming.api.datastream.DataStream; +import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment; +import org.apache.flink.table.api.Table; +import org.apache.flink.table.api.bridge.java.StreamTableEnvironment; +import org.apache.flink.types.Row; +import org.apache.flink.util.NumberSequenceIterator; + +import java.util.HashMap; +import java.util.Map; +import java.util.Random; + +/** A DataGenerator which creates a table of features, label and weight. */ +public class LabeledPointWithWeightGenerator + implements InputDataGenerator<LabeledPointWithWeightGenerator>, + HasFeaturesCol<LabeledPointWithWeightGenerator>, + HasWeightCol<LabeledPointWithWeightGenerator>, + HasLabelCol<LabeledPointWithWeightGenerator>, + HasVectorDim<LabeledPointWithWeightGenerator> { + private final Map<Param<?>, Object> paramMap = new HashMap<>(); + + public static final Param<Integer> LABEL_ARITY = + new IntParam( + "labelArity", + "Arity of label. " + + "If set to positive value, label would be a positive integer between 0 and arity - 1. " + + "If set to zero, label would be continuous double value.", + 2, + ParamValidators.gtEq(0)); + + public int getLabelArity() { + return get(LABEL_ARITY); + } + + public LabeledPointWithWeightGenerator setLabelArity(int value) { + return set(LABEL_ARITY, value); + } + + public static final Param<Integer> FEATURES_ARITY = + new IntParam( + "featuresArity", + "Arity of features. " + + "If set to positive value, features would be a positive integer between 0 and arity - 1. " + + "If set to zero, features would be continuous double value.\"", + 2, + ParamValidators.gtEq(0)); + + public int getFeaturesArity() { + return get(FEATURES_ARITY); + } + + public LabeledPointWithWeightGenerator setFeaturesArity(int value) { + return set(FEATURES_ARITY, value); + } + + public static final Param<Integer> WEIGHT_ARITY = + new IntParam( + "weightArity", + "Arity of weight. " + + "If set to positive value, weight would be a positive integer between 1 and arity. " + + "If set to zero, weight would be continuous double value.\"", + 1, + ParamValidators.gtEq(0)); + + public int getWeightArity() { + return get(WEIGHT_ARITY); + } + + public LabeledPointWithWeightGenerator setWeightArity(int value) { + return set(WEIGHT_ARITY, value); + } + + public LabeledPointWithWeightGenerator() { + ParamUtils.initializeMapWithDefaultValues(paramMap, this); + } + + @Override + public Table[] getData(StreamTableEnvironment tEnv) { + StreamExecutionEnvironment env = TableUtils.getExecutionEnvironment(tEnv); + + DataStream<Row> dataStream = + env.fromParallelCollection( + new NumberSequenceIterator(1L, getNumValues()), + BasicTypeInfo.LONG_TYPE_INFO) + .map( + new RandomLabeledPointWithWeightGenerator( + getSeed(), + getVectorDim(), + getFeaturesArity(), + getLabelArity(), + getWeightArity()), + new RowTypeInfo( + new TypeInformation[] { + DenseVectorTypeInfo.INSTANCE, Types.DOUBLE, Types.DOUBLE + }, + new String[] { + getFeaturesCol(), getLabelCol(), getWeightCol() + })); + + Table dataTable = tEnv.fromDataStream(dataStream); + + return new Table[] {dataTable}; + } + + @Override + public Map<Param<?>, Object> getParamMap() { + return paramMap; + } + + private static class RandomLabeledPointWithWeightGenerator extends RichMapFunction<Long, Row> { + private final long initSeed; + private final int vectorDim; + private final int featuresArity; + private final int labelArity; + private final int weightArity; + private Random random; + + private RandomLabeledPointWithWeightGenerator( + long initSeed, int vectorDim, int featuresArity, int labelArity, int weightArity) { + this.initSeed = initSeed; + this.vectorDim = vectorDim; + this.featuresArity = featuresArity; + this.labelArity = labelArity; + this.weightArity = weightArity; + } + + @Override + public void open(Configuration parameters) throws Exception { + super.open(parameters); + int index = getRuntimeContext().getIndexOfThisSubtask(); + random = new Random(Tuple2.of(initSeed, index).hashCode()); + } + + @Override + public Row map(Long aLong) { + double[] values = new double[vectorDim]; Review Comment: Would it be better to name this variable as features, to be consistent with `featuresArity`? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: issues-unsubscr...@flink.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org