{"action":"created","comment":{"url":"https://api.github.com/repos/apache/spark/pulls/comments/84589297","pull_request_review_id":5358937,"id":84589297,"diff_hunk":"@@ -0,0 +1,148 @@\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 breeze.numerics.{cos, sin}\n+import breeze.numerics.constants.Pi\n+\n+import org.apache.spark.SparkFunSuite\n+import org.apache.spark.ml.linalg.Vectors\n+import org.apache.spark.mllib.util.MLlibTestSparkContext\n+\n+class RandomProjectionSuite extends SparkFunSuite with MLlibTestSparkContext {\n+  test(\"RandomProjection\") {\n+    val data = {\n+      for (i <- -5 until 5; j <- -5 until 5) yield Vectors.dense(i.toDouble, j.toDouble)\n+    }\n+    val df = spark.createDataFrame(data.map(Tuple1.apply)).toDF(\"keys\")\n+\n+    // Project from 2 dimensional Euclidean Space to 1 dimensions\n+    val rp = new RandomProjection()\n+      .setOutputDim(1)\n+      .setInputCol(\"keys\")\n+      .setOutputCol(\"values\")\n+      .setBucketLength(1.0)\n+      .setSeed(12345)\n+\n+    val (falsePositive, falseNegative) = LSHTest.calculateLSHProperty(df, rp, 8.0, 2.0)\n+    assert(falsePositive < 0.05)\n+    assert(falseNegative < 0.06)\n+  }\n+\n+  test(\"RandomProjection with high dimension data\") {\n+    val numDim = 100\n+    val data = {\n+      for (i <- 0 until numDim; j <- Seq(-2, -1, 1, 2))\n+        yield Vectors.sparse(numDim, Seq((i, j.toDouble)))\n+    }\n+    val df = spark.createDataFrame(data.map(Tuple1.apply)).toDF(\"keys\")\n+\n+    // Project from 100 dimensional Euclidean Space to 10 dimensions\n+    val rp = new RandomProjection()\n+      .setOutputDim(10)\n+      .setInputCol(\"keys\")\n+      .setOutputCol(\"values\")\n+      .setBucketLength(2.5)\n+      .setSeed(12345)\n+\n+    val (falsePositive, falseNegative) = LSHTest.calculateLSHProperty(df, rp, 3.0, 2.0)\n+    assert(falsePositive == 0.0)\n+    assert(falseNegative < 0.05)\n+  }\n+\n+  test(\"approxNearestNeighbors for random projection\") {\n+    val data = {\n+      for (i <- -10 until 10; j <- -10 until 10) yield Vectors.dense(i.toDouble, j.toDouble)\n+    }\n+    val df = spark.createDataFrame(data.map(Tuple1.apply)).toDF(\"keys\")\n+    val key = Vectors.dense(1.2, 3.4)\n+\n+    val rp = new RandomProjection()\n+      .setOutputDim(2)\n+      .setInputCol(\"keys\")\n+      .setOutputCol(\"values\")\n+      .setBucketLength(4.0)\n+      .setSeed(12345)\n+\n+    val (precision, recall) = LSHTest.calculateApproxNearestNeighbors(rp, df, key, 100,\n+      singleProbing = true)\n+    assert(precision >= 0.6)\n+    assert(recall >= 0.6)\n+  }\n+\n+  test(\"approxNearestNeighbors with multiple probing\") {","path":"mllib/src/test/scala/org/apache/spark/ml/feature/RandomProjectionSuite.scala","position":88,"original_position":88,"commit_id":"e14f73e8a49d409e09a6ed541d4b40f07dc81013","original_commit_id":"e14f73e8a49d409e09a6ed541d4b40f07dc81013","user":{"login":"jkbradley","id":5084283,"avatar_url":"https://avatars.githubusercontent.com/u/5084283?v=3","gravatar_id":"","url":"https://api.github.com/users/jkbradley","html_url":"https://github.com/jkbradley","followers_url":"https://api.github.com/users/jkbradley/followers","following_url":"https://api.github.com/users/jkbradley/following{/other_user}","gists_url":"https://api.github.com/users/jkbradley/gists{/gist_id}","starred_url":"https://api.github.com/users/jkbradley/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jkbradley/subscriptions","organizations_url":"https://api.github.com/users/jkbradley/orgs","repos_url":"https://api.github.com/users/jkbradley/repos","events_url":"https://api.github.com/users/jkbradley/events{/privacy}","received_events_url":"https://api.github.com/users/jkbradley/received_events","type":"User","site_admin":false},"body":"If the goal here is to ensure multiple probing is a strict improvement, then I'd combine the unit tests to ensure that the data and Param settings remain the same.  I see the Params are already different, but perhaps they should be made identical.","created_at":"2016-10-23T03:25:17Z","updated_at":"2016-10-23T03:36:27Z","html_url":"https://github.com/apache/spark/pull/15148#discussion_r84589297","pull_request_url":"https://api.github.com/repos/apache/spark/pulls/15148","_links":{"self":{"href":"https://api.github.com/repos/apache/spark/pulls/comments/84589297"},"html":{"href":"https://github.com/apache/spark/pull/15148#discussion_r84589297"},"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 that will be implemented in a follow-up PR:\r\n - Bit Sampling for Hamming Distance, SignRandomProjection for Cosine Distance\r\n - 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-23T03:36:27Z","closed_at":null,"merged_at":null,"merge_commit_sha":"b73a0ac49fe44b7ab84a12f60245fc7e6a40ea2c","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/e14f73e8a49d409e09a6ed541d4b40f07dc81013","head":{"label":"Yunni:SPARK-5992-yunn-lsh","ref":"SPARK-5992-yunn-lsh","sha":"e14f73e8a49d409e09a6ed541d4b40f07dc81013","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-23T01:08:58Z","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":245545,"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":"7222a25a11790fa9d9d1428c84b6f827a785c9e8","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-23T00:21:36Z","pushed_at":"2016-10-23T01:48:13Z","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":601806,"stargazers_count":10459,"watchers_count":10459,"language":"Scala","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":9739,"mirror_url":"git://git.apache.org/spark.git","open_issues_count":483,"forks":9739,"open_issues":483,"watchers":10459,"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/e14f73e8a49d409e09a6ed541d4b40f07dc81013"}}}}
{"actor":{"display_login":"jkbradley"}}