conpy.utils.
reg_pinv
(x, reg=0, rank='full', rcond=1e-15)¶Compute a regularized pseudoinverse of a square matrix.
Regularization is performed by adding a constant value to each diagonal
element of the matrix before inversion. This is known as “diagonal
loading”. The loading factor is computed as reg * np.trace(x) / len(x)
.
The pseudo-inverse is computed through SVD decomposition and inverting the singular values. When the matrix is rank deficient, some singular values will be close to zero and will not be used during the inversion. The number of singular values to use can either be manually specified or automatically estimated.
Square matrix to invert.
Regularization parameter. Defaults to 0.
This controls the effective rank of the covariance matrix when
computing the inverse. The rank can be set explicitly by specifying an
integer value. If None
, the rank will be automatically estimated.
Since applying regularization will always make the covariance matrix
full rank, the rank is estimated before regularization in this case. If
‘full’, the rank will be estimated after regularization and hence
will mean using the full rank, unless reg=0
is used.
Defaults to ‘full’.
Cutoff for detecting small singular values when attempting to estimate
the rank of the matrix (rank='auto'
). Singular values smaller than
the cutoff are set to zero. When set to ‘auto’, a cutoff based on
floating point precision will be used. Defaults to 1e-15.
The inverted matrix.
Value added to the diagonal of the matrix during regularization.
If rank
was set to an integer value, this value is returned,
else the estimated rank of the matrix, before regularization, is
returned.