{"action":"created","comment":{"url":"https://api.github.com/repos/google/rappor/pulls/comments/28707479","id":28707479,"diff_hunk":"@@ -0,0 +1,155 @@\n+#!/usr/bin/Rscript\n+#\n+# Copyright 2015 Google Inc. All rights reserved.\n+# \n+# Licensed under the Apache License, Version 2.0 (the \"License\");\n+# you may not use this file except in compliance with the License.\n+# 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+library(\"optparse\")\n+\n+# First parse args\n+options(stringsAsFactors = FALSE)\n+if(!interactive()) {\n+  option_list <- list(\n+    # Flags\n+    make_option(c(\"--map1\", \"-m1\"), default = \"map_1.csv\",\n+                help = \"1st map filename\"),\n+    make_option(c(\"--map2\", \"-m2\"), default = \"map_2.csv\",\n+                help = \"2nd map filename\"),\n+    make_option(c(\"--reports\", \"-r\"), default = \"reports.csv\",\n+                help = \"Filename for reports\"),\n+    make_option(c(\"--params\", \"-p\"), default = \"params.csv\",\n+                help = \"Filename for parameters\")\n+  )\n+  opts <- parse_args(OptionParser(option_list = option_list))\n+}    \n+\n+source(\"../analysis/R/encode.R\")\n+source(\"../analysis/R/decode.R\")\n+source(\"../analysis/R/simulation.R\")\n+source(\"../analysis/R/read_input.R\")\n+source(\"../analysis/R/association.R\")\n+\n+# This function caches the .csv as an .rda for faster loading.  NOTE: It\n+# assumes the map csv file is immutable. This isn't true if you\n+# re-run assoc_sim.R. Adjust immutable_flag as required.\n+# Modified from analysis/R/read_input.R to load 2 or more map files\n+# into the environment\n+LoadMapFiles <- function(map_file, map_file2, params = NULL, \n+                         immutable_flag = FALSE, quote = \"\") {\n+  if (immutable_flag == FALSE) {\n+    # Read map files without caching them\n+    cat(\"Parsing\", map_file, \"and\", map_file2, \"...\\n\")\n+    map1 <- ReadMapFile(map_file, params = params, quote = quote)\n+    map2 <- ReadMapFile(map_file2, params = params, quote = quote)\n+    # association.R requires an rmap component that combines all\n+    # cohort maps\n+    # map$map should be split by cohorts\n+    map1$rmap <- map1$map\n+    map2$rmap <- map2$map\n+    split_map <- function(i, map_struct) {\n+      numbits <- params$k\n+      indices <- which(as.matrix(\n+          map_struct[((i - 1) * numbits + 1):(i * numbits),]) == TRUE,\n+          arr.ind = TRUE)\n+      sparseMatrix(indices[, \"row\"], indices[, \"col\"],\n+                   dims = c(numbits, max(indices[, \"col\"])))\n+    }\n+    # Apply the split_map function #cohorts (params$m) times\n+    map1$map <- lapply(1:params$m, function(i) split_map(i, map1$rmap))\n+    map2$map <- lapply(1:params$m, function(i) split_map(i, map2$rmap))\n+    map <- list()\n+    map[[1]] <- map1\n+    map[[2]] <- map2\n+    # Load maps to env when not storing it in .rda file\n+    e <- globalenv()\n+    e$map <- map\n+  } else {\n+    # Reads the map file and creates an R binary .rda.\n+    # If .rda file already exists, just loads that file.\n+    \n+    rda_file1 <- sub(\".csv\", \"\", map_file, fixed = TRUE)\n+    rda_file2 <- sub(\".csv\", \".rda\", map_file2, fixed = TRUE)\n+    rda_file <- paste(rda_file1, rda_file2, sep = \"_\")\n+    \n+    if (!file.exists(rda_file)) {\n+      cat(\"Parsing\", map_file, \"and\", map_file2, \"...\\n\")\n+      map1 <- ReadMapFile(map_file, params = params, quote = quote)\n+      map2 <- ReadMapFile(map_file2, params = params, quote = quote)\n+      # association.R requires an rmap component that combines all\n+      # cohort maps\n+      # map$map should be split by cohorts\n+      map1$rmap <- map1$map\n+      map2$rmap <- map2$map\n+      split_map <- function(i, map_struct) {\n+        numbits <- params$k\n+        indices <- which(as.matrix(\n+          map_struct[((i - 1) * numbits + 1):(i * numbits),]) == TRUE,\n+          arr.ind = TRUE)\n+        sparseMatrix(indices[, \"row\"], indices[, \"col\"],\n+                     dims = c(numbits, max(indices[, \"col\"])))\n+      }\n+      # Apply the split_map function #cohorts (params$m) times\n+      map1$map <- lapply(1:params$m, function(i) split_map(i, map1$rmap))\n+      map2$map <- lapply(1:params$m, function(i) split_map(i, map2$rmap))\n+      map <- list()\n+      map[[1]] <- map1\n+      map[[2]] <- map2\n+      save(map, file = file.path(tempdir(), basename(rda_file)))\n+      file.copy(file.path(tempdir(), basename(rda_file)), rda_file,\n+                overwrite = TRUE)\n+    }\n+    load(rda_file, .GlobalEnv)\n+  }\n+}\n+\n+main <- function(opts) {\n+  ptm <- proc.time()\n+  \n+  params <- ReadParameterFile(opts$params)\n+  LoadMapFiles(opts$map1, opts$map2, params = params,\n+               immutable_flag = FALSE)\n+  reportsObj <- read.csv(opts$reports, \n+                         colClasses = c(\"integer\", \"character\", \"character\"),","path":"tests/analyze_assoc.R","position":122,"original_position":122,"commit_id":"b5c3b0a792e7686cb52908aa1672ad10b9fcaf75","original_commit_id":"b5c3b0a792e7686cb52908aa1672ad10b9fcaf75","user":{"login":"ananthr","id":360524,"avatar_url":"https://avatars.githubusercontent.com/u/360524?v=3","gravatar_id":"","url":"https://api.github.com/users/ananthr","html_url":"https://github.com/ananthr","followers_url":"https://api.github.com/users/ananthr/followers","following_url":"https://api.github.com/users/ananthr/following{/other_user}","gists_url":"https://api.github.com/users/ananthr/gists{/gist_id}","starred_url":"https://api.github.com/users/ananthr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ananthr/subscriptions","organizations_url":"https://api.github.com/users/ananthr/orgs","repos_url":"https://api.github.com/users/ananthr/repos","events_url":"https://api.github.com/users/ananthr/events{/privacy}","received_events_url":"https://api.github.com/users/ananthr/received_events","type":"User","site_admin":false},"body":"Done.","created_at":"2015-04-20T17:04:57Z","updated_at":"2015-04-20T17:04:57Z","html_url":"https://github.com/google/rappor/pull/35#discussion_r28707479","pull_request_url":"https://api.github.com/repos/google/rappor/pulls/35","_links":{"self":{"href":"https://api.github.com/repos/google/rappor/pulls/comments/28707479"},"html":{"href":"https://github.com/google/rappor/pull/35#discussion_r28707479"},"pull_request":{"href":"https://api.github.com/repos/google/rappor/pulls/35"}}},"pull_request":{"url":"https://api.github.com/repos/google/rappor/pulls/35","id":33402218,"html_url":"https://github.com/google/rappor/pull/35","diff_url":"https://github.com/google/rappor/pull/35.diff","patch_url":"https://github.com/google/rappor/pull/35.patch","issue_url":"https://api.github.com/repos/google/rappor/issues/35","number":35,"state":"open","locked":false,"title":"Basic outline for association demo.","user":{"login":"ananthr","id":360524,"avatar_url":"https://avatars.githubusercontent.com/u/360524?v=3","gravatar_id":"","url":"https://api.github.com/users/ananthr","html_url":"https://github.com/ananthr","followers_url":"https://api.github.com/users/ananthr/followers","following_url":"https://api.github.com/users/ananthr/following{/other_user}","gists_url":"https://api.github.com/users/ananthr/gists{/gist_id}","starred_url":"https://api.github.com/users/ananthr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ananthr/subscriptions","organizations_url":"https://api.github.com/users/ananthr/orgs","repos_url":"https://api.github.com/users/ananthr/repos","events_url":"https://api.github.com/users/ananthr/events{/privacy}","received_events_url":"https://api.github.com/users/ananthr/received_events","type":"User","site_admin":false},"body":"Currently, the demo only supports 2 correlated variables.\r\n\r\nassoc_sim.R:\r\n- reads a candidate file to get list of candidates of 2 variables\r\n- simulates correlated distributions over these 2 variables (either poisson- or uniform-based)\r\n- generates map, reports files to be used as inputs to association analysis\r\n\r\nanalyze_assoc.R\r\n- reads 2 map files, params file, and reports\r\n- runs EM algorithm to estimate a joint distribution of these 2 variables\r\n- outputs results to stdout\r\n\r\nBoth parts of the demo also return timing info measured in R using proc.time()","created_at":"2015-04-15T22:16:59Z","updated_at":"2015-04-20T17:04:57Z","closed_at":null,"merged_at":null,"merge_commit_sha":"53094e4f934ddebf6cada6fd37fa863278a0e673","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/google/rappor/pulls/35/commits","review_comments_url":"https://api.github.com/repos/google/rappor/pulls/35/comments","review_comment_url":"https://api.github.com/repos/google/rappor/pulls/comments{/number}","comments_url":"https://api.github.com/repos/google/rappor/issues/35/comments","statuses_url":"https://api.github.com/repos/google/rappor/statuses/b5c3b0a792e7686cb52908aa1672ad10b9fcaf75","head":{"label":"google:feature/assoc-demo","ref":"feature/assoc-demo","sha":"b5c3b0a792e7686cb52908aa1672ad10b9fcaf75","user":{"login":"google","id":1342004,"avatar_url":"https://avatars.githubusercontent.com/u/1342004?v=3","gravatar_id":"","url":"https://api.github.com/users/google","html_url":"https://github.com/google","followers_url":"https://api.github.com/users/google/followers","following_url":"https://api.github.com/users/google/following{/other_user}","gists_url":"https://api.github.com/users/google/gists{/gist_id}","starred_url":"https://api.github.com/users/google/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/google/subscriptions","organizations_url":"https://api.github.com/users/google/orgs","repos_url":"https://api.github.com/users/google/repos","events_url":"https://api.github.com/users/google/events{/privacy}","received_events_url":"https://api.github.com/users/google/received_events","type":"Organization","site_admin":false},"repo":{"id":25319462,"name":"rappor","full_name":"google/rappor","owner":{"login":"google","id":1342004,"avatar_url":"https://avatars.githubusercontent.com/u/1342004?v=3","gravatar_id":"","url":"https://api.github.com/users/google","html_url":"https://github.com/google","followers_url":"https://api.github.com/users/google/followers","following_url":"https://api.github.com/users/google/following{/other_user}","gists_url":"https://api.github.com/users/google/gists{/gist_id}","starred_url":"https://api.github.com/users/google/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/google/subscriptions","organizations_url":"https://api.github.com/users/google/orgs","repos_url":"https://api.github.com/users/google/repos","events_url":"https://api.github.com/users/google/events{/privacy}","received_events_url":"https://api.github.com/users/google/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/google/rappor","description":"RAPPOR: Privacy-Preserving Reporting Algorithms","fork":false,"url":"https://api.github.com/repos/google/rappor","forks_url":"https://api.github.com/repos/google/rappor/forks","keys_url":"https://api.github.com/repos/google/rappor/keys{/key_id}","collaborators_url":"https://api.github.com/repos/google/rappor/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/google/rappor/teams","hooks_url":"https://api.github.com/repos/google/rappor/hooks","issue_events_url":"https://api.github.com/repos/google/rappor/issues/events{/number}","events_url":"https://api.github.com/repos/google/rappor/events","assignees_url":"https://api.github.com/repos/google/rappor/assignees{/user}","branches_url":"https://api.github.com/repos/google/rappor/branches{/branch}","tags_url":"https://api.github.com/repos/google/rappor/tags","blobs_url":"https://api.github.com/repos/google/rappor/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/google/rappor/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/google/rappor/git/refs{/sha}","trees_url":"https://api.github.com/repos/google/rappor/git/trees{/sha}","statuses_url":"https://api.github.com/repos/google/rappor/statuses/{sha}","languages_url":"https://api.github.com/repos/google/rappor/languages","stargazers_url":"https://api.github.com/repos/google/rappor/stargazers","contributors_url":"https://api.github.com/repos/google/rappor/contributors","subscribers_url":"https://api.github.com/repos/google/rappor/subscribers","subscription_url":"https://api.github.com/repos/google/rappor/subscription","commits_url":"https://api.github.com/repos/google/rappor/commits{/sha}","git_commits_url":"https://api.github.com/repos/google/rappor/git/commits{/sha}","comments_url":"https://api.github.com/repos/google/rappor/comments{/number}","issue_comment_url":"https://api.github.com/repos/google/rappor/issues/comments{/number}","contents_url":"https://api.github.com/repos/google/rappor/contents/{+path}","compare_url":"https://api.github.com/repos/google/rappor/compare/{base}...{head}","merges_url":"https://api.github.com/repos/google/rappor/merges","archive_url":"https://api.github.com/repos/google/rappor/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/google/rappor/downloads","issues_url":"https://api.github.com/repos/google/rappor/issues{/number}","pulls_url":"https://api.github.com/repos/google/rappor/pulls{/number}","milestones_url":"https://api.github.com/repos/google/rappor/milestones{/number}","notifications_url":"https://api.github.com/repos/google/rappor/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/google/rappor/labels{/name}","releases_url":"https://api.github.com/repos/google/rappor/releases{/id}","created_at":"2014-10-16T20:05:27Z","updated_at":"2015-04-19T04:23:20Z","pushed_at":"2015-04-19T04:23:20Z","git_url":"git://github.com/google/rappor.git","ssh_url":"git@github.com:google/rappor.git","clone_url":"https://github.com/google/rappor.git","svn_url":"https://github.com/google/rappor","homepage":"","size":1961,"stargazers_count":109,"watchers_count":109,"language":"R","has_issues":true,"has_downloads":false,"has_wiki":false,"has_pages":true,"forks_count":18,"mirror_url":null,"open_issues_count":17,"forks":18,"open_issues":17,"watchers":109,"default_branch":"master"}},"base":{"label":"google:master","ref":"master","sha":"5f144eec137e284b5be694618e78dc471cad4af8","user":{"login":"google","id":1342004,"avatar_url":"https://avatars.githubusercontent.com/u/1342004?v=3","gravatar_id":"","url":"https://api.github.com/users/google","html_url":"https://github.com/google","followers_url":"https://api.github.com/users/google/followers","following_url":"https://api.github.com/users/google/following{/other_user}","gists_url":"https://api.github.com/users/google/gists{/gist_id}","starred_url":"https://api.github.com/users/google/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/google/subscriptions","organizations_url":"https://api.github.com/users/google/orgs","repos_url":"https://api.github.com/users/google/repos","events_url":"https://api.github.com/users/google/events{/privacy}","received_events_url":"https://api.github.com/users/google/received_events","type":"Organization","site_admin":false},"repo":{"id":25319462,"name":"rappor","full_name":"google/rappor","owner":{"login":"google","id":1342004,"avatar_url":"https://avatars.githubusercontent.com/u/1342004?v=3","gravatar_id":"","url":"https://api.github.com/users/google","html_url":"https://github.com/google","followers_url":"https://api.github.com/users/google/followers","following_url":"https://api.github.com/users/google/following{/other_user}","gists_url":"https://api.github.com/users/google/gists{/gist_id}","starred_url":"https://api.github.com/users/google/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/google/subscriptions","organizations_url":"https://api.github.com/users/google/orgs","repos_url":"https://api.github.com/users/google/repos","events_url":"https://api.github.com/users/google/events{/privacy}","received_events_url":"https://api.github.com/users/google/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/google/rappor","description":"RAPPOR: Privacy-Preserving Reporting Algorithms","fork":false,"url":"https://api.github.com/repos/google/rappor","forks_url":"https://api.github.com/repos/google/rappor/forks","keys_url":"https://api.github.com/repos/google/rappor/keys{/key_id}","collaborators_url":"https://api.github.com/repos/google/rappor/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/google/rappor/teams","hooks_url":"https://api.github.com/repos/google/rappor/hooks","issue_events_url":"https://api.github.com/repos/google/rappor/issues/events{/number}","events_url":"https://api.github.com/repos/google/rappor/events","assignees_url":"https://api.github.com/repos/google/rappor/assignees{/user}","branches_url":"https://api.github.com/repos/google/rappor/branches{/branch}","tags_url":"https://api.github.com/repos/google/rappor/tags","blobs_url":"https://api.github.com/repos/google/rappor/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/google/rappor/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/google/rappor/git/refs{/sha}","trees_url":"https://api.github.com/repos/google/rappor/git/trees{/sha}","statuses_url":"https://api.github.com/repos/google/rappor/statuses/{sha}","languages_url":"https://api.github.com/repos/google/rappor/languages","stargazers_url":"https://api.github.com/repos/google/rappor/stargazers","contributors_url":"https://api.github.com/repos/google/rappor/contributors","subscribers_url":"https://api.github.com/repos/google/rappor/subscribers","subscription_url":"https://api.github.com/repos/google/rappor/subscription","commits_url":"https://api.github.com/repos/google/rappor/commits{/sha}","git_commits_url":"https://api.github.com/repos/google/rappor/git/commits{/sha}","comments_url":"https://api.github.com/repos/google/rappor/comments{/number}","issue_comment_url":"https://api.github.com/repos/google/rappor/issues/comments{/number}","contents_url":"https://api.github.com/repos/google/rappor/contents/{+path}","compare_url":"https://api.github.com/repos/google/rappor/compare/{base}...{head}","merges_url":"https://api.github.com/repos/google/rappor/merges","archive_url":"https://api.github.com/repos/google/rappor/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/google/rappor/downloads","issues_url":"https://api.github.com/repos/google/rappor/issues{/number}","pulls_url":"https://api.github.com/repos/google/rappor/pulls{/number}","milestones_url":"https://api.github.com/repos/google/rappor/milestones{/number}","notifications_url":"https://api.github.com/repos/google/rappor/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/google/rappor/labels{/name}","releases_url":"https://api.github.com/repos/google/rappor/releases{/id}","created_at":"2014-10-16T20:05:27Z","updated_at":"2015-04-19T04:23:20Z","pushed_at":"2015-04-19T04:23:20Z","git_url":"git://github.com/google/rappor.git","ssh_url":"git@github.com:google/rappor.git","clone_url":"https://github.com/google/rappor.git","svn_url":"https://github.com/google/rappor","homepage":"","size":1961,"stargazers_count":109,"watchers_count":109,"language":"R","has_issues":true,"has_downloads":false,"has_wiki":false,"has_pages":true,"forks_count":18,"mirror_url":null,"open_issues_count":17,"forks":18,"open_issues":17,"watchers":109,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/google/rappor/pulls/35"},"html":{"href":"https://github.com/google/rappor/pull/35"},"issue":{"href":"https://api.github.com/repos/google/rappor/issues/35"},"comments":{"href":"https://api.github.com/repos/google/rappor/issues/35/comments"},"review_comments":{"href":"https://api.github.com/repos/google/rappor/pulls/35/comments"},"review_comment":{"href":"https://api.github.com/repos/google/rappor/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/google/rappor/pulls/35/commits"},"statuses":{"href":"https://api.github.com/repos/google/rappor/statuses/b5c3b0a792e7686cb52908aa1672ad10b9fcaf75"}}}}