X-Git-Url: https://git.auder.net/?p=morpheus.git;a=blobdiff_plain;f=pkg%2FR%2Futils.R;fp=pkg%2FR%2Futils.R;h=5b9d999c64b88b1bdcdc0a21f953c5a1dcef0e21;hp=9d026dab1329f2f7dc4e966d207176156951f8dd;hb=ab35f6102896a49e86e853262c0650faa2931638;hpb=4b2f17bb108bab0f263619cfe00eabfb1e9b8860 diff --git a/pkg/R/utils.R b/pkg/R/utils.R index 9d026da..5b9d999 100644 --- a/pkg/R/utils.R +++ b/pkg/R/utils.R @@ -11,10 +11,10 @@ #' normalize(x) #column 1 is 1/sqrt(5) (1 2), #' #and column 2 is 1/sqrt(10) (-1, 3) #' @export -normalize = function(x) +normalize <- function(x) { - x = as.matrix(x) - norm2 = sqrt( colSums(x^2) ) + x <- as.matrix(x) + norm2 <- sqrt( colSums(x^2) ) sweep(x, 2, norm2, '/') } @@ -25,12 +25,12 @@ normalize = function(x) # # @return Matrix of size dxd # -.T_I_I_w = function(Te, w) +.T_I_I_w <- function(Te, w) { - d = length(w) - Ma = matrix(0,nrow=d,ncol=d) + d <- length(w) + Ma <- matrix(0,nrow=d,ncol=d) for (j in 1:d) - Ma = Ma + w[j] * Te[,,j] + Ma <- Ma + w[j] * Te[,,j] Ma } @@ -41,11 +41,11 @@ normalize = function(x) # # @return Matrix of size dxd # -.Moments_M2 = function(X, Y) +.Moments_M2 <- function(X, Y) { - n = nrow(X) - d = ncol(X) - M2 = matrix(0,nrow=d,ncol=d) + n <- nrow(X) + d <- ncol(X) + M2 <- matrix(0,nrow=d,ncol=d) matrix( .C("Moments_M2", X=as.double(X), Y=as.double(Y), pn=as.integer(n), pd=as.integer(d), M2=as.double(M2), PACKAGE="morpheus")$M2, nrow=d, ncol=d) } @@ -57,11 +57,11 @@ normalize = function(x) # # @return Array of size dxdxd # -.Moments_M3 = function(X, Y) +.Moments_M3 <- function(X, Y) { - n = nrow(X) - d = ncol(X) - M3 = array(0,dim=c(d,d,d)) + n <- nrow(X) + d <- ncol(X) + M3 <- array(0,dim=c(d,d,d)) array( .C("Moments_M3", X=as.double(X), Y=as.double(Y), pn=as.integer(n), pd=as.integer(d), M3=as.double(M3), PACKAGE="morpheus")$M3, dim=c(d,d,d) ) } @@ -90,9 +90,9 @@ computeMoments = function(X, Y) # # @return A permutation minimizing cost # -.hungarianAlgorithm = function(distances) +.hungarianAlgorithm <- function(distances) { - n = nrow(distances) + n <- nrow(distances) .C("hungarianAlgorithm", distances=as.double(distances), pn=as.integer(n), assignment=integer(n), PACKAGE="morpheus")$assignment } @@ -120,7 +120,7 @@ computeMoments = function(X, Y) #' # a[[i]] is expected to contain m1 for all i #' #' @export -alignMatrices = function(Ms, ref, ls_mode=c("exact","approx1","approx2")) +alignMatrices <- function(Ms, ref, ls_mode=c("exact","approx1","approx2")) { if (!is.matrix(ref) || any(is.na(ref))) stop("ref: matrix, no NAs") @@ -130,7 +130,7 @@ alignMatrices = function(Ms, ref, ls_mode=c("exact","approx1","approx2")) L <- length(Ms) for (i in 1:L) { - m = Ms[[i]] #shorthand + m <- Ms[[i]] #shorthand if (ls_mode == "exact") {