glass.algorithm — General purpose algorithms¶
This module contains general implementations of algorithms which are used by GLASS, but are otherwise unrelated to GLASS functionality.
This module should be imported manually if used outside of GLASS:
import glass.algorithm
Non-negative least squares¶
- glass.algorithm.nnls(a, b, *, tol=0.0, maxiter=None)[source]¶
Compute a non-negative least squares solution.
Implementation of the algorithm due to [Lawson95] as described by [Bro97].
- Parameters:
- Returns:
The non-negative least squares solution.
- Raises:
ValueError – If
ais not a matrix.ValueError – If
bis not a vector.ValueError – If the shapes of
aandbdo not match.
- Return type:
Nearest correlation matrix¶
- glass.algorithm.nearcorr(a, *, tol=None, niter=100)[source]¶
Compute the nearest correlation matrix.
Returns the nearest correlation matrix using the alternating projections algorithm of [Higham02].
- Parameters:
- Returns:
Nearest correlation matrix.
- Return type:
Covariance matrix regularisation¶
- glass.algorithm.cov_clip(cov, rtol=None)[source]¶
Covariance matrix from clipping non-positive eigenvalues.
The relative tolerance rtol is defined as for
matrix_rank().- Return type:
- Parameters:
Parameter¶
- cov
A symmetric matrix (or a stack of matrices).
- rtol
An optional relative tolerance for eigenvalues to be considered positive.
- Returns:
Covariance matrix with negative eigenvalues clipped.
- glass.algorithm.cov_nearest(cov, tol=None, niter=100)[source]¶
Covariance matrix from nearest correlation matrix.
Divides cov along rows and columns by the square root of the diagonal, then computes the nearest valid correlation matrix using
nearcorr(), before scaling rows and columns back. The diagonal of the input is hence unchanged.- Parameters:
- Returns:
Covariance matrix from nearest correlation matrix.
- Return type: