{"action":"created","comment":{"url":"https://api.github.com/repos/apache/spark/pulls/comments/82635900","pull_request_review_id":3529820,"id":82635900,"diff_hunk":"@@ -0,0 +1,107 @@\n+/*\n+ * Licensed to the Apache Software Foundation (ASF) under one or more\n+ * contributor license agreements.  See the NOTICE file distributed with\n+ * this work for additional information regarding copyright ownership.\n+ * The ASF licenses this file to You under the Apache License, Version 2.0\n+ * (the \"License\"); you may not use this file except in compliance with\n+ * the License.  You may obtain a copy of the License at\n+ *\n+ *    http://www.apache.org/licenses/LICENSE-2.0\n+ *\n+ * Unless required by applicable law or agreed to in writing, software\n+ * distributed under the License is distributed on an \"AS IS\" BASIS,\n+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n+ * See the License for the specific language governing permissions and\n+ * limitations under the License.\n+ */\n+\n+package org.apache.spark.ml.feature\n+\n+import scala.util.Random\n+\n+import org.apache.spark.annotation.{Experimental, Since}\n+import org.apache.spark.ml.linalg.{Vector, Vectors, VectorUDT}\n+import org.apache.spark.ml.util.Identifiable\n+import org.apache.spark.sql.types.StructType\n+\n+/**\n+ * Model produced by [[MinHash]]\n+ */\n+@Experimental\n+@Since(\"2.1.0\")\n+class MinHashModel private[ml] (override val uid: String, hashFunctions: Seq[Int => Long])\n+  extends LSHModel[MinHashModel] {\n+\n+  @Since(\"2.1.0\")\n+  override protected[this] val hashFunction: Vector => Vector = {\n+    elems: Vector =>\n+      require(elems.numNonzeros > 0, \"Must have at least 1 non zero entry.\")\n+      Vectors.dense(hashFunctions.map(\n+        func => elems.toSparse.indices.toList.map(func).min.toDouble\n+      ).toArray)\n+  }\n+\n+  @Since(\"2.1.0\")\n+  override protected[ml] def keyDistance(x: Vector, y: Vector): Double = {\n+    val xSet = x.toSparse.indices.toSet\n+    val ySet = y.toSparse.indices.toSet\n+    1 - xSet.intersect(ySet).size.toDouble / xSet.union(ySet).size.toDouble\n+  }\n+\n+  @Since(\"2.1.0\")\n+  override protected[ml] def hashDistance(x: Vector, y: Vector): Double = {\n+    // Since it's generated by hashing, it will be a pair of dense vectors.\n+    x.toDense.values.zip(y.toDense.values).map(x => math.abs(x._1 - x._2)).min\n+  }\n+}\n+\n+/**\n+ * LSH class for Jaccard distance\n+ * The input set should be represented in sparse vector form. For example,\n+ *    Vectors.sparse(10, Array[(2, 1.0), (3, 1.0), (5, 1.0)])\n+ * means there are 10 elements in the space. This set contains elem 2, elem 3 and elem 5\n+ */\n+@Experimental\n+@Since(\"2.1.0\")\n+class MinHash private[ml] (override val uid: String) extends LSH[MinHashModel] {\n+\n+  private[this] val prime = 2038074743\n+\n+  @Since(\"2.1.0\")\n+  override def setInputCol(value: String): this.type = super.setInputCol(value)\n+\n+  @Since(\"2.1.0\")\n+  override def setOutputCol(value: String): this.type = super.setOutputCol(value)\n+\n+  @Since(\"2.1.0\")\n+  override def setOutputDim(value: Int): this.type = super.setOutputDim(value)\n+\n+  private[this] lazy val randSeq: Seq[Int] = {\n+    Seq.fill($(outputDim))(1 + Random.nextInt(prime - 1)).take($(outputDim))","path":"mllib/src/main/scala/org/apache/spark/ml/feature/MinHash.scala","position":null,"original_position":80,"commit_id":"142d8e96f7c7e5ef80b3fe11ada1be9cd499bc8a","original_commit_id":"df198868f8505a307ac2bc1af33ff345f5207be6","user":{"login":"Yunni","id":6089987,"avatar_url":"https://avatars.githubusercontent.com/u/6089987?v=3","gravatar_id":"","url":"https://api.github.com/users/Yunni","html_url":"https://github.com/Yunni","followers_url":"https://api.github.com/users/Yunni/followers","following_url":"https://api.github.com/users/Yunni/following{/other_user}","gists_url":"https://api.github.com/users/Yunni/gists{/gist_id}","starred_url":"https://api.github.com/users/Yunni/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Yunni/subscriptions","organizations_url":"https://api.github.com/users/Yunni/orgs","repos_url":"https://api.github.com/users/Yunni/repos","events_url":"https://api.github.com/users/Yunni/events{/privacy}","received_events_url":"https://api.github.com/users/Yunni/received_events","type":"User","site_admin":false},"body":"Removed.","created_at":"2016-10-10T16:18:16Z","updated_at":"2016-10-10T16:18:16Z","html_url":"https://github.com/apache/spark/pull/15148#discussion_r82635900","pull_request_url":"https://api.github.com/repos/apache/spark/pulls/15148","_links":{"self":{"href":"https://api.github.com/repos/apache/spark/pulls/comments/82635900"},"html":{"href":"https://github.com/apache/spark/pull/15148#discussion_r82635900"},"pull_request":{"href":"https://api.github.com/repos/apache/spark/pulls/15148"}}},"pull_request":{"url":"https://api.github.com/repos/apache/spark/pulls/15148","id":85743693,"html_url":"https://github.com/apache/spark/pull/15148","diff_url":"https://github.com/apache/spark/pull/15148.diff","patch_url":"https://github.com/apache/spark/pull/15148.patch","issue_url":"https://api.github.com/repos/apache/spark/issues/15148","number":15148,"state":"open","locked":false,"title":"[SPARK-5992][ML] Locality Sensitive Hashing","user":{"login":"Yunni","id":6089987,"avatar_url":"https://avatars.githubusercontent.com/u/6089987?v=3","gravatar_id":"","url":"https://api.github.com/users/Yunni","html_url":"https://github.com/Yunni","followers_url":"https://api.github.com/users/Yunni/followers","following_url":"https://api.github.com/users/Yunni/following{/other_user}","gists_url":"https://api.github.com/users/Yunni/gists{/gist_id}","starred_url":"https://api.github.com/users/Yunni/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Yunni/subscriptions","organizations_url":"https://api.github.com/users/Yunni/orgs","repos_url":"https://api.github.com/users/Yunni/repos","events_url":"https://api.github.com/users/Yunni/events{/privacy}","received_events_url":"https://api.github.com/users/Yunni/received_events","type":"User","site_admin":false},"body":"## What changes were proposed in this pull request?\r\n\r\nImplement Locality Sensitive Hashing along with approximate nearest neighbors and approximate similarity join based on the [design doc](https://docs.google.com/document/d/1D15DTDMF_UWTTyWqXfG7y76iZalky4QmifUYQ6lH5GM/edit).\r\n\r\nDetailed changes are as follows:\r\n(1) Implement abstract LSH, LSHModel classes as Estimator-Model\r\n(2) Implement approxNearestNeighbors and approxSimilarityJoin in the abstract LSHModel\r\n(3) Implement Random Projection as LSH subclass for Euclidean distance, Min Hash for Jaccard Distance\r\n(4) Implement unit test utility methods including checkLshProperty, checkNearestNeighbor and checkSimilarityJoin\r\n\r\nThings haven't implemented in this pull request:\r\n(1) LSH subclasses for Hamming Distance, Cosine Distance\r\n(2) PySpark Integration for the scala classes and methods.\r\n\r\n## How was this patch tested?\r\nUnit test is implemented for all the implemented classes and algorithms. A scalability test on Uber's dataset was performed internally.\r\n\r\nTested the methods on [WEX dataset](https://aws.amazon.com/items/2345) from AWS, with the steps and results [here](https://docs.google.com/document/d/19BXg-67U83NVB3M0I84HVBVg3baAVaESD_mrg_-vLro/edit).\r\n\r\n## References\r\nGionis, Aristides, Piotr Indyk, and Rajeev Motwani. \"Similarity search in high dimensions via hashing.\" VLDB 7 Sep. 1999: 518-529.\r\nWang, Jingdong et al. \"Hashing for similarity search: A survey.\" arXiv preprint arXiv:1408.2927 (2014).\r\n","created_at":"2016-09-19T06:38:23Z","updated_at":"2016-10-10T16:18:16Z","closed_at":null,"merged_at":null,"merge_commit_sha":"7177822237f9eb83b16c3a130b88816a526531f4","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/apache/spark/pulls/15148/commits","review_comments_url":"https://api.github.com/repos/apache/spark/pulls/15148/comments","review_comment_url":"https://api.github.com/repos/apache/spark/pulls/comments{/number}","comments_url":"https://api.github.com/repos/apache/spark/issues/15148/comments","statuses_url":"https://api.github.com/repos/apache/spark/statuses/142d8e96f7c7e5ef80b3fe11ada1be9cd499bc8a","head":{"label":"Yunni:SPARK-5992-yunn-lsh","ref":"SPARK-5992-yunn-lsh","sha":"142d8e96f7c7e5ef80b3fe11ada1be9cd499bc8a","user":{"login":"Yunni","id":6089987,"avatar_url":"https://avatars.githubusercontent.com/u/6089987?v=3","gravatar_id":"","url":"https://api.github.com/users/Yunni","html_url":"https://github.com/Yunni","followers_url":"https://api.github.com/users/Yunni/followers","following_url":"https://api.github.com/users/Yunni/following{/other_user}","gists_url":"https://api.github.com/users/Yunni/gists{/gist_id}","starred_url":"https://api.github.com/users/Yunni/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Yunni/subscriptions","organizations_url":"https://api.github.com/users/Yunni/orgs","repos_url":"https://api.github.com/users/Yunni/repos","events_url":"https://api.github.com/users/Yunni/events{/privacy}","received_events_url":"https://api.github.com/users/Yunni/received_events","type":"User","site_admin":false},"repo":{"id":67909681,"name":"spark","full_name":"Yunni/spark","owner":{"login":"Yunni","id":6089987,"avatar_url":"https://avatars.githubusercontent.com/u/6089987?v=3","gravatar_id":"","url":"https://api.github.com/users/Yunni","html_url":"https://github.com/Yunni","followers_url":"https://api.github.com/users/Yunni/followers","following_url":"https://api.github.com/users/Yunni/following{/other_user}","gists_url":"https://api.github.com/users/Yunni/gists{/gist_id}","starred_url":"https://api.github.com/users/Yunni/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Yunni/subscriptions","organizations_url":"https://api.github.com/users/Yunni/orgs","repos_url":"https://api.github.com/users/Yunni/repos","events_url":"https://api.github.com/users/Yunni/events{/privacy}","received_events_url":"https://api.github.com/users/Yunni/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/Yunni/spark","description":"Mirror of Apache Spark","fork":true,"url":"https://api.github.com/repos/Yunni/spark","forks_url":"https://api.github.com/repos/Yunni/spark/forks","keys_url":"https://api.github.com/repos/Yunni/spark/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Yunni/spark/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Yunni/spark/teams","hooks_url":"https://api.github.com/repos/Yunni/spark/hooks","issue_events_url":"https://api.github.com/repos/Yunni/spark/issues/events{/number}","events_url":"https://api.github.com/repos/Yunni/spark/events","assignees_url":"https://api.github.com/repos/Yunni/spark/assignees{/user}","branches_url":"https://api.github.com/repos/Yunni/spark/branches{/branch}","tags_url":"https://api.github.com/repos/Yunni/spark/tags","blobs_url":"https://api.github.com/repos/Yunni/spark/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Yunni/spark/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Yunni/spark/git/refs{/sha}","trees_url":"https://api.github.com/repos/Yunni/spark/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Yunni/spark/statuses/{sha}","languages_url":"https://api.github.com/repos/Yunni/spark/languages","stargazers_url":"https://api.github.com/repos/Yunni/spark/stargazers","contributors_url":"https://api.github.com/repos/Yunni/spark/contributors","subscribers_url":"https://api.github.com/repos/Yunni/spark/subscribers","subscription_url":"https://api.github.com/repos/Yunni/spark/subscription","commits_url":"https://api.github.com/repos/Yunni/spark/commits{/sha}","git_commits_url":"https://api.github.com/repos/Yunni/spark/git/commits{/sha}","comments_url":"https://api.github.com/repos/Yunni/spark/comments{/number}","issue_comment_url":"https://api.github.com/repos/Yunni/spark/issues/comments{/number}","contents_url":"https://api.github.com/repos/Yunni/spark/contents/{+path}","compare_url":"https://api.github.com/repos/Yunni/spark/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Yunni/spark/merges","archive_url":"https://api.github.com/repos/Yunni/spark/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Yunni/spark/downloads","issues_url":"https://api.github.com/repos/Yunni/spark/issues{/number}","pulls_url":"https://api.github.com/repos/Yunni/spark/pulls{/number}","milestones_url":"https://api.github.com/repos/Yunni/spark/milestones{/number}","notifications_url":"https://api.github.com/repos/Yunni/spark/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Yunni/spark/labels{/name}","releases_url":"https://api.github.com/repos/Yunni/spark/releases{/id}","deployments_url":"https://api.github.com/repos/Yunni/spark/deployments","created_at":"2016-09-11T04:17:57Z","updated_at":"2016-09-11T04:18:21Z","pushed_at":"2016-10-10T16:17:29Z","git_url":"git://github.com/Yunni/spark.git","ssh_url":"git@github.com:Yunni/spark.git","clone_url":"https://github.com/Yunni/spark.git","svn_url":"https://github.com/Yunni/spark","homepage":null,"size":184863,"stargazers_count":0,"watchers_count":0,"language":"Scala","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"apache:master","ref":"master","sha":"8f0c35a4d0dd458719627be5f524792bf244d70a","user":{"login":"apache","id":47359,"avatar_url":"https://avatars.githubusercontent.com/u/47359?v=3","gravatar_id":"","url":"https://api.github.com/users/apache","html_url":"https://github.com/apache","followers_url":"https://api.github.com/users/apache/followers","following_url":"https://api.github.com/users/apache/following{/other_user}","gists_url":"https://api.github.com/users/apache/gists{/gist_id}","starred_url":"https://api.github.com/users/apache/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apache/subscriptions","organizations_url":"https://api.github.com/users/apache/orgs","repos_url":"https://api.github.com/users/apache/repos","events_url":"https://api.github.com/users/apache/events{/privacy}","received_events_url":"https://api.github.com/users/apache/received_events","type":"Organization","site_admin":false},"repo":{"id":17165658,"name":"spark","full_name":"apache/spark","owner":{"login":"apache","id":47359,"avatar_url":"https://avatars.githubusercontent.com/u/47359?v=3","gravatar_id":"","url":"https://api.github.com/users/apache","html_url":"https://github.com/apache","followers_url":"https://api.github.com/users/apache/followers","following_url":"https://api.github.com/users/apache/following{/other_user}","gists_url":"https://api.github.com/users/apache/gists{/gist_id}","starred_url":"https://api.github.com/users/apache/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apache/subscriptions","organizations_url":"https://api.github.com/users/apache/orgs","repos_url":"https://api.github.com/users/apache/repos","events_url":"https://api.github.com/users/apache/events{/privacy}","received_events_url":"https://api.github.com/users/apache/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/apache/spark","description":"Mirror of Apache Spark","fork":false,"url":"https://api.github.com/repos/apache/spark","forks_url":"https://api.github.com/repos/apache/spark/forks","keys_url":"https://api.github.com/repos/apache/spark/keys{/key_id}","collaborators_url":"https://api.github.com/repos/apache/spark/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/apache/spark/teams","hooks_url":"https://api.github.com/repos/apache/spark/hooks","issue_events_url":"https://api.github.com/repos/apache/spark/issues/events{/number}","events_url":"https://api.github.com/repos/apache/spark/events","assignees_url":"https://api.github.com/repos/apache/spark/assignees{/user}","branches_url":"https://api.github.com/repos/apache/spark/branches{/branch}","tags_url":"https://api.github.com/repos/apache/spark/tags","blobs_url":"https://api.github.com/repos/apache/spark/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/apache/spark/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/apache/spark/git/refs{/sha}","trees_url":"https://api.github.com/repos/apache/spark/git/trees{/sha}","statuses_url":"https://api.github.com/repos/apache/spark/statuses/{sha}","languages_url":"https://api.github.com/repos/apache/spark/languages","stargazers_url":"https://api.github.com/repos/apache/spark/stargazers","contributors_url":"https://api.github.com/repos/apache/spark/contributors","subscribers_url":"https://api.github.com/repos/apache/spark/subscribers","subscription_url":"https://api.github.com/repos/apache/spark/subscription","commits_url":"https://api.github.com/repos/apache/spark/commits{/sha}","git_commits_url":"https://api.github.com/repos/apache/spark/git/commits{/sha}","comments_url":"https://api.github.com/repos/apache/spark/comments{/number}","issue_comment_url":"https://api.github.com/repos/apache/spark/issues/comments{/number}","contents_url":"https://api.github.com/repos/apache/spark/contents/{+path}","compare_url":"https://api.github.com/repos/apache/spark/compare/{base}...{head}","merges_url":"https://api.github.com/repos/apache/spark/merges","archive_url":"https://api.github.com/repos/apache/spark/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/apache/spark/downloads","issues_url":"https://api.github.com/repos/apache/spark/issues{/number}","pulls_url":"https://api.github.com/repos/apache/spark/pulls{/number}","milestones_url":"https://api.github.com/repos/apache/spark/milestones{/number}","notifications_url":"https://api.github.com/repos/apache/spark/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/apache/spark/labels{/name}","releases_url":"https://api.github.com/repos/apache/spark/releases{/id}","deployments_url":"https://api.github.com/repos/apache/spark/deployments","created_at":"2014-02-25T08:00:08Z","updated_at":"2016-10-10T16:16:01Z","pushed_at":"2016-10-10T16:18:12Z","git_url":"git://github.com/apache/spark.git","ssh_url":"git@github.com:apache/spark.git","clone_url":"https://github.com/apache/spark.git","svn_url":"https://github.com/apache/spark","homepage":null,"size":532624,"stargazers_count":10297,"watchers_count":10297,"language":"Scala","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":9569,"mirror_url":"git://git.apache.org/spark.git","open_issues_count":482,"forks":9569,"open_issues":482,"watchers":10297,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/apache/spark/pulls/15148"},"html":{"href":"https://github.com/apache/spark/pull/15148"},"issue":{"href":"https://api.github.com/repos/apache/spark/issues/15148"},"comments":{"href":"https://api.github.com/repos/apache/spark/issues/15148/comments"},"review_comments":{"href":"https://api.github.com/repos/apache/spark/pulls/15148/comments"},"review_comment":{"href":"https://api.github.com/repos/apache/spark/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/apache/spark/pulls/15148/commits"},"statuses":{"href":"https://api.github.com/repos/apache/spark/statuses/142d8e96f7c7e5ef80b3fe11ada1be9cd499bc8a"}}}}
{"actor":{"display_login":"Yunni"}}