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

Matthieu Brucher matthieu.brucher@gmail....
Wed Nov 21 01:49:24 CST 2012


Shor answer: you shouldn't! This time, it will work, next time it won't.
You must never depend on an implementation detail as it is the case here.
Add a post processing step, and it will be allright on all platforms and
also in all languages.

Cheers,


2012/11/21 Virgil Stokes <vs@it.uu.se>

>  On 21-Nov-2012 02:30, Alex Leach wrote:
>
> 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
>
>
> _______________________________________________
> SciPy-User mailing listSciPy-User@scipy.orghttp://mail.scipy.org/mailman/listinfo/scipy-user
>
>  Very interesting Alex --- Guess I should get a Mac :-)
>
> How can I force the use of the Lapack (on my Win32 system) that is being
> used by the Mac OS X?
>
> _______________________________________________
> SciPy-User mailing list
> SciPy-User@scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user
>
>


-- 
Information System Engineer, Ph.D.
Blog: http://matt.eifelle.com
LinkedIn: http://www.linkedin.com/in/matthieubrucher
Music band: http://liliejay.com/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/scipy-user/attachments/20121121/03933062/attachment-0001.html 


More information about the SciPy-User mailing list