Skip to content

Commit

Permalink
Prepare for CRAN (#4)
Browse files Browse the repository at this point in the history
* Update

* Update

* Refix
  • Loading branch information
teramonagi authored and shinichi-takayanagi committed Apr 17, 2019
1 parent 0e26772 commit e27496d
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 5 deletions.
5 changes: 4 additions & 1 deletion .Rbuildignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
^cran-comments\.md$
^.*\.Rproj$
^\.Rproj\.user$
^README\.Rmd$
^\.travis\.yml$
^cran-comments\.md$
^docs$
6 changes: 3 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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) <doi:10.1145/2487575.2487623>).
URL: https://github.com/shinichi-takayanagi/frequentdirections
BugReports: https://github.com/shinichi-takayanagi/frequentdirections/issues
License: MIT + file LICENSE
Expand Down
4 changes: 3 additions & 1 deletion R/frequentdirections.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down
16 changes: 16 additions & 0 deletions inst/examples/example.R
Original file line number Diff line number Diff line change
@@ -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)
18 changes: 18 additions & 0 deletions man/plot_svd.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions man/sketching.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e27496d

Please sign in to comment.