Re: [R] matlab eigs function in R

From: Frede Aakmann Tøgersen <FredeA.Togersen_at_agrsci.dk>
Date: Wed, 04 Jun 2008 10:57:55 +0200


Thomas

As far I can see eig (matlab) and eigen (R) both uses LAPACK as the engine, so no differences apart from rounding errors should be expected.

You are not being particular friendly, since you have not told the whole story about how you use eigs in matlab (you are giving some options to eigs). The man page for eigs tells that eigs find largest eigenvalues and eigenvectors of a sparse matrix. However to see how this is done one needs to consult the references (see below) in order to find out. It is some iterative method depending on numerous parameters.

If I use eigs with default values for it's options on

M = [1.2607   -3.5575    2.2968         0         0         0
    -3.5575   10.1429   -6.5855         0         0         0
     2.2968   -6.5855    4.2887         0         0         0
          0         0         0    2.6359   -4.8489    2.2130
          0         0         0   -4.8489    8.9217   -4.0728
          0         0         0    2.2130   -4.0728    1.8598]


to find the four eigenvalues closest to 0 I get:

[Y,eigenvals] = eigs(M,4,0)
Iteration 1: a few Ritz values of the 6-by-6 matrix:

     0
     0
     0
     0


Y =

   0.77166670795421  -0.00007309382085  -0.00000000000000  -0.57709401467465
  -0.15442436854521   0.00132216402668  -0.00000000000001  -0.57751272471495
  -0.61675233485287  -0.00113088742149  -0.00000000000000  -0.57744396127772
   0.00795845605741  -0.68639286168232   0.57735026918974   0.00001228756964
  -0.01410736097199  -0.03974888299631   0.57735026918963  -0.00011191813149
   0.00614890491458   0.72614174467891   0.57735026918951   0.00009963056184


eigenvals =

   0.02530485525437                  0                  0                  0
                  0   0.00109157646361                  0                  0
                  0                  0  -0.00000000000000                  0
                  0                  0                  0  -0.00003332911697



Now setting e.g.

options.issym = 1
options.p = 6 (number of basis vectors)

we now get

[Y,eigenvals] = eigs(M,4,0,options)
Iteration 1: a few Ritz values of the 6-by-6 matrix:

     0
     0
     0
     0


Y =

  -0.76500157409670  -0.00223987987076  -0.00000000000000  -0.57702216553796
   0.13515933807820   0.00165998521603  -0.00000000000000  -0.57744188181803
   0.62913726290127   0.00151722712519  -0.00000000000000  -0.57758630415522
  -0.00973169974519  -0.68255505830793   0.57735026918973  -0.00048056999418
   0.02143072866845  -0.04677389396937   0.57735026918963   0.00017535669432
  -0.01169902892326   0.72932895227757   0.57735026918951   0.00030521329984


eigenvals =

   0.02542832424752                  0                  0                  0
                  0   0.00110871605179                  0                  0
                  0                  0  -0.00000000000000                  0
                  0                  0                  0  -0.00003331498129

Different answers!!!

What causes the difference the references should explain to us.

If you need functions for sparse matrices in R consider the sparseM and Matrix packages. The latter has a eigen() but I don't know which methods it uses to calculate the eigenvalues and -vectors.

Best regards

Frede Aakmann Tøgersen
Scientist

UNIVERSITY OF AARHUS
Faculty of Agricultural Sciences
Dept. of Genetics and Biotechnology
Blichers Allé 20, P.O. BOX 50
DK-8830 Tjele

Phone: +45 8999 1900
Direct: +45 8999 1878

E-mail: FredeA.Togersen_at_agrsci.dk
Web: http://www.agrsci.org

This email may contain information that is confidential. Any use or publication of this email without written permission from Faculty of Agricultural Sciences is not allowed. If you are not the intended recipient, please notify Faculty of Agricultural Sciences immediately and delete this email.  

References for eigs

[1] Lehoucq, R.B. and D.C. Sorensen, "Deflation Techniques for an Implicitly Re-Started Arnoldi Iteration," SIAM J. Matrix Analysis and Applications, Vol. 17, 1996, pp. 789-821.

[2] Lehoucq, R.B., D.C. Sorensen, and C. Yang, ARPACK Users' Guide: Solution of Large-Scale Eigenvalue Problems with Implicitly Restarted Arnoldi Methods, SIAM Publications, Philadelphia, 1998.

[3] Sorensen, D.C., "Implicit Application of Polynomial Filters in a k-Step Arnoldi Method," SIAM J. Matrix Analysis and Applications, Vol. 13, 1992, pp. 357-385.  

> -----Oprindelig meddelelse-----
> Fra: r-help-bounces_at_r-project.org
> [mailto:r-help-bounces_at_r-project.org] På vegne af kayteck_master
> Sendt: 3. juni 2008 8:22
> Til: r-help_at_r-project.org
> Emne: Re: [R] matlab eigs function in R
>
>
> Dear Thomas
>
> Yes, you're right. But I'm looking for this not only for
> computational cost reasons.
> eigen function from R has identical behavior to matlab
> function eig, but not to eigs.
> Even in matlab you can check that those function are not
> giving identical results.
> Here you have a short example :
> Suppose we have given a matrix M
> M =
>
> 1.2607 -3.5575 2.2968 0 0 0
> -3.5575 10.1429 -6.5855 0 0 0
> 2.2968 -6.5855 4.2887 0 0 0
> 0 0 0 2.6359 -4.8489 2.2130
> 0 0 0 -4.8489 8.9217 -4.0728
> 0 0 0 2.2130 -4.0728 1.8598
>
> For eig (R's eigen)we have:
> [V,eiggg]=eig(M);
> V =
>
> 0.5774 0 0 -0.7663 0 0.2820
> 0.5774 0 0 0.1389 0 -0.8046
> 0.5774 0 0 0.6273 0 0.5226
> 0 0.5774 -0.6857 0 0.4432 0
> 0 0.5774 -0.0410 0 -0.8155 0
> 0 0.5774 0.7267 0 0.3723 0
>
>
> eiggg =
>
> -0.0000 0 0 0 0 0
> 0 -0.0000 0 0 0 0
> 0 0 0.0011 0 0 0
> 0 0 0 0.0252 0 0
> 0 0 0 0 13.4163 0
> 0 0 0 0 0 15.6671
>
> And for matlab's eigs we have:
> [Y,eigenvals] = eigs(M,4,0,options) ;
> Y =
>
> -0.8147 -0.0106 -0.0000 -0.5774
> 0.3802 -0.0143 -0.0000 -0.5774
> 0.4344 0.0249 0.0000 -0.5774
> -0.0332 0.6871 -0.5774 0.0000
> 0.0430 0.0379 -0.5774 0.0000
> -0.0098 -0.7250 -0.5774 0.0000
>
>
> eigenvals =
>
> 0.0331 0 0 0
> 0 0.0011 0 0
> 0 0 0.0000 0
> 0 0 0 -0.0000
>
> As you can see, columns of chosen eigenvectors are different.
> I'm looking for function similar to eigs in R. I'll try with
> svd, which you have mentioned. Thank you for that idea, maybe
> it will be what i'm looking for.
>
> Kayteck
> --
> View this message in context:
> http://www.nabble.com/matlab-eigs-function-in-R-tp17619641p176
> 29655.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help_at_r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Wed 04 Jun 2008 - 09:48:55 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 04 Jun 2008 - 10:30:40 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive