[Numpy-discussion] Efficient orthogonalisation with scipy/numpy
Robert Kern
robert.kern at gmail.com
Tue Jan 19 16:16:59 EST 2010
On Tue, Jan 19, 2010 at 15:12, Gael Varoquaux
<gael.varoquaux at normalesup.org> wrote:
> On Tue, Jan 19, 2010 at 02:58:32PM -0600, Robert Kern wrote:
>> > I am not sure that what I am doing is optimal.
>
>> If confounds is orthonormal, then there is no need to use lstsq().
>
>> y = y - np.dot(np.dot(confounds, y), confounds)
>
> Unfortunately, confounds is not orthonormal, and as it is different at
> each call, I cannot orthogonalise it as a preprocessing.
Ah, then you shouldn't have said "Yes" when I asked if they were
orthonormal. :-)
However, you can orthonormalize inside the function and reuse that for
both x and y. Using the QR decomposition is likely cheaper than the
SVD that lstsq() does.
ortho_confounds = linalg.qr(confounds.T)[0].T
--
Robert Kern
"I have come to believe that the whole world is an enigma, a harmless
enigma that is made terrible by our own mad attempt to interpret it as
though it had an underlying truth."
-- Umberto Eco
More information about the NumPy-Discussion
mailing list