API Documentation

megaman.utils.eigendecomp.check_eigen_solver(eigen_solver, solver_kwds, size=None, nvec=None)[source]

Check that the selected eigensolver is valid

Parameters:

eigen_solver : string

string value to validate

size, nvec : int (optional)

if both provided, use the specified problem size and number of vectors to determine the optimal method to use with eigen_solver=’auto’

Returns:

eigen_solver : string

The eigen solver. This only differs from the input if eigen_solver == ‘auto’ and size is specified.

megaman.utils.eigendecomp.eigen_decomposition(G, n_components=8, eigen_solver='auto', random_state=None, drop_first=True, largest=True, solver_kwds=None)[source]

Function to compute the eigendecomposition of a square matrix.

Parameters:

G : array_like or sparse matrix

The square matrix for which to compute the eigen-decomposition.

n_components : integer, optional

The number of eigenvectors to return

eigen_solver : {‘auto’, ‘dense’, ‘arpack’, ‘lobpcg’, or ‘amg’}

‘auto’ :

attempt to choose the best method for input data (default)

‘dense’ :

use standard dense matrix operations for the eigenvalue decomposition. For this method, M must be an array or matrix type. This method should be avoided for large problems.

‘arpack’ :

use arnoldi iteration in shift-invert mode. For this method, M may be a dense matrix, sparse matrix, or general linear operator. Warning: ARPACK can be unstable for some problems. It is best to try several random seeds in order to check results.

‘lobpcg’ :

Locally Optimal Block Preconditioned Conjugate Gradient Method. A preconditioned eigensolver for large symmetric positive definite (SPD) generalized eigenproblems.

‘amg’ :

Algebraic Multigrid solver (requires pyamg to be installed) It can be faster on very large, sparse problems, but may also lead to instabilities.

random_state : int seed, RandomState instance, or None (default)

A pseudo random number generator used for the initialization of the lobpcg eigen vectors decomposition when eigen_solver == ‘amg’. By default, arpack is used.

solver_kwds : any additional keyword arguments to pass to the selected eigen_solver

Returns:

lambdas, diffusion_map : eigenvalues, eigenvectors

megaman.utils.eigendecomp.null_space(M, k, k_skip=1, eigen_solver='arpack', random_state=None, solver_kwds=None)[source]

Find the null space of a matrix M: eigenvectors associated with 0 eigenvalues

Parameters:

M : {array, matrix, sparse matrix, LinearOperator}

Input covariance matrix: should be symmetric positive semi-definite

k : integer

Number of eigenvalues/vectors to return

k_skip : integer, optional

Number of low eigenvalues to skip.

eigen_solver : {‘auto’, ‘dense’, ‘arpack’, ‘lobpcg’, or ‘amg’}

‘auto’ :

algorithm will attempt to choose the best method for input data

‘dense’ :

use standard dense matrix operations for the eigenvalue decomposition. For this method, M must be an array or matrix type. This method should be avoided for large problems.

‘arpack’ :

use arnoldi iteration in shift-invert mode. For this method, M may be a dense matrix, sparse matrix, or general linear operator. Warning: ARPACK can be unstable for some problems. It is best to try several random seeds in order to check results.

‘lobpcg’ :

Locally Optimal Block Preconditioned Conjugate Gradient Method. A preconditioned eigensolver for large symmetric positive definite (SPD) generalized eigenproblems.

‘amg’ :

AMG requires pyamg to be installed. It can be faster on very large, sparse problems, but may also lead to instabilities.

random_state: numpy.RandomState or int, optional

The generator or seed used to determine the starting vector for arpack iterations. Defaults to numpy.random.

solver_kwds : any additional keyword arguments to pass to the selected eigen_solver

Returns:

null_space : estimated k vectors of the null space

error : estimated error (sum of eigenvalues)

Notes

dense solver key words: see
http://docs.scipy.org/doc/scipy-0.14.0/reference/generated/scipy.linalg.eigh.html for symmetric problems and http://docs.scipy.org/doc/scipy-0.14.0/reference/generated/scipy.linalg.eig.html#scipy.linalg.eig for non symmetric problems.
arpack sovler key words: see
http://docs.scipy.org/doc/scipy-0.14.0/reference/generated/scipy.sparse.linalg.eigsh.html for symmetric problems and http://docs.scipy.org/doc/scipy-0.14.0/reference/generated/scipy.sparse.linalg.eigs.html#scipy.sparse.linalg.eigs for non symmetric problems.
lobpcg solver keywords: see
http://docs.scipy.org/doc/scipy/reference/generated/scipy.sparse.linalg.lobpcg.html
amg solver keywords: see
http://pyamg.googlecode.com/svn/branches/1.0.x/Docs/html/pyamg.aggregation.html#module-pyamg.aggregation.aggregation (Note amg solver uses lobpcg and also accepts lobpcg keywords)