Created
October 29, 2015 15:51
-
-
Save ewoo/4c096a62bcadb5a3280d to your computer and use it in GitHub Desktop.
A Random Projection function using "mlr" package in R.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Written by Adam Acosta | |
randomProjection <- function(A, k) { | |
if (!is.matrix(A)) { | |
tmp <- as.matrix(A) | |
} else { | |
tmp <- A | |
} | |
p <- ncol(tmp) | |
set.seed(as.numeric(format(Sys.time(), '%S'))) | |
R <- matrix(data = rnorm(k), nrow = k, ncol = p) | |
tmp <- apply(tmp, 2, function(x) (x - mean(x)) / sd(x)) | |
as.data.frame(t(R %*% t(tmp))) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
A Package is Available for performing Random Projection in R language
https://cran.r-project.org/web/packages/RandPro/index.html