damped_pseudo_inverse#
- t3toolbox.backend.linalg.damped_pseudo_inverse(M, eps, rcond=None)#
def damped_pseudo_inverse( M: NDArray, # shape=C+(m, n) eps: typ.Optional[NDArray], # damping, shape=C; None -> the clipped (minimum-norm) pinv rcond: typ.Optional[typ.Union[float, NDArray]] = None, # relative clip: a scalar, or broadcastable to # C+(1,); None -> dtype eps * max(m, n) ) -> typ.Tuple[ NDArray, # M^{+eps}, shape=C+(n, m) NDArray, # s, the singular values of M, shape=C+(min(m, n),), descending ]:
The damped pseudo-inverse
M^{+eps} = V f(S) U^Tof a (stack of) matrices, and its spectrum.One thin batched SVD
M = U S V^Tand the filterfiltered_reciprocal()onS.eps=Nonegives the clipped minimum-norm pseudo-inverse (numpy.linalg.pinv’s, with the same default relative clipdtype eps * max(m, n)); a dampingepsgives the Tikhonov-regularized inverse(M^T M + eps^2 I)^{-1} M^T, which stays bounded (by1/(2 eps)in norm) however smallM’s singular values are.No basis is kept – only the product
V f(S) U^T– so the result does not depend on how the SVD picks the singular vectors of a degenerate or zero block (the clipped values multiply them by 0). That is what makes it transparent to zero padding, and why it is a plain SVD rather thanpad_safe_svd()(which exists for consumers that DO keep the basis). Returns the singular values too, for diagnostics (the smallest real one is the conditioning the damping guards). Stack-aware (one opaque batchC); dispatch is inferred.Examples
>>> import numpy as np >>> import t3toolbox.backend.linalg as linalg >>> np.random.seed(0) >>> M = np.random.randn(4, 3) >>> Mp, s = linalg.damped_pseudo_inverse(M, None) >>> print(Mp.shape, s.shape, np.allclose(Mp, np.linalg.pinv(M))) (3, 4) (3,) True >>> Mp_eps, _ = linalg.damped_pseudo_inverse(M, np.array(0.5)) # Tikhonov >>> print(np.allclose(Mp_eps, np.linalg.solve(M.T @ M + 0.25 * np.eye(3), M.T))) True