Message-ID: <B08B6AF0CF8CA44F81B9983EEBDCD686794B3EFC@DC1VEX10MB001.air.org>
Date: 2013-12-06T17:43:40Z
From: Doran, Harold
Subject: Help - Trace of matrices
In-Reply-To: <CANt=4Mj8ihh9+QEZocWH=rJsFcUcOy=wVkYCfQNTmsp8dS6Jsw@mail.gmail.com>
A fast computation I use is based on the following:
A <- matrix(rnorm(16), ncol = 4)
B <- matrix(rnorm(16), ncol = 4)
C <- A %*% B
sum(diag(C))
### This is less expensive to compute when the matrix multiplication is expensive
sum(A * t(B))
So, it just uses the elementwise calculations and sums over all cels
-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of Wagner Bonat
Sent: Friday, December 06, 2013 12:02 PM
To: r-help at r-project.org
Subject: [R] Help - Trace of matrices
Dear,
I need to calculate the following equation
tr(Sigma^-1 %*% D.Sigma)
I know only Sigma (positive definite) and D.Sigma (derivative of Sigma), a naive code is
sum(diag(solve(Sigma,D.Sigma)))
but these matrices are dense and big dimension (10000 x 10000), and I need to evaluate this equation many times.
What is the better way to evaluate this equation in R ?
Note that I need only the diagonal, I think is possible to calculate only the diagnonal, but how ??
--
Wagner Hugo Bonat
LEG - Laborat?rio de Estat?stica e Geoinforma??o UFPR - Universidade Federal do Paran?
[[alternative HTML version deleted]]