You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@mahout.apache.org by 刘鎏 <li...@gmail.com> on 2012/01/18 10:39:21 UTC

About QRDecomposition

Hi,
When I run QRDecomposition in mahout , I find the result of Q or R is
different from the example in wiki(
http://en.wikipedia.org/wiki/QR_decomposition#Using_Householder_reflections).
After reading the source code, I find the implement of QR decomposition is
exactly different from the tradition way such as the procedure in wiki.
Could any one show why mahout implement it in such a way? Thanks for your
replies!

Liu Liu

Re: About QRDecomposition

Posted by Ted Dunning <te...@gmail.com>.
I put a comment on the wikipedia talk page.  The wikipedia example is just
wrong.

On Thu, Jan 19, 2012 at 8:18 AM, Ted Dunning <te...@gmail.com> wrote:

> And on the subject of correctness, R gives exactly the Mahout results.
>
> > x
>   V1  V2  V3
> 1 12 -51   4
> 2  6 167 -68
> 3 -4  24 -41
>
> > qr.Q(qr(x))
>            [,1]       [,2]        [,3]
> [1,] -0.8571429  0.3942857  0.33142857
> [2,] -0.4285714 -0.9028571 -0.03428571
> [3,]  0.2857143 -0.1714286  0.94285714
> > qr.R(qr(x))
>       V1   V2  V3
> [1,] -14  -21  14
> [2,]   0 -175  70
> [3,]   0    0 -35
> >
>
> And the results you quote from Wikipedia don't actually combine to get the
> right result:
>
> > as.matrix(q) %*% as.matrix(r)
>            V1        V2         V3
> [1,] 11.99996 -50.98650   4.002192
> [2,]  5.99998 166.97736  24.000335
> [3,]  3.99994 -67.98786 -40.998769
> > q
>         V1      V2      V3
> 1 -0.85714  0.3110 -0.4106
> 2 -0.42857 -0.8728  0.2335
> 3 -0.28571  0.3761  0.8814
> > r
>    V1        V2       V3
> 1 -14   -8.4286  -2.0000
> 2   0 -187.1736 -35.1241
> 3   0    0.0000 -32.1761
> >
>
>
> 2012/1/19 刘鎏 <li...@gmail.com>
>
>> Hi, Ted
>>
>> Thanks for your comment. The original matrix is:
>>
>> qRef - 3 x 3
>>  12.00000 -51.00000   4.00000
>>   6.00000 167.00000 -68.00000
>>  -4.00000  24.00000 -41.00000
>>
>> The result of mahout:
>> q - 3 x 3
>>  -0.85714   0.39429  -0.33143
>>  -0.42857  -0.90286   0.03429
>>   0.28571  -0.17143  -0.94286
>>
>> r - 3 x 3
>>  -14.00000 -21.00000  14.00000
>>   0.00000-175.00000  70.00000
>>   0.00000   0.00000  35.00000
>>
>> The result of wiki(http://en.wikipedia.org/wiki/QR_decomposition):
>>
>> q - 3 x 3
>>  -0.85714   0.3110  -0.4106
>>  -0.42857  -0.8728   0.2335
>>  -0.28571   0.3761   0.8814
>>
>> r - 3 x 3
>>  -14.00000 -8.4286  -2.0000
>>   0.00000  -187.1736  -35.1241
>>   0.00000   0.00000    -32.1761
>>
>> I notice that there are differences in computing householder vector, given
>> input vector x,
>>
>> In mahout, householder vector is computed as v= x/||x||,
>> however in wiki, it is computed as u = x+||x||*e1, v=u/||u||.
>>
>> So, would you please give me  some clues about why did mahout(actually
>> JAMA) do like that?
>> Thanks for your reply!
>>
>> Liu Liu
>> On Thu, Jan 19, 2012 at 8:01 AM, Ted Dunning <te...@gmail.com>
>> wrote:
>>
>> > There are lots of QR decomposition algorithms and the results are not
>> > necessarily unique, especially for rank deficient inputs.
>> >
>> > If you post your exact results, I could comment more specifically.
>>  Without
>> > more details, I really can't answer your question in any specific way.
>> >
>> > On Wed, Jan 18, 2012 at 9:39 AM, 刘鎏 <li...@gmail.com> wrote:
>> >
>> > > Hi,
>> > > When I run QRDecomposition in mahout , I find the result of Q or R is
>> > > different from the example in wiki(
>> > >
>> >
>> http://en.wikipedia.org/wiki/QR_decomposition#Using_Householder_reflections
>> > > ).
>> > > After reading the source code, I find the implement of QR
>> decomposition
>> > is
>> > > exactly different from the tradition way such as the procedure in
>> wiki.
>> > > Could any one show why mahout implement it in such a way? Thanks for
>> your
>> > > replies!
>> > >
>> > > Liu Liu
>> > >
>> >
>>
>>
>>
>> --
>> 刘鎏
>>
>> 奇艺公司
>> 北京市海淀区海淀东三街2号欧美汇大厦8层 100080
>>
>> Phone: (010) 6267-7240
>> E-mail: liuliu@qiyi.com
>> MSN: alex_rose2001@hotmail.com
>>
>
>

Re: About QRDecomposition

Posted by Ted Dunning <te...@gmail.com>.
And on the subject of correctness, R gives exactly the Mahout results.

> x
  V1  V2  V3
1 12 -51   4
2  6 167 -68
3 -4  24 -41

> qr.Q(qr(x))
           [,1]       [,2]        [,3]
[1,] -0.8571429  0.3942857  0.33142857
[2,] -0.4285714 -0.9028571 -0.03428571
[3,]  0.2857143 -0.1714286  0.94285714
> qr.R(qr(x))
      V1   V2  V3
[1,] -14  -21  14
[2,]   0 -175  70
[3,]   0    0 -35
>

And the results you quote from Wikipedia don't actually combine to get the
right result:

> as.matrix(q) %*% as.matrix(r)
           V1        V2         V3
[1,] 11.99996 -50.98650   4.002192
[2,]  5.99998 166.97736  24.000335
[3,]  3.99994 -67.98786 -40.998769
> q
        V1      V2      V3
1 -0.85714  0.3110 -0.4106
2 -0.42857 -0.8728  0.2335
3 -0.28571  0.3761  0.8814
> r
   V1        V2       V3
1 -14   -8.4286  -2.0000
2   0 -187.1736 -35.1241
3   0    0.0000 -32.1761
>


2012/1/19 刘鎏 <li...@gmail.com>

> Hi, Ted
>
> Thanks for your comment. The original matrix is:
>
> qRef - 3 x 3
>  12.00000 -51.00000   4.00000
>   6.00000 167.00000 -68.00000
>  -4.00000  24.00000 -41.00000
>
> The result of mahout:
> q - 3 x 3
>  -0.85714   0.39429  -0.33143
>  -0.42857  -0.90286   0.03429
>   0.28571  -0.17143  -0.94286
>
> r - 3 x 3
>  -14.00000 -21.00000  14.00000
>   0.00000-175.00000  70.00000
>   0.00000   0.00000  35.00000
>
> The result of wiki(http://en.wikipedia.org/wiki/QR_decomposition):
>
> q - 3 x 3
>  -0.85714   0.3110  -0.4106
>  -0.42857  -0.8728   0.2335
>  -0.28571   0.3761   0.8814
>
> r - 3 x 3
>  -14.00000 -8.4286  -2.0000
>   0.00000  -187.1736  -35.1241
>   0.00000   0.00000    -32.1761
>
> I notice that there are differences in computing householder vector, given
> input vector x,
>
> In mahout, householder vector is computed as v= x/||x||,
> however in wiki, it is computed as u = x+||x||*e1, v=u/||u||.
>
> So, would you please give me  some clues about why did mahout(actually
> JAMA) do like that?
> Thanks for your reply!
>
> Liu Liu
> On Thu, Jan 19, 2012 at 8:01 AM, Ted Dunning <te...@gmail.com>
> wrote:
>
> > There are lots of QR decomposition algorithms and the results are not
> > necessarily unique, especially for rank deficient inputs.
> >
> > If you post your exact results, I could comment more specifically.
>  Without
> > more details, I really can't answer your question in any specific way.
> >
> > On Wed, Jan 18, 2012 at 9:39 AM, 刘鎏 <li...@gmail.com> wrote:
> >
> > > Hi,
> > > When I run QRDecomposition in mahout , I find the result of Q or R is
> > > different from the example in wiki(
> > >
> >
> http://en.wikipedia.org/wiki/QR_decomposition#Using_Householder_reflections
> > > ).
> > > After reading the source code, I find the implement of QR decomposition
> > is
> > > exactly different from the tradition way such as the procedure in wiki.
> > > Could any one show why mahout implement it in such a way? Thanks for
> your
> > > replies!
> > >
> > > Liu Liu
> > >
> >
>
>
>
> --
> 刘鎏
>
> 奇艺公司
> 北京市海淀区海淀东三街2号欧美汇大厦8层 100080
>
> Phone: (010) 6267-7240
> E-mail: liuliu@qiyi.com
> MSN: alex_rose2001@hotmail.com
>

Re: About QRDecomposition

Posted by 刘鎏 <li...@gmail.com>.
Hi, Ted

Thanks for your comment. The original matrix is:

qRef - 3 x 3
  12.00000 -51.00000   4.00000
   6.00000 167.00000 -68.00000
  -4.00000  24.00000 -41.00000

The result of mahout:
q - 3 x 3
  -0.85714   0.39429  -0.33143
  -0.42857  -0.90286   0.03429
   0.28571  -0.17143  -0.94286

r - 3 x 3
 -14.00000 -21.00000  14.00000
   0.00000-175.00000  70.00000
   0.00000   0.00000  35.00000

The result of wiki(http://en.wikipedia.org/wiki/QR_decomposition):

q - 3 x 3
  -0.85714   0.3110  -0.4106
  -0.42857  -0.8728   0.2335
  -0.28571   0.3761   0.8814

r - 3 x 3
 -14.00000 -8.4286  -2.0000
   0.00000  -187.1736  -35.1241
   0.00000   0.00000    -32.1761

I notice that there are differences in computing householder vector, given
input vector x,

In mahout, householder vector is computed as v= x/||x||,
however in wiki, it is computed as u = x+||x||*e1, v=u/||u||.

So, would you please give me  some clues about why did mahout(actually
JAMA) do like that?
Thanks for your reply!

Liu Liu
On Thu, Jan 19, 2012 at 8:01 AM, Ted Dunning <te...@gmail.com> wrote:

> There are lots of QR decomposition algorithms and the results are not
> necessarily unique, especially for rank deficient inputs.
>
> If you post your exact results, I could comment more specifically.  Without
> more details, I really can't answer your question in any specific way.
>
> On Wed, Jan 18, 2012 at 9:39 AM, 刘鎏 <li...@gmail.com> wrote:
>
> > Hi,
> > When I run QRDecomposition in mahout , I find the result of Q or R is
> > different from the example in wiki(
> >
> http://en.wikipedia.org/wiki/QR_decomposition#Using_Householder_reflections
> > ).
> > After reading the source code, I find the implement of QR decomposition
> is
> > exactly different from the tradition way such as the procedure in wiki.
> > Could any one show why mahout implement it in such a way? Thanks for your
> > replies!
> >
> > Liu Liu
> >
>



-- 
刘鎏

奇艺公司
北京市海淀区海淀东三街2号欧美汇大厦8层 100080

Phone: (010) 6267-7240
E-mail: liuliu@qiyi.com
MSN: alex_rose2001@hotmail.com

Re: About QRDecomposition

Posted by Ted Dunning <te...@gmail.com>.
There are lots of QR decomposition algorithms and the results are not
necessarily unique, especially for rank deficient inputs.

If you post your exact results, I could comment more specifically.  Without
more details, I really can't answer your question in any specific way.

On Wed, Jan 18, 2012 at 9:39 AM, 刘鎏 <li...@gmail.com> wrote:

> Hi,
> When I run QRDecomposition in mahout , I find the result of Q or R is
> different from the example in wiki(
> http://en.wikipedia.org/wiki/QR_decomposition#Using_Householder_reflections
> ).
> After reading the source code, I find the implement of QR decomposition is
> exactly different from the tradition way such as the procedure in wiki.
> Could any one show why mahout implement it in such a way? Thanks for your
> replies!
>
> Liu Liu
>