Displaying 20 results from an estimated 1000 matches similar to: "crossprod(x) vs crossprod(x,x)"
2002 Mar 15
1
Thought on crossprod
Hi everyone,
I do a lot of work with large variance matrices, and I like to use
"crossprod" for speed and to keep everything symmetric, i.e. I often
compute "crossprod(Q %*% t(A))" for "A %*% Sigma %*% t(A)", where
"Sigma" decomposes as "t(Q) %*% Q". I notice in the code that
"crossprod", current definition
> crossprod
function (x,
2005 Oct 05
2
eliminate t() and %*% using crossprod() and solve(A,b)
Hi
I have a square matrix Ainv of size N-by-N where N ~ 1000
I have a rectangular matrix H of size N by n where n ~ 4.
I have a vector d of length N.
I need X = solve(t(H) %*% Ainv %*% H) %*% t(H) %*% Ainv %*% d
and
H %*% X.
It is possible to rewrite X in the recommended crossprod way:
X <- solve(quad.form(Ainv, H), crossprod(crossprod(Ainv, H), d))
where quad.form() is a little
2003 Oct 17
2
Problems with crossprod
Dear R-users,
I found a strange problem
working with products of two matrices, say:
a <- A[i, ] ; crossprod(a)
where i is a set of integers selecting rows. When i is empty
the result is in a sense random.
After some trials the right answer
(a matrix of zeros) appears.
--------------- Illustration --------------------
R : Copyright 2003, The R Development Core Team
Version 1.8.0
2005 Jan 27
3
the incredible lightness of crossprod
The following is at least as much out of intellectual curiosity
as for practical reasons.
On reviewing some code written by novices to R, I came
across:
crossprod(x, y)[1,1]
I thought, "That isn't a very S way of saying that, I wonder
what the penalty is for using 'crossprod'." To my surprise the
penalty was substantially negative. Handily the client had S-PLUS
as
2004 Oct 06
3
crossprod vs %*% timing
Hi
the manpage says that crossprod(x,y) is formally equivalent to, but
faster than, the call 't(x) %*% y'.
I have a vector 'a' and a matrix 'A', and need to evaluate 't(a) %*% A
%*% a' many many times, and performance is becoming crucial. With
f1 <- function(a,X){ ignore <- t(a) %*% X %*% a }
f2 <- function(a,X){ ignore <-
2008 Mar 10
1
crossprod is slower than t(AA)%*BB
Dear Rdevelopers
The background for this email is that I was helping a PhD student to
improve the speed of her R code. I suggested to replace calls like
t(AA)%*% BB by crossprod(AA,BB) since I expected this to be faster. The
surprising result to me was that this change actually made her code
slower.
> ## Examples :
>
> AA <- matrix(rnorm(3000*1000),3000,1000)
> BB <-
2002 Jul 14
1
crossprod and X %*% t(X)
hi,
the help page for crossprod states that crossprod(A,B) is faster than
t(A) %*% B; experimentation certainly bears this out. more alarming
is the evidence that crossprod(t(A), B) is faster than A %*% B:
on a PII laptop, 128MB memory, win98, R-1.5.0.-patched precompiled
(no ATLAS):
> A <- matrix(rnorm(250000),500,500)
> B <- matrix(rnorm(250000),500,500)
> for (i in 1:5) {
2003 Sep 07
3
bug in crossprod? (PR#4092)
# Your mailer is set to "none" (default on Windows),
# hence we cannot send the bug report directly from R.
# Please copy the bug report (after finishing it) to
# your favorite email program and send it to
#
# r-bugs@r-project.org
#
######################################################
# The last line of following code produces a segmentation fault:
x <- 1:10
f <- gl(5,2)
2013 Mar 05
1
crossprod(): g77 versus gfortran
Hi
I've got two builds of R, one using g77 (version 3.4.6) and the other
using gfortran (version 4.1.2). The two builds are otherwise identical
as far as I can tell. The one which used g77 performs crossprod()s
roughly twice as fast as the gfortran one. I'm wondering if this rings a
bell with anyone, and if so, are you aware of any configure settings
which will improve the performance
2010 Mar 27
1
R runs in a usual way, but simulations are not performed
Dear addresses, I need perform a batch of 10 000 simulations for each of
4 options considered. (The idea is to obtain the parameter estimates in
a heteroskedastic linear regression model - with additive or mixed
heteroskedasticity - via the Kenward-Roger small-sample adjusted
covariance matrix of disturbances). For this purpose I wrote an R
program which would capture all possible options (true
2007 Jun 15
0
NaN in crossprod
Hello,
I have come across a troubling problem in which my call to crossprod
will occasionally produce NaNs. That is, a proper matrix cross-product
will be produced except that some of the matrix elements will
arbitrarily be NaN. For my purposes, this is extremely bad. On several
different R sessions run this morning this example below may fail a few
times out of a million, though sometimes not at
2010 May 08
1
matrix cross product in R different from cross product in Matlab
Hi all,
I have been searching all sorts of documentation, reference cards, cheat
sheets but can't find why R's
crossprod(A, B) which is identical to A%*%B
does not produce the same as Matlabs
cross(A, B)
Supposedly both calculate the cross product, and say so, or where do I
go wrong?
R is only doing sums in the crossprod however, as indicated by
(z <- crossprod(1:4)) # = sum(1 +
2015 Mar 19
6
RFC: Matrix package: Matrix products (%*%, crossprod, tcrossprod) involving "nsparseMatrix" aka sparse pattern matrices
This is a Request For Comment, also BCCed to 390 package maintainers
of reverse dependencies of the Matrix package.
Most users and package authors working with our 'Matrix' package will
be using it for numerical computations, and so will be using
"dMatrix" (d : double precision) matrix objects M, and indirectly, e.g., for
M >= c will also use "lMatrix" (l:
2015 Mar 19
0
RFC: Matrix package: Matrix products (%*%, crossprod, tcrossprod) involving "nsparseMatrix" aka sparse pattern matrices
Hi Martin
I got stung by this last week.
glmnet produces a coefficient matrix of class ?dgCMatrix?
If a predictor matrix was created using sparseMatrix as follows,
one gets unexpected results, as this simple example shows.
My fix was easy (I always convert the predictor matrix to class ?dgCMatrix? now)
Trevor
> y=Matrix(diag(4))
> y
4 x 4 diagonal matrix of class "ddiMatrix"
2015 Mar 20
0
RFC: Matrix package: Matrix products (%*%, crossprod, tcrossprod) involving "nsparseMatrix" aka sparse pattern matrices
Hi Martin,
package arules heavily relies on ngCMatrix and uses multiplication and
addition for logical operations. I think it makes sense that in a mixed
operation with one dgCMatrix and one ngCMatrix the ngCMatrix should be
"promoted" to a dgCMatrix.
The current behavior of %*% and friends is in deed confusing:
> m <- matrix(sample(c(0,1), 5*5, replace=TRUE), nrow=5)
>
2008 May 01
4
efficient code - yet another question
Dear list members;
The code given below corresponds to the PCA-NIPALS (principal
component analysis) algorithm adapted from the nipals function in the
package chemometrics. The reason for using NIPALS instead of SVD is
the ability of this algorithm to handle missing values, but that's a
different story. I've been trying to find a way to improve (if
possible) the efficiency of the code,
2018 Jan 08
2
Fwd: R/MKL Intel 2018 Compatibility
Dear all,
I would like to submit an issue that we are facing.
Indeed, in our environment, we are optimizing the R code to speed up some
mathematical calculations as matrix products using the INTEL libraries (
MKL) ( https://software.intel.com/en-us/mkl )
With the last version of the MKL libraries Intel 2018, we are facing to an
issue with *all INTERNAL command* that are executing in R.
2011 Mar 20
2
Why unique(sample) decreases the performance ?
Hi,
I' am interested in differences between sample's result when samples consist
of full elements and consist of only distinct elements. When sample consist
of full elements it take about 120 sec., but when consist of only distinct
elements it take about 4.5 or 5 times more sec. I expected that opposite of
this result, because unique(sample) has less elements than full sample. Code
as
2010 Nov 16
2
Integrating functions / vector arithmetic
Hello,
I was trying to build some functions which I would like to integrate over an
interval using the function 'integrate' from the 'stats' package. As an
example, please consider the function
h(u)=sin(pi*u) + sqrt(2)*sin(pi*2*u) + sqrt(3)*sin(pi*3*u) + 2*sin(pi*4*u)
Two alternative ways to 'build' this function are as in f and g below:
coeff<-sqrt(1:4)
2009 Jul 07
3
Error due to non-conformable arrays
Hello,
Consider this function for generalized ridge regression:
gre <- function (X,y,D){
n <- dim(X)[1]
p <- dim(X)[2]
intercept <- rep(1, n)
X <- cbind(intercept, X)
X2D <- crossprod(X,X)+ D
Xy <- crossprod(X,y)
bth <- qr.solve(X2D, Xy)
}
# suppose X is an (nxp) design matrix and y is an (nx1) response vector
p <- dim(x)[2]
D<- diag(rep(1.5,p))
bt