weibozhao commented on a change in pull request #24:
URL: https://github.com/apache/flink-ml/pull/24#discussion_r752855277
##########
File path:
flink-ml-lib/src/main/java/org/apache/flink/ml/classification/knn/KnnModelData.java
##########
@@ -0,0 +1,223 @@
+package org.apache.flink.ml.classification.knn;
+
+import org.apache.flink.api.common.serialization.Encoder;
+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.connector.file.src.reader.SimpleStreamFormat;
+import org.apache.flink.core.fs.FSDataInputStream;
+import org.apache.flink.table.types.DataType;
+import org.apache.flink.types.Row;
+
+import org.apache.flink.shaded.curator4.com.google.common.collect.ImmutableMap;
+
+import com.esotericsoftware.kryo.Kryo;
+import com.esotericsoftware.kryo.io.Input;
+import com.esotericsoftware.kryo.io.Output;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+import java.util.PriorityQueue;
+
+import static org.apache.flink.ml.classification.knn.KnnUtil.castTo;
+import static org.apache.flink.ml.classification.knn.KnnUtil.serializeResult;
+import static org.apache.flink.ml.classification.knn.KnnUtil.updateQueue;
+
+/** knn model data, which will be used to calculate the distances between
nodes. */
+public class KnnModelData implements Serializable, Cloneable {
+ private static final long serialVersionUID = -2940551481683238630L;
+ private final List<FastDistanceMatrixData> dictData;
+ private final EuclideanDistance fastDistance;
+ protected Comparator<? super Tuple2<Double, Object>> comparator;
+ private DataType idType;
+
+ /**
+ * constructor.
+ *
+ * @param list BaseFastDistanceData list.
+ * @param fastDistance used to accelerate the speed of calculating
distance.
+ */
+ public KnnModelData(List<FastDistanceMatrixData> list, EuclideanDistance
fastDistance) {
+ this.dictData = list;
+ this.fastDistance = fastDistance;
+ comparator = Comparator.comparingDouble(o -> -o.f0);
+ }
+
+ /**
+ * set id type.
+ *
+ * @param idType id type.
+ */
+ public void setIdType(DataType idType) {
+ this.idType = idType;
+ }
+
+ /**
+ * find the nearest topN neighbors from whole nodes.
+ *
+ * @param input input node.
+ * @param topN top N.
+ * @param radius the parameter to describe the range to find neighbors.
+ * @return
+ */
+ public String findNeighbor(Object input, Integer topN, Double radius) {
Review comment:
the calculation is using model to predict.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]