Thread Subject: speeding up matrix algebra

Subject: speeding up matrix algebra

From: Hans Henrik Sievertsen

Date: 22 Mar, 2010 11:00:07

Message: 1 of 4

Hi all,
a:
cov=(X'*X)^-1

It takes about <0.00001 seconds

If I run
cova=(X'(Z*((Z'Z)^-1)*Z')*X)

It takes about 2.6 seconds

Where X has dim 10,000 x 10
And Z has dim 10,000 x 11

so that cov X has dim 10 x 10...

Any suggestions on how I could speed up the calculation of cova?

Regards
Hans

Subject: speeding up matrix algebra

From: Husam Aldahiyat

Date: 22 Mar, 2010 11:13:03

Message: 2 of 4

"Hans Henrik Sievertsen" <hhsievertsen@gmail.com> wrote in message <ho7ijn$7mu$1@fred.mathworks.com>...
> Hi all,
> a:
> cov=(X'*X)^-1
>
> It takes about <0.00001 seconds
>
> If I run
> cova=(X'(Z*((Z'Z)^-1)*Z')*X)
>
> It takes about 2.6 seconds
>
> Where X has dim 10,000 x 10
> And Z has dim 10,000 x 11
>
> so that cov X has dim 10 x 10...
>
> Any suggestions on how I could speed up the calculation of cova?
>
> Regards
> Hans

For starters:

>> tic;a^-1;toc
Elapsed time is 1.122925 seconds.

>> tic;inv(a);toc
Elapsed time is 0.482904 seconds.

Subject: speeding up matrix algebra

From: Rune Allnor

Date: 22 Mar, 2010 11:23:12

Message: 3 of 4

On 22 Mar, 12:00, "Hans Henrik Sievertsen" <hhsievert...@gmail.com>
wrote:
> Hi all,
> a:
> cov=(X'*X)^-1
>
> It takes about <0.00001 seconds
>
> If I run
> cova=(X'(Z*((Z'Z)^-1)*Z')*X)
>
> It takes about 2.6 seconds
>
> Where X has dim 10,000 x 10
> And Z has dim 10,000 x 11
>
> so that cov X has dim 10 x 10...
>
> Any suggestions on how I could speed up the calculation of cova?

1) Compute the SVD of Z.
2) Eliminate terms.
3) See what's left - it shouldn't be much.

My attempt (*don't* trust this!!!):

Z = USV
Z' = V'SU'
V'V = VV' = I
U'U = UU' = I

Z'Z = V'SU'USV = V'S^2 V
(Z'Z)^-1 = V'S^{-2}V
Z(Z'Z)^-1z = USVV'S^{-2}VV'SU' = UU'

If my arithmetics is correct, you only need the left-singular
vectors of Z. Once they have been computed, first compute Y = X'U
and last the cross product C = YY'.

Make sure you call the SVD routine as

[...] = svd(Z,0);

or the computations will take forever.

Rune

Subject: speeding up matrix algebra

From: Matt J

Date: 22 Mar, 2010 14:49:02

Message: 4 of 4

"Hans Henrik Sievertsen" <hhsievertsen@gmail.com> wrote in message <ho7ijn$7mu$1@fred.mathworks.com>...

> Any suggestions on how I could speed up the calculation of cova?
=============

Precompute Z'*X and recycle it appropriately in the computations:

tic;
iZtZ=inv(Z'*Z);
ZtX=Z'*X;
cova=(ZtX)'*iZtZ*ZtX;
toc
%Elapsed time is 0.004999 seconds.

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
speed Hans Henrik Sievertsen 22 Mar, 2010 07:04:10
rssFeed for this Thread

Contact us at files@mathworks.com