bundles / scipy 1.17.1 / scipy / sparse / linalg / _eigen / arpack / arpack / eigsh
function
scipy.sparse.linalg._eigen.arpack.arpack:eigsh
Signature
def eigsh ( A , k = 6 , M = None , sigma = None , which = LM , v0 = None , ncv = None , maxiter = None , tol = 0 , return_eigenvectors = True , Minv = None , OPinv = None , mode = normal , rng = None ) Summary
Find k eigenvalues and eigenvectors of the real symmetric square matrix or complex Hermitian matrix A.
Extended Summary
Solves A @ x[i] = w[i] * x[i], the standard eigenvalue problem for w[i] eigenvalues with corresponding eigenvectors x[i].
If M is specified, solves A @ x[i] = w[i] * M @ x[i], the generalized eigenvalue problem for w[i] eigenvalues with corresponding eigenvectors x[i].
Note that there is no specialized routine for the case when A is a complex Hermitian matrix. In this case, eigsh() will call eigs() and return the real parts of the eigenvalues thus obtained.
Parameters
A: ndarray, sparse matrix or LinearOperatorA square operator representing the operation
A @ x, whereAis real symmetric or complex Hermitian. For buckling mode (see below)Amust additionally be positive-definite.k: int, optionalThe number of eigenvalues and eigenvectors desired.
kmust be smaller than N. It is not possible to compute all eigenvectors of a matrix.
Returns
w: arrayArray of k eigenvalues.
v: arrayAn array representing the
keigenvectors. The columnv[:, i]is the eigenvector corresponding to the eigenvaluew[i].
Other Parameters
M: An N x N matrix, array, sparse matrix, or linear operator representingthe operation
M @ xfor the generalized eigenvalue problemA @ x = w * M @ x.
M must represent a real symmetric matrix if A is real, and must represent a complex Hermitian matrix if A is complex. For best results, the data type of M should be the same as that of A. Additionally:
If sigma is None, M is symmetric positive definite.
If sigma is specified, M is symmetric positive semi-definite.
In buckling mode, M is symmetric indefinite.
If sigma is None, eigsh requires an operator to compute the solution of the linear equation
M @ x = b. This is done internally via a (sparse) LU decomposition for an explicit matrix M, or via an iterative solver for a general linear operator. Alternatively, the user can supply the matrix or operator Minv, which givesx = Minv @ b = M^-1 @ b.sigma: realFind eigenvalues near sigma using shift-invert mode. This requires an operator to compute the solution of the linear system
[A - sigma * M] x = b, where M is the identity matrix if unspecified. This is computed internally via a (sparse) LU decomposition for explicit matrices A & M, or via an iterative solver if either A or M is a general linear operator. Alternatively, the user can supply the matrix or operatorOPinv, which givesx = OPinv @ b = [A - sigma * M]^-1 @ b. Regardless of the selected mode (normal, cayley, or buckling),OPinvshould always be supplied asOPinv = [A - sigma * M]^-1.Note that when sigma is specified, the keyword 'which' refers to the shifted eigenvalues
w'[i]where:if
mode == 'normal':w'[i] = 1 / (w[i] - sigma).if
mode == 'cayley':w'[i] = (w[i] + sigma) / (w[i] - sigma).if
mode == 'buckling':w'[i] = w[i] / (w[i] - sigma).(see further discussion in 'mode' below)
v0: ndarray, optionalStarting vector for iteration. Default: random
ncv: int, optionalThe number of Lanczos vectors generated ncv must be greater than k and smaller than n; it is recommended that
ncv > 2*k. Default:min(n, max(2*k + 1, 20))which: str ['LM' | 'SM' | 'LA' | 'SA' | 'BE']If A is a complex Hermitian matrix, 'BE' is invalid. Which
keigenvectors and eigenvalues to find:'LM'Largest (in magnitude) eigenvalues.
'SM'Smallest (in magnitude) eigenvalues.
'LA'Largest (algebraic) eigenvalues.
'SA'Smallest (algebraic) eigenvalues.
'BE'Half (k/2) from each end of the spectrum.
When k is odd, return one more (k/2+1) from the high end. When sigma != None, 'which' refers to the shifted eigenvalues
w'[i](see discussion in 'sigma', above). ARPACK is generally better at finding large values than small values. If small eigenvalues are desired, consider using shift-invert mode for better performance.maxiter: int, optionalMaximum number of Arnoldi update iterations allowed. Default:
n*10tol: floatRelative accuracy for eigenvalues (stopping criterion). The default value of 0 implies machine precision.
Minv: N x N matrix, array, sparse matrix, or LinearOperatorSee notes in M, above.
OPinv: N x N matrix, array, sparse matrix, or LinearOperatorSee notes in sigma, above.
return_eigenvectors: boolReturn eigenvectors (True) in addition to eigenvalues. This value determines the order in which eigenvalues are sorted. The sort order is also dependent on the
whichvariable.For which = 'LM' or 'SA':
If
return_eigenvectorsis True, eigenvalues are sorted by algebraic value.If
return_eigenvectorsis False, eigenvalues are sorted by absolute value.For which = 'BE' or 'LA':
eigenvalues are always sorted by algebraic value.
For which = 'SM':
If
return_eigenvectorsis True, eigenvalues are sorted by algebraic value.If
return_eigenvectorsis False, eigenvalues are sorted by decreasing absolute value.
mode: string ['normal' | 'buckling' | 'cayley']Specify strategy to use for shift-invert mode. This argument applies only for real-valued A and sigma != None. For shift-invert mode, ARPACK internally solves the eigenvalue problem
OP @ x'[i] = w'[i] * B @ x'[i]and transforms the resulting Ritz vectors x'[i] and Ritz values w'[i] into the desired eigenvectors and eigenvalues of the problemA @ x[i] = w[i] * M @ x[i]. The modes are as follows:'normal' :
OP = [A - sigma * M]^-1 @ M, B = M, w'[i] = 1 / (w[i] - sigma)
'buckling' :
OP = [A - sigma * M]^-1 @ A, B = A, w'[i] = w[i] / (w[i] - sigma)
'cayley' :
OP = [A - sigma * M]^-1 @ [A + sigma * M], B = M, w'[i] = (w[i] + sigma) / (w[i] - sigma)
The choice of mode will affect which eigenvalues are selected by the keyword 'which', and can also impact the stability of convergence (see [2] for a discussion).
rng: `numpy.random.Generator`, optionalPseudorandom number generator state. When
rngis None, a new numpy.random.Generator is created using entropy from the operating system. Types other than numpy.random.Generator are passed to numpy.random.default_rng to instantiate aGenerator.
Raises
: ArpackNoConvergenceWhen the requested convergence is not obtained.
The currently converged eigenvalues and eigenvectors can be found as
eigenvaluesandeigenvectorsattributes of the exception object.
Notes
This function is a wrapper to the ARPACK [1] SSEUPD and DSEUPD functions which use the Implicitly Restarted Lanczos Method to find the eigenvalues and eigenvectors [2].
Examples
import numpy as np from scipy.sparse.linalg import eigsh identity = np.eye(13) eigenvalues, eigenvectors = eigsh(identity, k=6) eigenvalues eigenvectors.shape✓
See also
Aliases
-
scipy.sparse.linalg.eigsh
Referenced by
This package
Other packages
- skimage release_notes:release_0.17
- skimage skimage.graph._graph_cut:cut_normalized