 ## Finding k largest eigenvalues

General CULA Dense (LAPACK & BLAS) support and troubleshooting. Use this forum if you are having a general problem or have encountered a bug.

### Finding k largest eigenvalues

Is there any method or future to implement algorithms like lanczos algorithms to find the k largest eigen values? Is there any solution for now?

Posts: 15
Joined: Wed Jun 20, 2012 2:58 am

### Re: Finding k largest eigenvalues

These exist for symmetric and hermitian matrices in the syevx/heevx routines.
john

Posts: 587
Joined: Thu Jul 23, 2009 2:31 pm

### Re: Finding k largest eigenvalues

yes, I just realized that I can find eigenvalues in a specific range or specific indices.But what would be the corresponding eigenvectors if I set rang to "I"

Posts: 15
Joined: Wed Jun 20, 2012 2:58 am

### Re: Finding k largest eigenvalues

Assuming you set JOBZ to 'V' then you'll get the appropriate number of vectors in Z.
john

Posts: 587
Joined: Thu Jul 23, 2009 2:31 pm

### Re: Finding k largest eigenvalues

Yes, it works now.Thanks.

but can you tell me y when I set m= iu-il+1 I get kind of wired answer? Because when I set m=n it makes more sense :

for example for a matrix of 8x8 dimension I get following result for top 4 eigenvectors:
eigenvalues:
[ 8.00000000e-04 8.00000000e-04 8.00000000e-04 8.00000000e-04
2.45898573e+00 3.11167768e+00 9.95596484e+00 2.56381985e+01]

eigenvectors:
scipy.linalg.eigh :
[[-0.14611719 0.78394033 -0.31431961 -0.25958747]
[-0.00860211 -0.23798928 0.39718488 -0.46557788]
[ 0.18952489 0.0831798 -0.09898343 -0.16464493]
[ 0.28435409 -0.21043358 -0.61696779 -0.44713126]
[-0.04668508 -0.27840988 -0.45123004 -0.04021424]
[ 0.5469773 -0.07060557 0.24148952 -0.39681434]
[ 0.17376323 0.41502762 0.29308223 -0.25266402]
[ 0.72817684 0.15116997 -0.07195456 0.5156543 ]]

with m=n:

[[-0.14611719 0.78394033 -0.31431961 -0.25958747 0. 0. 0.
0. ]
[-0.00860211 -0.23798928 0.39718488 -0.46557788 0. 0. 0.
0. ]
[ 0.18952489 0.0831798 -0.09898343 -0.16464493 0. 0. 0.
0. ]
[ 0.28435409 -0.21043358 -0.61696779 -0.44713126 0. 0. 0.
0. ]
[-0.04668508 -0.27840988 -0.45123004 -0.04021424 0. 0. 0.
0. ]
[ 0.5469773 -0.07060557 0.24148952 -0.39681434 0. 0. 0.
0. ]
[ 0.17376323 0.41502762 0.29308223 -0.25266402 0. 0. 0.
0. ]
[ 0.72817684 0.15116997 -0.07195456 0.5156543 0. 0. 0.
0. ]]

with m= iu-il+1

[[-0.14611719 -0.04668508 0.78394033 -0.27840988 -0.31431961 -0.45123004
-0.25958747 -0.04021424]
[-0.00860211 0.5469773 -0.23798928 -0.07060557 0.39718488 0.24148952
-0.46557788 -0.39681434]
[ 0.18952489 0.17376323 0.0831798 0.41502762 -0.09898343 0.29308223
-0.16464493 -0.25266402]
[ 0.28435409 0.72817684 -0.21043358 0.15116997 -0.61696779 -0.07195456
-0.44713126 0.5156543 ]]

Posts: 15
Joined: Wed Jun 20, 2012 2:58 am

### Re: Finding k largest eigenvalues

I'm sorry, I don't understand the question - M is an output from this routine.
john

Posts: 587
Joined: Thu Jul 23, 2009 2:31 pm

### Re: Finding k largest eigenvalues

john wrote:I'm sorry, I don't understand the question - M is an output from this routine.

Yes, but the question is what would be the value of M . Base on the documents when I set RANGE to "I" the value of M should be iu-il+1 . in this case the eigenvectors (Z) has some confusing format. but when I set to m=n the resulted eigenvectors have different indexes.

for comparison look at the first two rows of eigenvectors:

in case m=n :
[[-0.14611719 0.78394033 -0.31431961 -0.25958747 0. 0. 0.
0. ]
[-0.00860211 -0.23798928 0.39718488 -0.46557788 0. 0. 0.
0. ]

but for m=iu-il+1

[[-0.14611719 -0.04668508 0.78394033 -0.27840988 -0.31431961 -0.45123004
-0.25958747 -0.04021424]
[-0.00860211 0.5469773 -0.23798928 -0.07060557 0.39718488 0.24148952
-0.46557788 -0.39681434]

you see the latter case I have some other values between my eigenvectors.

Sorry If don't explain well the problem.

Posts: 15
Joined: Wed Jun 20, 2012 2:58 am

### Re: Finding k largest eigenvalues

Like John said, M is an output value that when using the integer range option should be equal to IU-IL+1.

Are you setting IL and IU? For example, if you want the top 2 values it should be IL=1 and UL=2 (not the Fortran 1-base indexing).

From the docs:
Code: Select all
`If RANGE='I', the indices (in ascending order) of the smallest and largest eigenvalues to be returned.1 <= IL <= IU <= N, if N > 0; IL = 1 and IU = 0 if N = 0.`
kyle

Posts: 301
Joined: Fri Jun 12, 2009 7:47 pm

### Re: Finding k largest eigenvalues

Yes I know this about M but when I set to to IU-IL+1. the answer is not obvious for me. Did you check my result on previews post about different values of M?

kyle wrote:
Are you setting IL and IU? For example, if you want the top 2 values it should be IL=1 and UL=2 (not the Fortran 1-base indexing).

But by setting IL=1 and UL=2 I am getting the 2 smallest eigenvalues not largest. for a 8x8 matrix for getting top 2 I should set IL=6 and UL=8.

Posts: 15
Joined: Wed Jun 20, 2012 2:58 am

### Re: Finding k largest eigenvalues

You are correct about the ordering, this routine does indeed order the eigenvalues from lowest to smallest.

I just ran a similar problem.

Range = I; N = 8; IL = 6; IU = 8

Values:
Code: Select all
`   0.60990590602159556      0.70335476519539919   `

Vectors:
Code: Select all
`   0.30120404264911910   double   0.34704179211947256   double   0.22719182935148297   double   0.42993973500585869   double   0.33341002307228246   double   0.43737133822625307   double   0.33032203696194246   double   0.37524023913192073   double   0.076775878678010015   double   -0.41740538801404498   double   -0.25349112551809067   double   0.56032238991829530   double   -0.60328068615833719   double   0.037490411343624956   double   0.25657054787550626   double   0.10236069498767375   double`

And with

Range = A; N = 8

Values:
Code: Select all
`...   0.60990590602159567   0.70335476519539941`

Vectors:
Code: Select all
`...   0.30120404264911949   double   0.34704179211947273   double   0.22719182935148283   double   0.42993973500585947   double   0.33341002307228307   double   0.43737133822625301   double   0.33032203696194229   double   0.37524023913192039   double   0.076775878678010057   double   -0.41740538801404492   double   -0.25349112551809044   double   0.56032238991829464   double   -0.60328068615833819   double   0.037490411343625317   double   0.25657054787550626   double   0.10236069498767436   double`

My results were as expected, the last 2 vectors and values from the 'all' version matched the results from the 'range' version.

Perhaps you have a data layout issue? CULA is column major which might differ from your reference implementation.
kyle

Posts: 301
Joined: Fri Jun 12, 2009 7:47 pm

### Re: Finding k largest eigenvalues

I have to investigate more about it then. Thanks 