From e27496d70bc6d27fe0407f161327ea28a5533823 Mon Sep 17 00:00:00 2001 From: Nagi Teramo Date: Thu, 18 Apr 2019 06:42:56 +0900 Subject: [PATCH] Prepare for CRAN (#4) * Update * Update * Refix --- .Rbuildignore | 5 ++++- DESCRIPTION | 6 +++--- R/frequentdirections.R | 4 +++- inst/examples/example.R | 16 ++++++++++++++++ man/plot_svd.Rd | 18 ++++++++++++++++++ man/sketching.Rd | 18 ++++++++++++++++++ 6 files changed, 62 insertions(+), 5 deletions(-) create mode 100644 inst/examples/example.R diff --git a/.Rbuildignore b/.Rbuildignore index b436380..13c1c67 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -1,3 +1,6 @@ -^cran-comments\.md$ ^.*\.Rproj$ ^\.Rproj\.user$ +^README\.Rmd$ +^\.travis\.yml$ +^cran-comments\.md$ +^docs$ diff --git a/DESCRIPTION b/DESCRIPTION index 0f177db..c12c67a 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,13 +1,13 @@ Package: frequentdirections Type: Package -Title: Implementation of Frequent-Directions algorithm for efficient matrix sketching [E. Liberty, SIGKDD2013] +Title: Implementation of Frequent-Directions Algorithm for Efficient Matrix Sketching Version: 0.1.0 Authors@R: c( person("Shinichi", "Takayanagi", , "shinichi.takayanagi@gmail.com", role = c("aut", "cre")), person("Nagi", "Teramo", , "teramonagi@gmail.com", role = c("aut")) ) -Description: Implementation of Frequent-Directions algorithm - for efficient matrix sketching [E. Liberty, SIGKDD2013] +Description: Implement frequent-directions algorithm for efficient matrix sketching. + (Edo Liberty (2013) ). URL: https://github.com/shinichi-takayanagi/frequentdirections BugReports: https://github.com/shinichi-takayanagi/frequentdirections/issues License: MIT + file LICENSE diff --git a/R/frequentdirections.R b/R/frequentdirections.R index e58a3ba..d5793b3 100644 --- a/R/frequentdirections.R +++ b/R/frequentdirections.R @@ -9,6 +9,7 @@ all_zero_row_index <- function(x, eps){ #' @param a Original matrix to be sketched (n x m) #' @param l The number of rows in sketched matrix (l x m) #' @param eps If a value is smaller than eps, that is considered as equal to zero. The default value is 10^(-8) +#' @example inst/examples/example.R #' @export sketching <- function(a, l, eps=10^(-8)){ m <- ncol(a) @@ -44,6 +45,7 @@ sketching <- function(a, l, eps=10^(-8)){ #' @param a Original matrix to be sketched (n x m) #' @param label Group index for each a's row. These values are used for group and color. #' @param b A sketched matrix (l x m) +#' @example inst/examples/example.R #' @export plot_svd <- function(a, label = NULL, b = a){ v <- svd(b)$v @@ -53,7 +55,7 @@ plot_svd <- function(a, label = NULL, b = a){ # Projection matrix(x_p = XV = UΣ) and plot x <- a %*% v[,1:2] df <- data.frame(x = x[,1], y = x[,2]) - ggobj <- ggplot2::ggplot(df, ggplot2::aes(x=x, y=y)) + + ggobj <- ggplot2::ggplot(df, ggplot2::aes_string(x="x", y="y")) + ggplot2::labs(x = "The first singular vector", y = "The second singular vector") ggobj + if(!is.null(label)){ label <- as.character(label) diff --git a/inst/examples/example.R b/inst/examples/example.R new file mode 100644 index 0000000..2213929 --- /dev/null +++ b/inst/examples/example.R @@ -0,0 +1,16 @@ +# Dummy data +size_col <- 50 +size_row <- 10^3 +x <- matrix( + c(rnorm(size_row * size_col), rnorm(size_row * size_col, mean=1)), + ncol = size_col, byrow = TRUE +) +x <- scale(x) +y <- rep(1:2, each=size_row) +# Show 2D plot using SVD +frequentdirections::plot_svd(x, y) +# Matrix Skethinc(l=6) +b <- frequentdirections::sketching(x, 6, 10^(-8)) +# Show 2D plot using sketched matrix and show similar result with the above +# That means that 6 dim is enough to express the original data matrix (x) +frequentdirections::plot_svd(x, y, b) diff --git a/man/plot_svd.Rd b/man/plot_svd.Rd index bb7f581..225bf96 100644 --- a/man/plot_svd.Rd +++ b/man/plot_svd.Rd @@ -16,3 +16,21 @@ plot_svd(a, label = NULL, b = a) \description{ Plot data using the first and second singular vector } +\examples{ +# Dummy data +size_col <- 50 +size_row <- 10^3 +x <- matrix( + c(rnorm(size_row * size_col), rnorm(size_row * size_col, mean=1)), + ncol = size_col, byrow = TRUE +) +x <- scale(x) +y <- rep(1:2, each=size_row) +# Show 2D plot using SVD +frequentdirections::plot_svd(x, y) +# Matrix Skethinc(l=6) +b <- frequentdirections::sketching(x, 6, 10^(-8)) +# Show 2D plot using sketched matrix and show similar result with the above +# That means that 6 dim is enough to express the original data matrix (x) +frequentdirections::plot_svd(x, y, b) +} diff --git a/man/sketching.Rd b/man/sketching.Rd index 2dcc255..d83ff8d 100644 --- a/man/sketching.Rd +++ b/man/sketching.Rd @@ -16,3 +16,21 @@ sketching(a, l, eps = 10^(-8)) \description{ Compute a sketch matrix of input matrix } +\examples{ +# Dummy data +size_col <- 50 +size_row <- 10^3 +x <- matrix( + c(rnorm(size_row * size_col), rnorm(size_row * size_col, mean=1)), + ncol = size_col, byrow = TRUE +) +x <- scale(x) +y <- rep(1:2, each=size_row) +# Show 2D plot using SVD +frequentdirections::plot_svd(x, y) +# Matrix Skethinc(l=6) +b <- frequentdirections::sketching(x, 6, 10^(-8)) +# Show 2D plot using sketched matrix and show similar result with the above +# That means that 6 dim is enough to express the original data matrix (x) +frequentdirections::plot_svd(x, y, b) +}