[R] Inverse of many small matrices

Feng Li m at feng.li
Fri Apr 3 05:00:28 CEST 2015


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 Murdoch

I 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



More information about the R-help mailing list