[SciPy-Dev] QR-decomposition with Q but not Q

Sturla Molden sturla@molden...
Thu Aug 11 16:01:30 CDT 2011


Regarding the "costlyness" of QR and SVD:

Very often we are interested in QR or SVD only to compute a 
least-squares fit. To save time and memory instead of computing the full 
QR or SVD, LAPACK has specialized drivers for least-squares problems:

*GELS        lstsq with QR
*GELSS lstsq with SVD
*GELSD lstsq with SVD (divide and conquer)
*GGGLM       general linear model with QR

Some of these are exposed in SciPy or statmodels (I think, but I like to 
do it myself...) Anyway, I don't think it's worth the effort to 
duplicate these drivers with specialized QR code, if we only need the QR 
for least-squares.

If anyone is interested, I'm attaching some Fortran 95 code I've used 
for the purpose (porting to Python/NumPy is easy). Array arguments and 
shapes are similar to standard convention in statistics, c.f. Montgomery 
& Peck (1992), Introduction to linear regression analysis.

Sturla



Den 11.08.2011 09:00, skrev Martin Teichmann:
> Hi list,
>
> A QR decomposition is done in two steps: firstly,
> R is calculated and an intermediate form of Q
> (the so called "elementary reflectors"), and in a second
> step, Q is actually calculated.
>
> The second step, however, can be costly and
> thus is not done if you are not interested in Q. The
> QR decomposition code already allows for not
> calculating Q.
>
> Very often, however, one is interested in Q only in
> order to multiply it with a vector c. This can be done
> without ever calculating Q.
>
> I just wrote a patch and submitted it to github, it's here:
> https://github.com/scipy/scipy/pull/55
> which does just this. I'm not sure if I should write both
> on scipy-dev and github, scipy-dev just seems to
> have faster responses...
>
> Greetings
>
> Martin
>

-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: linalg.f90
Url: http://mail.scipy.org/pipermail/scipy-dev/attachments/20110811/b8c1d42a/attachment.pl 
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: linear_regression.f95
Url: http://mail.scipy.org/pipermail/scipy-dev/attachments/20110811/b8c1d42a/attachment-0001.pl 
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: numtypes.f95
Url: http://mail.scipy.org/pipermail/scipy-dev/attachments/20110811/b8c1d42a/attachment-0002.pl 
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: test_regression.f95
Url: http://mail.scipy.org/pipermail/scipy-dev/attachments/20110811/b8c1d42a/attachment-0003.pl 


More information about the SciPy-Dev mailing list