damped_pseudo_inverse ===================== .. py:function:: t3toolbox.backend.linalg.damped_pseudo_inverse(M, eps, rcond = None) .. code-block:: python 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^T`` of a (stack of) matrices, and its spectrum. One thin batched SVD ``M = U S V^T`` and the filter :py:func:`filtered_reciprocal` on ``S``. ``eps=None`` gives the clipped minimum-norm pseudo-inverse (``numpy.linalg.pinv``'s, with the same default relative clip ``dtype eps * max(m, n)``); a damping ``eps`` gives the Tikhonov-regularized inverse ``(M^T M + eps^2 I)^{-1} M^T``, which stays bounded (by ``1/(2 eps)`` in norm) however small ``M``'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 than :py:func:`pad_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 batch ``C``); dispatch is inferred. .. rubric:: 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