## Finding k largest eigenvalues

11 posts
• Page

**1**of**1**### 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?

- mjadidi
**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
- Administrator
**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"

- mjadidi
**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
- Administrator
**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 ]]

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 ]]

- mjadidi
**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
- Administrator
**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.

sorry for bad explanation.

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.

- mjadidi
**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:

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
- Administrator
**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?

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.

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.

- mjadidi
**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:

Vectors:

And with

Range = A; N = 8

Values:

Vectors:

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.

I just ran a similar problem.

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

Values:

- Code: Select all
`[0] 0.60990590602159556`

[1] 0.70335476519539919

Vectors:

- Code: Select all
`[0] 0.30120404264911910 double`

[1] 0.34704179211947256 double

[2] 0.22719182935148297 double

[3] 0.42993973500585869 double

[4] 0.33341002307228246 double

[5] 0.43737133822625307 double

[6] 0.33032203696194246 double

[7] 0.37524023913192073 double

[8] 0.076775878678010015 double

[9] -0.41740538801404498 double

[10] -0.25349112551809067 double

[11] 0.56032238991829530 double

[12] -0.60328068615833719 double

[13] 0.037490411343624956 double

[14] 0.25657054787550626 double

[15] 0.10236069498767375 double

And with

Range = A; N = 8

Values:

- Code: Select all
`...`

[6] 0.60990590602159567

[7] 0.70335476519539941

Vectors:

- Code: Select all
`...`

[48] 0.30120404264911949 double

[49] 0.34704179211947273 double

[50] 0.22719182935148283 double

[51] 0.42993973500585947 double

[52] 0.33341002307228307 double

[53] 0.43737133822625301 double

[54] 0.33032203696194229 double

[55] 0.37524023913192039 double

[56] 0.076775878678010057 double

[57] -0.41740538801404492 double

[58] -0.25349112551809044 double

[59] 0.56032238991829464 double

[60] -0.60328068615833819 double

[61] 0.037490411343625317 double

[62] 0.25657054787550626 double

[63] 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
- Administrator
**Posts:**301**Joined:**Fri Jun 12, 2009 7:47 pm

### Re: Finding k largest eigenvalues

I have to investigate more about it then. Thanks

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

11 posts
• Page

**1**of**1**### Who is online

Users browsing this forum: No registered users and 3 guests