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

Sturla Molden sturla at molden.no
Thu Aug 11 17:01:30 EDT 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.python.org/pipermail/scipy-dev/attachments/20110811/b8c1d42a/attachment.ksh>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: linear_regression.f95
URL: <http://mail.python.org/pipermail/scipy-dev/attachments/20110811/b8c1d42a/attachment-0001.ksh>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: numtypes.f95
URL: <http://mail.python.org/pipermail/scipy-dev/attachments/20110811/b8c1d42a/attachment-0002.ksh>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: test_regression.f95
URL: <http://mail.python.org/pipermail/scipy-dev/attachments/20110811/b8c1d42a/attachment-0003.ksh>


More information about the SciPy-Dev mailing list