search for: tcrossprod

Displaying 20 results from an estimated 61 matches for "tcrossprod".

Did you mean: crossprod
2008 May 01
4
efficient code - yet another question
...while (!ende) { nr <- nr + 1 ph <- t(crossprod(th, Xh) * as.vector(1 / crossprod(th))) ph <- ph * as.vector(1/sqrt(crossprod(ph))) thnew <- t(tcrossprod(t(ph), Xh) * as.vector(1/(crossprod(ph)))) prec <- crossprod(th-thnew) th <- thnew if (prec <= (tol^2)) ende <- TRUE if (it <= nr) ende <- TRUE # didn't converge...
2015 Mar 19
0
RFC: Matrix package: Matrix products (%*%, crossprod, tcrossprod) involving "nsparseMatrix" aka sparse pattern matrices
...ay still seem surprising that matrix multiplication does > not behave numerically for a pair of such matrices, and by the > principle of "least surprise" we should provide the boolean arithmetic > matrix products in another way than by the standard %*%, > crossprod() and tcrossprod() functions. > So one possibility could be to change the standard functions to behave > numerically, > and e.g., use %&% (replace the numeric "*" by a logical "&") and > crossprod(A,B, boolean=TRUE), tcrossprod(A,B, boolean=TRUE) > for the three bool...
2015 Mar 20
0
RFC: Matrix package: Matrix products (%*%, crossprod, tcrossprod) involving "nsparseMatrix" aka sparse pattern matrices
...ay still seem surprising that matrix multiplication does > not behave numerically for a pair of such matrices, and by the > principle of "least surprise" we should provide the boolean arithmetic > matrix products in another way than by the standard %*%, > crossprod() and tcrossprod() functions. > So one possibility could be to change the standard functions to behave > numerically, > and e.g., use %&% (replace the numeric "*" by a logical "&") and > crossprod(A,B, boolean=TRUE), tcrossprod(A,B, boolean=TRUE) > for the three bool...
2011 Sep 14
3
make check reg-tests-1b.R fails with Ubuntu R
...d graphics system # Stock Ubuntu-provided R has the same failure: andy at n88:~$ /usr/bin/R -q --vanilla > dtk.R.version() [1] "R 2.10.1, 2009-12-14, svn.rev 50720, i486-pc-linux-gnu" > x <- matrix(c(1, 0, NA, 1), 2, 2) ; y <- matrix(c(1, 0, 0, 2, 1, 0), 3, 2) > (z <- tcrossprod(x, y)) [,1] [,2] [,3] [1,] NA NA 0 [2,] 2 1 0 > identical(z, x %*% t(y)) [1] FALSE # R I just built from scratch, same failure as stock R: andy at n88:~$ /usr/local/pkg/R-2.12-branch-20110914/bin/R -q --vanilla > dtk.R.version() [1] "R 2.12.2 (Patched), 2011-03-18...
2016 Aug 01
2
R, OpenBLAS and OMP_NUM_THREEADS
...able CPU, which isn't ideal for machines more than a couple of CPUs. Setting the environment (OMP_NUM_THREADS or OPENBLAS_NUM_THREADS) in the shell works: $ OMP_NUM_THREADS=1 R > Sys.getenv("OMP_NUM_THREADS") [1] "1" > system.time({x <- replicate(5e3, rnorm(5e3)); tcrossprod(x) }) [runs in one thread] but adding it to /etc/R/Renviron.site doesn't: $ R > Sys.getenv("OMP_NUM_THREADS") [1] "1" > system.time({x <- replicate(5e3, rnorm(5e3)); tcrossprod(x) }) [runs multi-threaded] (nor does setting the variable at runtime with `Sys.setenv...
2010 May 23
1
need help in understanding R code, and maybe some math
...hm for correcting a non positive definite covariance matrix. I found this code in R: http://projects.cs.kent.ac.uk/projects/cxxr/trac/browser/trunk/src/library/Recommended/Matrix/R/nearPD.R?rev=637 I managed to understand most of it, the only line I really don't understand is this one: X <- tcrossprod(Q * rep(d[p], each=nrow(Q)), Q) This line is supposed to calculate the matrix product Q*D*Q^T, Q is an n by m matrix and R is a diagonal n by n matrix. What does this mean? I also don't understand the meaning of a cross product between matrices, I only know it between vectors. Thanks, Barisda...
2011 Nov 03
1
Question about Calculation of Cross Product
...me. I would like to calculate the cross product of two vectors. According to my text book, it defines like this: a = (ax, ay, az) b = (bx, by, bz) then, the cross product of a and b is: a X b = (ay*bz-az*by, az*bx-ax*bz, ax*by-ay*bz) It can also write in a determinant format. But the crossprod or tcrossprod function in R appeared not calculate the cross product. Suppose I enter this: > a = c(1, 2, 3) > b = c(2, 3, 4) > ab = crossprod(a, b) > ab [,1] [1,] 20 > ab = tcrossprod(a, b) > ab [,1] [,2] [,3] [1,] 2 3 4 [2,] 4 6 8 [3,] 6 9 12 Does any k...
2015 Mar 19
6
RFC: Matrix package: Matrix products (%*%, crossprod, tcrossprod) involving "nsparseMatrix" aka sparse pattern matrices
...ones. Further, it may still seem surprising that matrix multiplication does not behave numerically for a pair of such matrices, and by the principle of "least surprise" we should provide the boolean arithmetic matrix products in another way than by the standard %*%, crossprod() and tcrossprod() functions. So one possibility could be to change the standard functions to behave numerically, and e.g., use %&% (replace the numeric "*" by a logical "&") and crossprod(A,B, boolean=TRUE), tcrossprod(A,B, boolean=TRUE) for the three boolean arithmetic version o...
2017 Jun 18
2
dist function in R is very slow
Hi Stefan, Thank you very much for pointing me to the wordspace package. It does the job a bit faster than my C code but is 100 times more convenient. By the way, since the tcrossprod function in the Matrix package is so fast, the Euclidean distance can be computed very fast: euc_dist <- function(m) {mtm <- Matrix::tcrossprod(m); sq <- rowSums(m*m);? sqrt(outer(sq,sq,"+") - 2*mtm)} It takes less than 50 seconds for my (dense) matrix of 5,054 rows and 12,803 co...
2011 Feb 07
1
Unusual slowing of R matrix multiplication version 2.12.1 (2010-10-15) vs 2.12.0
...-core-dual-processor Macs. I have checked this result on 3 different macs using the following R-script: Using Version 2.12.0 on a dual core dual processor Mac: > source("http://www.bio.umass.edu/biology/kunkel/pub/R/CuriousResult.R") matrix multiplication 43.543 1.308 14.788 tcrossprod 41.147 1.286 11.9 transposition and reuse 40.407 3.525 43.606 elementwise after reshape 21.474 1.828 23.124 columnwise sapply 34.695 32.35 66.592 for loop over columns 37.237 29.471 67.2 On the same day upgrading to 2.12.1 on the same dual core...
2010 Jun 06
2
Generalized DCC GARCH ML estimation
-- View this message in context: http://r.789695.n4.nabble.com/Generalized-DCC-GARCH-ML-estimation-tp2245125p2245125.html Sent from the R help mailing list archive at Nabble.com.
2010 May 08
1
matrix cross product in R different from cross product in Matlab
...cation of first column of first matrix with first column of second matrix of second matrix [2,] ? 2*5+5*2 ? ? cant figure out how these were derived, definitely this is NOT identical to e.g. http://en.wikipedia.org/wiki/Cross_product I can work it out for the tcrossprod > c <- tcrossprod(g, h) > c [,1] [,2] [1,] 32 14 [2,] 77 32 because [,1] [,2] [1,] 1*4+2*5+3*6 1*1+2*2+3*3 #sum of elementwise multiplication of first line of first matrix with first line of second matrix sum of elementwise multi...
2006 Sep 07
2
Matrix package in R-2.4.0alpha
...th, cbind2, rbind2, Arith, Math, Math2, Summary, Compare, !, +, %*%, Schur, as.array, as.matrix, as.vector, band, chol, colMeans, colSums, coerce, crossprod, determinant, diag, dim, dimnames, dimnames<-, expand, expm, kronecker, image, isSymmetric, norm, rcond, rowMeans, rowSums, show, solve, t, tcrossprod, tril, triu Error: package/namespace load failed for 'Matrix' > sessionInfo() R version 2.4.0 alpha (2006-09-05 r39134) i386-pc-mingw32 locale: LC_COLLATE=Spanish_Chile.1252;LC_CTYPE=Spanish_Chile.1252;LC_MONETARY=Spanish_Chile.1252;LC_NUMERIC=C;LC_TIME=Spanish_Chile.1252 attached base...
2009 Jan 14
3
Precision in R
Dear All, I'm preparing a simple algorithm for matrix multiplication for a specific purpose, but I'm getting some unexpected results. If anyone could give a clue, I would really appreciate. Basically what I want to do is a simple matrix multiplication: (WB) %*% t(WB). The WB is in the disk so I compared to approaches: - Load 'WB' using 'read.table' (put it in WB.tmp) and
2010 Jul 30
4
transpose of complex matrices in R
...case where transposition does not occur simultaneously with complex conjugation. And I'm not 100% sure that that wasn't a mistake. Matlab and Octave sort of recognize this, as "A'" means the Hermitian transpose of "A". In R, this issue makes t(), crossprod(), and tcrossprod() pretty much useless to me. OK, so what to do? I have several options: 1. define functions myt(), and mycrossprod() to get round the problem: myt <- function(x){t(Conj(x))} 2. Try to redefine t.default(): t.default <- function(x){if(is.complex(x)){return(base::t(Conj(x)))} else {r...
2016 Aug 02
0
R, OpenBLAS and OMP_NUM_THREEADS
...machines more than a couple of CPUs. > > Setting the environment (OMP_NUM_THREADS or OPENBLAS_NUM_THREADS) in the > shell works: > > $ OMP_NUM_THREADS=1 R >> Sys.getenv("OMP_NUM_THREADS") > [1] "1" >> system.time({x <- replicate(5e3, rnorm(5e3)); tcrossprod(x) }) > [runs in one thread] > > but adding it to /etc/R/Renviron.site doesn't: > > $ R >> Sys.getenv("OMP_NUM_THREADS") > [1] "1" >> system.time({x <- replicate(5e3, rnorm(5e3)); tcrossprod(x) }) > [runs multi-threaded] > > (nor doe...
2017 Jun 18
0
dist function in R is very slow
> By the way, since the tcrossprod function in the Matrix package is so fast, the Euclidean distance can be computed very fast: Indeed. > euc_dist <- function(m) {mtm <- Matrix::tcrossprod(m); sq <- rowSums(m*m); sqrt(outer(sq,sq,"+") - 2*mtm)} There are two reasons why I didn't use this optimization in...
2009 Sep 20
1
Computing the sum of cross products of rows of a matrix
...(1,2,3),3),ncol=3) ## > x ## [,1] [,2] [,3] ## [1,] 1 1 1 ## [2,] 2 2 2 ## [3,] 3 3 3 ## and a storage matrix like this cross <- matrix(rep(0,9),ncol=3) ## then use a loop to sum up the cross products of the rows for (i in 1:nrow(x)){ cross <- cross+tcrossprod(x[i,]) } ## The result ## ## > cross ## [,1] [,2] [,3] ## [1,] 14 14 14 ## [2,] 14 14 14 ## [3,] 14 14 14 -- ----------------------- Stephan Lindner University of Michigan
2024 Nov 26
1
Problem installing some r-packages via spack
Hi All, This occurs when I try to install certain r packages via the Spack package manager (the example is for DelayedArray): 70 ** R 71 ** inst 72 ** byte-compile and prepare package for lazy loading >> 73 Error: objects 'crossprod', 'tcrossprod' are not exported by 'namespace:Matrix' 74 Execution halted 75 ERROR: lazy loading failed for package 'DelayedArray' The command that Spack is executing is something like this: /usr/local/spack/opt/spack/linux-debian12-x86_64/gcc-12.2.0/r-4.4.1-loskbhydpk5kch62...
2006 Dec 10
1
Problem with loading "library(Matrix)" at Ubuntu
...e) : in 'Matrix' methods specified for export, but none defined: Arith, Math, Math2, +, %*%, Schur, as.matrix, chol, colMeans, colSums, coerce, crossprod, determinant, diag, dim, dimnames, dimnames<-, expand, expm, kronecker, image, norm, rcond, rowMeans, rowSums, show, solve, t, tcrossprod Error: package/namespace load failed for 'Matrix' Here is my system: > sessionInfo() R version 2.4.0 (2006-10-03) i486-pc-linux-gnu locale: LC_CTYPE=en_US.UTF-8;LC_NUMERIC=C;LC_TIME=en_US.UTF-8;LC_COLLATE=en_US.UTF-8;LC_MONETARY=en_US.UTF-8;LC_MESSAGES=en_US.UTF-8;LC_PAPER=en_US.UTF-8...