SVD

class hcipy.util.SVD(matrix=None, num_modes=None, M=None)

Bases: object

The Singular Value Decomposition for the provided matrix.

This class wraps two versions of the SVD in numpy and scipy, and provides easy access to singular modes (as mode bases) and allows for calculation of the SVD for a limited number of modes.

When a sparse matrix is passed, and no number of modes is given, all but one mode will be calculated. The reason is that the sparse SVD implementation in Scipy doesn’t allow calculation of all modes. If all modes are required, the user must pass a densified version of the matrix (ie. matrix.toarray()).

Parameters:
matrixndarray or any sparse matrix

The matrix on which to perform the SVD.

num_modesint or None

The number of singular values and modes to calculate. If this is None, and matrix is not sparse, all modes will be computed. If this is None and matrix is sparse, all but one mode will be computed.

Attributes Summary

M

S

The singular values of the matrix.

U

The U matrix of the SVD.

Vt

The V^T matrix of the SVD.

left_singular_modes

The left singular modes of the matrix, as a ModeBasis.

matrix

The matrix for which the SVD was calculated.

num_modes

The number of singular modes that were calculated in this SVD.

right_singular_modes

The right singular modes of the matrix, as a ModeBasis.

singular_values

The singular values of the matrix.

svd

The raw U, S, and V^T matrices of the SVD as a tuple.

Attributes Documentation

M
S

The singular values of the matrix.

U

The U matrix of the SVD.

Vt

The V^T matrix of the SVD.

left_singular_modes

The left singular modes of the matrix, as a ModeBasis.

matrix

The matrix for which the SVD was calculated.

num_modes

The number of singular modes that were calculated in this SVD.

right_singular_modes

The right singular modes of the matrix, as a ModeBasis.

singular_values

The singular values of the matrix.

svd

The raw U, S, and V^T matrices of the SVD as a tuple.