Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

PyTorch torch.lobpcg function

PyTorch torch.lobpcg function


PyTorch torch reference manual PyTorch torch reference manual

torch.lobpcg is a function in PyTorch used to solve eigenvalue problems with the LOBPCG (Locally Optimal Block Preconditioned Conjugate Gradient) method. It is especially suitable for eigenvalue computation of large-scale sparse matrices.

Function definition

torch.lobpcg(A, B=None, X=None, k=None, n=None, tol=None, maxiter=None, largest=None, method=None, tracker=None, ortho_iparams=None, ortho_fparams=None, ortho_cparams=None)

Parameters:

Return Value:


Usage examples

Example

import

torch

Create a symmetric positive-definite matrix

n

=

100

A

=

torch.

randn

(

n

,

n

)

A

=

A

@

A.

T

 

Make it symmetric positive definite

Initial approximation

k

=

3

X

=

torch.

randn

(

n

,

k

)

LOBPCG solution

eigenvalues

,

eigenvectors

=

torch.

lobpcg

(

A

,

X

=

X

,

k

=

k

)

print

(

"Matrix shape:"

,

A.

shape

)

print

(

"Eigenvalues:"

)

print

(

eigenvalues

)

The output is:

矩阵形状: torch.Size([100, 100])

Eigenvalues:

tensor([105.0154, 101.8972,  98.6843])


PyTorch torch reference manual PyTorch torch reference manual