[SciPy-User] qr decompostion gives negative q, r ?

Alex Leach beamesleach@gmail....
Tue Nov 20 19:30:55 CST 2012


On Wednesday 21 Nov 2012 01:36:08 Virgil Stokes wrote:
> 
> I have the following matrix, A:
> 
> array([[  7.07106781e+02,   5.49702852e-04,   1.66675481e-19],
>         [ -3.53553391e+01,   7.07104659e+01,   1.66675481e-19],
>         [  0.00000000e+00,  -3.97555166e+00,   7.07106781e-03],
>         [ -7.07106781e+02,  -6.48214647e-04,   1.66675481e-19],
>         [  3.53553391e+01,  -7.07104226e+01,   1.66675481e-19],
>         [  0.00000000e+00,   3.97560687e+00,  -7.07106781e-03],
>         [  0.00000000e+00,   0.00000000e+00,   0.00000000e+00],
>         [  0.00000000e+00,   0.00000000e+00,   0.00000000e+00],
>         [  0.00000000e+00,   0.00000000e+00,   0.00000000e+00]])
> 

> 
> Using np.linalg.qr(A) I get the following for R (3x3) which is
> "square-root" of the covariance matrix:
> 
> array([[ -1.00124922e+03,   4.99289918e+00,   0.00000000e+00],
>         [  0.00000000e+00,  -1.00033071e+02,   5.62045938e-04],
>         [  0.00000000e+00,   0.00000000e+00,  -9.98419272e-03]])
> 

I thought this would be down to the Lapack library you have linked against, as 
numpy uses Lapack's [zd]gqrf internally. I know Matlab comes distributed with 
Intel's MKL, so I imagine Matlab would use Intel's MKL routines internally.
Without knowing anything about the math, here are some test cases on Linux and 
Mac OS X. Looks like it's dependent on platform, from these results...

>>> a = np.array( ... )
>>> q, r = np.linalg.qr( a )
>>> r

**Linux**
Intel MKL:
array([[ -1.00124922e+03,   4.99289919e+00,   2.40741243e-35],
       [  0.00000000e+00,  -1.00033071e+02,   5.62045938e-04],
       [  0.00000000e+00,   0.00000000e+00,  -9.98419272e-03]])

ATLAS Lapack:
array([[ -1.00124922e+03,   4.99289919e+00,  -2.40741243e-35],
       [  0.00000000e+00,  -1.00033071e+02,   5.62045938e-04],
       [  0.00000000e+00,   0.00000000e+00,  -9.98419272e-03]])


**Mac OS X**:
Accelerate Framework:-
array([[  1.00124922e+03,  -4.99289919e+00,   2.40741243e-35],
       [  0.00000000e+00,   1.00033071e+02,  -5.62045938e-04],
       [  0.00000000e+00,   0.00000000e+00,   9.98419272e-03]])

ATLAS Lapack:-
array([[  1.00124922e+03,  -4.99289919e+00,   2.40741243e-35],
       [  0.00000000e+00,   1.00033071e+02,  -5.62045938e-04],
       [  0.00000000e+00,   0.00000000e+00,   9.98419272e-03]])

Cheers,
Alex
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/scipy-user/attachments/20121121/1c5b4179/attachment.html 


More information about the SciPy-User mailing list