Dear all, I am working with a likelihood function that requires the inverse of many small covariance matrices for multivariate normal densities. When the sample size is large, this calculation is really heavy. Those matrices are independent but unfortunately I can hardly find a way to vectorize them. Can anyone give me a hint to speed this up? Thanks in advance! Feng -- Feng Li, Ph.D. School of Statistics and Mathematics Central University of Finance and Economics 100081 Beijing, China http://feng.li/
On 02/04/2015 9:31 AM, Feng Li wrote:> Dear all, > > I am working with a likelihood function that requires the inverse of > many small covariance matrices for multivariate normal densities. When > the sample size is large, this calculation is really heavy. Those > matrices are independent but unfortunately I can hardly find a way to > vectorize them. > > Can anyone give me a hint to speed this up? Thanks in advance! >Are you sure you need the inverses of those matrices? For example, if you are trying to compute x^t Ainv x, where Ainv is A inverse, the naive calculation is t(x) %*% solve(A) %*% x, but that's likely slower and less accurate than other equivalent ones, such as x %*% solve(A, x), and I wouldn't be surprised if there are better ones. Duncan Murdoch
On 04/02/2015 10:40 PM, Duncan Murdoch wrote:> On 02/04/2015 9:31 AM, Feng Li wrote: >> Dear all, >> >> I am working with a likelihood function that requires the inverse of >> many small covariance matrices for multivariate normal densities. When >> the sample size is large, this calculation is really heavy. Those >> matrices are independent but unfortunately I can hardly find a way to >> vectorize them. >> >> Can anyone give me a hint to speed this up? Thanks in advance! >> > > Are you sure you need the inverses of those matrices? For example, if > you are trying to compute x^t Ainv x, > where Ainv is A inverse, the naive calculation is t(x) %*% solve(A) %*% > x, but that's likely slower and less accurate than other equivalent > ones, such as x %*% solve(A, x), and I wouldn't be surprised if there > are better ones. > > Duncan MurdochI agree what you suggested is good practice. But my likelihood function needs to calculate "x %*% solve(A_i, x)" for i=1,...,n, which is the bottom neck. Feng