Skip to content
This repository was archived by the owner on Sep 27, 2023. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions analysis/DESCRIPTION
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Package: rappor
Title: R package for Rappor Analysis
Description: R functions used for analyzing Rappor data.
Author: Rappor Discuss <rappor-discuss@googlegroups.com>
Maintainer: Rappor Discuss <rappor-discuss@googlegroups.com>
Copyright: Copyright (C) 2014 Google, Inc.
Version: 0.1
License: Apache License 2.0
Url: https://github.com/google/rappor
Depends: Matrix, RUnit, glmnet, limSolve, parallel
6 changes: 6 additions & 0 deletions analysis/NAMESPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import(Matrix)
import(RUnit)
import(glmnet)
import(limSolve)
import(parallel)
exportPattern("^[^\\.]")
5 changes: 1 addition & 4 deletions analysis/R/alternative.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.

library(limSolve)
library(Matrix)

# The next two functions create a matrix (G) and a vector (H) encoding
# linear inequality constraints that a solution vector (x) must satisfy:
# G * x >= H
Expand Down Expand Up @@ -80,4 +77,4 @@ ConstrainedLinModel <- function(X,Y) {
names(coefs) <- colnames(X)

coefs
}
}
10 changes: 0 additions & 10 deletions analysis/R/association.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.

library(parallel) # mclapply

source.rappor <- function(rel_path) {
abs_path <- paste0(Sys.getenv("RAPPOR_REPO", ""), rel_path)
source(abs_path)
}

source.rappor("analysis/R/util.R") # for Log
source.rappor("analysis/R/decode.R") # for ComputeCounts

#
# Tools used to estimate variable distributions of up to three variables
# in RAPPOR. This contains the functions relevant to estimating joint
Expand Down
13 changes: 1 addition & 12 deletions analysis/R/decode.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

#
# This library implements the RAPPOR marginal decoding algorithms using LASSO.

library(glmnet)

# So we don't have to change pwd
source.rappor <- function(rel_path) {
abs_path <- paste0(Sys.getenv("RAPPOR_REPO", ""), rel_path)
source(abs_path)
}

source.rappor('analysis/R/alternative.R')
# Implements the RAPPOR marginal decoding algorithms using LASSO.

EstimateBloomCounts <- function(params, obs_counts) {
# Estimates the number of times each bit in each cohort was set in original
Expand Down
1 change: 0 additions & 1 deletion analysis/R/decode_ngrams.R
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ FindPairwiseCandidates <- function(report_data, N, ngram_params, params) {

.ComputeDist <- function(i, inds, cohorts, reports, maps, params,
num_ngrams_collected) {
library(glmnet)
ind <- inds[[i]]
cohort_subset <- lapply(1:num_ngrams_collected, function(x)
cohorts[ind])
Expand Down
14 changes: 0 additions & 14 deletions analysis/R/ngrams_simulation.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,6 @@
# dictionary of terms over which we want to learn a distribution. This
# mostly contains functions that aid in the generation of synthetic data.

library(RUnit)
library(parallel)

source("analysis/R/encode.R")
source("analysis/R/decode.R")
source("analysis/R/simulation.R")
source("analysis/R/association.R")
source("analysis/R/decode_ngrams.R")

# The alphabet is the set of all possible characters that will appear in a
# string. Here we use the English alphabet, but one might want to include
# numbers or punctuation marks.
Expand Down Expand Up @@ -240,11 +231,6 @@ EstimateDictionaryTrial <- function(N, str_len, num_strs,
#
# Returns:
# List with recovered and true marginals.

# We call the needed libraries here in order to make them available when this
# function gets called by BorgApply. Otherwise, they do not get included.
library(glmnet)
library(parallel)
sim <- SimulateNGrams(N, ngram_params, str_len, num_strs = num_strs,
alphabet, params, distribution)

Expand Down
10 changes: 0 additions & 10 deletions analysis/R/read_input.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,6 @@
#
# Read parameter, counts and map files.

library(Matrix)

source.rappor <- function(rel_path) {
abs_path <- paste0(Sys.getenv("RAPPOR_REPO", ""), rel_path)
source(abs_path)
}

source.rappor("analysis/R/util.R") # for Log


ReadParameterFile <- function(params_file) {
# Read parameter file. Format:
# k, h, m, p, q, f
Expand Down
3 changes: 0 additions & 3 deletions analysis/R/simulation.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@
# RAPPOR simulation library. Contains code for encoding simulated data and
# creating the map used to encode and decode reports.

library(glmnet)
library(parallel) # mclapply

SetOfStrings <- function(num_strings = 100) {
# Generates a set of strings for simulation purposes.
strs <- paste0("V_", as.character(1:num_strings))
Expand Down
20 changes: 3 additions & 17 deletions bin/decode_assoc.R
Original file line number Diff line number Diff line change
Expand Up @@ -113,26 +113,12 @@ if (!interactive()) {
opts <- ParseOptions()
}

#
# Load libraries and source our own code.
#

library(RJSONIO) # toJSON()

# So we don't have to change pwd
source.rappor <- function(rel_path) {
abs_path <- paste0(Sys.getenv("RAPPOR_REPO", ""), rel_path)
source(abs_path)
}

source.rappor("analysis/R/association.R")
source.rappor("analysis/R/fast_em.R")
source.rappor("analysis/R/read_input.R")
source.rappor("analysis/R/util.R")

options(stringsAsFactors = FALSE)
options(max.print = 100) # So our structure() debug calls look better

library(RJSONIO) # toJSON()
library(rappor)

CreateAssocStringMap <- function(all_cohorts_map, params) {
# Processes the maps loaded using ReadMapFile and turns it into something
# that association.R can use. Namely, we want a map per cohort.
Expand Down
19 changes: 2 additions & 17 deletions bin/decode_dist.R
Original file line number Diff line number Diff line change
Expand Up @@ -56,25 +56,10 @@ if (!interactive()) {
opts <- ParseOptions()
}

#
# Load libraries and source our own code.
#
options(stringsAsFactors = FALSE)

library(RJSONIO)

# So we don't have to change pwd
source.rappor <- function(rel_path) {
abs_path <- paste0(Sys.getenv("RAPPOR_REPO", ""), rel_path)
source(abs_path)
}

source.rappor("analysis/R/read_input.R")
source.rappor("analysis/R/decode.R")
source.rappor("analysis/R/util.R")

source.rappor("analysis/R/alternative.R")

options(stringsAsFactors = FALSE)
library(rappor)


main <- function(opts) {
Expand Down
6 changes: 6 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,16 @@ cpp-client() {
popd
}

r-package() {
R CMD BUILD analysis/
sudo R CMD INSTALL rappor_0.1.tar.gz
}

if test $# -eq 0 ; then
cpp-client
doc
fastrand
r-package
else
"$@"
fi
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,7 @@
# Authors: vpihur@google.com (Vasyl Pihur), fanti@google.com (Giulia Fanti)

library(RUnit)
source("analysis/R/encode.R")
source("analysis/R/decode.R")
source("analysis/R/simulation.R")
source("analysis/R/association.R")
source("analysis/R/fast_em.R")
source("analysis/R/util.R")
library(rappor)

SamplePopulations <- function(N, num_variables = 1, params,
variable_opts) {
Expand Down
4 changes: 2 additions & 2 deletions analysis/R/decode_test.R → tests/RUnit/decode_test.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@

library(RUnit)
library(abind)

source('analysis/R/decode.R')
library(rappor)
source('tests/gen_counts.R')


L1Distance <- function(X, Y) {
# Computes the L1 distance between two named vectors
common <- intersect(names(X), names(Y))
Expand Down
4 changes: 1 addition & 3 deletions analysis/R/run_tests.R → tests/RUnit/run_tests.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,8 @@
#
# Run unit tests for RAPPOR R code.

library(RUnit)

run_tests <- function() {
dirs <- "analysis/R" # Run from root
dirs <- "tests/RUnit" # Run from root
test_suite <- defineTestSuite("rappor", dirs, testFileRegexp = "_test.R$",
testFuncRegexp = "^Test")
stopifnot(isValidTestSuite(test_suite))
Expand Down
8 changes: 2 additions & 6 deletions analysis/R/unknowns_test.R → tests/RUnit/unknowns_test.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,8 @@
# Both tests generate their own data.

library(parallel)
source("analysis/R/encode.R")
source("analysis/R/decode.R")
source("analysis/R/simulation.R")
source("analysis/R/association.R")
source("analysis/R/decode_ngrams.R")
source("analysis/R/ngrams_simulation.R")
library(rappor)

alphabet <- letters
options(warn = -1)

Expand Down
8 changes: 2 additions & 6 deletions tests/analyze_assoc.R
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,7 @@ if(!interactive()) {
opts <- parse_args(OptionParser(option_list = option_list))
}

source("../analysis/R/encode.R")
source("../analysis/R/decode.R")
source("../analysis/R/simulation.R")
source("../analysis/R/read_input.R")
source("../analysis/R/association.R")
library(rappor)

# This function processes the maps loaded using ReadMapFile
# Association analysis requires a map object with a map
Expand Down Expand Up @@ -123,4 +119,4 @@ main <- function(opts) {

if(!interactive()) {
main(opts)
}
}
8 changes: 2 additions & 6 deletions tests/assoc_sim.R
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,9 @@ if(!interactive()) {
help = "Run simulation with uniform distribution")
)
opts <- parse_args(OptionParser(option_list = option_list))
}
}

source("../analysis/R/encode.R")
source("../analysis/R/decode.R")
source("../analysis/R/simulation.R")
source("../analysis/R/read_input.R")
source("../analysis/R/association.R")
library(rappor)

# Read unique values of reports from a csv file
# Inputs: filename. The file is expected to contain two rows of strings
Expand Down
7 changes: 1 addition & 6 deletions tests/compare_dist.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ if (is_main) {
positional_arguments = 3) # input and output
}

library(rappor)
library(ggplot2)

# Use CairoPNG if available. Useful for headless R.
Expand All @@ -47,12 +48,6 @@ if (library(Cairo, quietly = TRUE, logical.return = TRUE)) {
cat('Using png\n')
}

source("analysis/R/read_input.R")
source("analysis/R/decode.R")
source("analysis/R/util.R")

source("analysis/R/alternative.R") # temporary

LoadContext <- function(prefix_case) {
# Creates the context, filling it with privacy parameters
# Arg:
Expand Down
2 changes: 1 addition & 1 deletion tests/gen_counts.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

source('analysis/R/read_input.R')
library(rappor)

RandomPartition <- function(total, weights) {
# Outputs a random partition according to a specified distribution
Expand Down
2 changes: 1 addition & 1 deletion tests/gen_true_values_test.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#
# gen_reports_test.R

source('analysis/R/util.R') # Log()
library(rappor)

source('tests/gen_true_values.R') # module under test

Expand Down