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

Robert Kern robert.kern@gmail....
Tue Nov 20 17:29:31 CST 2012


On Tue, Nov 20, 2012 at 11:21 PM, Virgil Stokes <vs@it.uu.se> wrote:
> On 2012-11-20 23:59, Robert Kern wrote:
>> On Tue, Nov 20, 2012 at 10:49 PM, Virgil Stokes <vs@it.uu.se> wrote:
>>
>>> Ok Skipper,
>>> Unfortunately, things are worse than I had hoped, numpy sometimes
>>> returns the negative of the q,r and other times the same as MATLAB!
>>> Thus, as someone has already mentioned in this discussion, the "sign"
>>> seems to depend on the matrix being decomposed. This could be a
>>> nightmare to track down.
>>>
>>> I hope that I can return to some older versions of numpy/scipy to work
>>> around this problem until this problem is fixed. Any suggestions on how
>>> to recover earlier versions would be appreciated.
>> That's not going to help you. The only thing that we guarantee (or
>> have *ever* guaranteed) is that the result is a valid QR
>> decomposition. If you need to swap signs to normalize things to your
>> desired convention, you will need to do that as a postprocessing step.
> But why do I need to normalize with numpy (at least with latest
> release); but not with MATLAB.

Because MATLAB decided to do the normalization step for you. That's a
valid decision. And so is ours.

> A simple question for you.
>
> In my application MATLAB generates a sequence of QR factorizations for
> covariance matrices in which R is always PD --- which is corect!

That is not part of the definition of a QR decomposition. Failing to
meet that property does not make the QR decomposition incorrect.

The only thing that is incorrect is passing an arbitrary, but valid,
QR decomposition to something that is expecting a strict *subset* of
valid QR decompositions.

--
Robert Kern


More information about the SciPy-User mailing list