Fanoid commented on code in PR #191:
URL: https://github.com/apache/flink-ml/pull/191#discussion_r1050354918


##########
flink-ml-lib/src/main/java/org/apache/flink/ml/feature/lsh/MinHashLSHModelData.java:
##########
@@ -0,0 +1,209 @@
+/*
+ * 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.feature.lsh;
+
+import org.apache.flink.api.common.serialization.Encoder;
+import org.apache.flink.api.common.typeinfo.TypeInformation;
+import org.apache.flink.api.common.typeutils.base.IntSerializer;
+import 
org.apache.flink.api.common.typeutils.base.array.IntPrimitiveArraySerializer;
+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.core.memory.DataInputViewStreamWrapper;
+import org.apache.flink.core.memory.DataOutputView;
+import org.apache.flink.core.memory.DataOutputViewStreamWrapper;
+import org.apache.flink.ml.linalg.DenseVector;
+import org.apache.flink.ml.linalg.SparseVector;
+import org.apache.flink.ml.linalg.Vector;
+import org.apache.flink.util.Preconditions;
+
+import java.io.EOFException;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.util.Arrays;
+import java.util.Random;
+
+/**
+ * Model data of {@link MinHashLSHModel}.
+ *
+ * <p>This class also provides classes to save/load model data.
+ */
+public class MinHashLSHModelData implements LSHScheme {
+
+    // A large prime smaller than sqrt(2^63 − 1)
+    private static final int HASH_PRIME = 2038074743;
+
+    public int numHashTables;
+    public int numHashFunctionsPerTable;
+    public int[] randCoeffA;
+    public int[] randCoeffB;
+
+    public MinHashLSHModelData() {}
+
+    public MinHashLSHModelData(
+            int numHashTables, int numHashFunctionsPerTable, int[] randCoeffA, 
int[] randCoeffB) {
+        this.numHashTables = numHashTables;
+        this.numHashFunctionsPerTable = numHashFunctionsPerTable;
+        this.randCoeffA = randCoeffA;
+        this.randCoeffB = randCoeffB;
+    }
+
+    public static MinHashLSHModelData generateModelData(

Review Comment:
   If the random seed is unchanged, the coefficients are deterministic. 
   
   Yet, there are some reasons, I think, making storing coefficients more 
suitable:
   1. In concept, coefficients are part of MinHash LSH model, while the seed is 
not.
   2. It might happen that users set a different random seed for the model, 
which creates a totally different model without fitting.
   3. There is a chance that the model data is used outside Java ecosystem. In 
this situation, it is hard to reproduce the same model.



-- 
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]

Reply via email to