[SciPy-User] qr decompostion gives negative q, r ?
Charles R Harris
charlesr.harris@gmail....
Thu Nov 22 14:12:14 CST 2012
On Thu, Nov 22, 2012 at 8:10 AM, Pauli Virtanen <pav@iki.fi> wrote:
> Virgil Stokes <vs <at> it.uu.se> writes:
> [clip]
> > Of course you are correct Jason, and I have not checked every QR
> decomposition
> > in MATLAB and numpy. However, for my particular application I do know
> that the
> > R returned from MATLAB always has diagonal elements > 0, while this is
> not the
> > case for my installation of numpy.
>
> It is incorrect to assume this. Also Matlab does not guarantee
> that R is PD. That you get it is just due to lucky choice
> of matrices and the MATLAB version/platform.
>
> Compare (these are on the same machine!):
>
> MATLAB(R) Version 7.10.0.499 (R2010a) 64-bit (glnxa64) February 5, 2010
>
> >> A=[707.106781, 0.000549702852, 1.66675481e-19;-35.3553391, 70.7104659,
> 1.66675481e-19;0.0, -3.97555166, 0.00707106781;-707.106781,
> -0.000648214647,
> 1.66675481e-19;35.3553391, -70.7104226, 1.66675481e-19;0.0, 3.97560687,
> -0.00707106781;0.0, 0.0, 0.0;0.0, 0.0, 0.0;0.0, 0.0, 0.0]; [Q,R]=qr(A,0); R
>
> R =
>
> 1.0e+03 *
>
> 1.0012 -0.0050 0.0000
> 0 0.1000 -0.0000
> 0 0 0.0000
>
>
> MATLAB(R) R2012a (7.14.0.739) 64-bit (glnxa64) February 9, 2012
>
> >> A=[707.106781, 0.000549702852, 1.66675481e-19;-35.3553391, 70.7104659,
> 1.66675481e-19;0.0, -3.97555166, 0.00707106781;-707.106781,
> -0.000648214647,
> 1.66675481e-19;35.3553391, -70.7104226, 1.66675481e-19;0.0, 3.97560687,
> -0.00707106781;0.0, 0.0, 0.0;0.0, 0.0, 0.0;0.0, 0.0, 0.0]; [Q,R]=qr(A,0); R
>
> R =
>
> 1.0e+03 *
>
> -1.0012 0.0050 0.0000
> 0 -0.1000 0.0000
> 0 0 -0.0000
>
>
> These, and the results returned by Numpy/Scipy are all correct QR
> decompositions. There are several signs in QR that can be freely
> chosen, and in general there is no particular reason to stick with
> a given choice.
>
>
The term 'positive definite' doesn't really apply either. Just making the
diagonals of r come positive in the qr factorization of a covariance
doesn't make the quadratic form associated with r PD:
In [17]: m[0]
Out[17]:
array([[ 1. , -0.9],
[-0.9, 1. ]])
In [18]: eigvalsh(m[0])
Out[18]: array([ 0.1, 1.9])
In [19]: rp[0]
Out[19]:
array([[ 1.3453624 , -1.33792946],
[ 0. , 0.14122589]])
In [20]: eigvalsh(.5*(rp[0].T + rp[0]))
Out[20]: array([-0.15670585, 1.64329415])
Chuck
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/scipy-user/attachments/20121122/bc569916/attachment.html
More information about the SciPy-User
mailing list