torch_numopt.utils.stability module#
- fix_stability(mat)[source]#
Procedure to adjust a matrix by adding a very small value to the diagonal to avoid numerical instability problems.
- Parameters:
- mat: torch.Tensor
Ill conditioned matrix.
- Returns:
- fixed_mat: torch.Tensor
(Hopefully) Well conditioned matrix.
- pinv_svd_trunc(mat, thresh=0.0001)[source]#
Procedure to calculate the pseudoinverse of a matrix by using truncated SVD in order to maintain numerical stability.
- Parameters:
- mat: torch.Tensor
Problematic matrix that we want to invert.
- thresh: float
Threshold applied to the S matrix in the SVD procedure.
- Returns:
- inverted_mat: torch.Tensor
Pseudoinverse of the input matrix.