filtered_reciprocal#

t3toolbox.backend.linalg.filtered_reciprocal(s, eps, rcond=None)#
def filtered_reciprocal(
        s:      NDArray,                     # singular values, shape=C+(k,), descending
        eps:    typ.Optional[NDArray],       # damping, shape=C (broadcast over k); None -> exact clipped 1/s

        rcond:  typ.Optional[typ.Union[float, NDArray]] = None,  # relative clip vs s[..., :1]: a scalar, or
                                                                 #   broadcastable to C+(1,); None -> dtype eps * k
) -> NDArray:                                # f(s), shape=C+(k,); 0 where clipped

The clipped, optionally damped reciprocal of a spectrum: f(s) = s / (s^2 + eps^2).

Every s at or below the clip rcond * s[..., :1] (relative to the largest value, so the spectrum must be descending, as an SVD returns it) maps to exactly 0, whatever eps is. rcond is one scalar for the whole stack, or an array broadcastable to C+(1,) – one clip per stack element (the uniform lift passes each padded block’s clip at its REAL dimensions this way):

  • eps=None – the exact clipped reciprocal 1/s, the filter of a minimum-norm pseudo-inverse – the shared geometry’s clipped group solve (its tied projection and retraction) uses exactly this, bit for bit what it always computed;

  • eps given (one value per stack element, broadcast over the k values) – the Tikhonov filter s / (s^2 + eps^2): ~1/s for s >> eps, ~s/eps^2 for s << eps, and never above 1/(2 eps). eps = 0 is the exact reciprocal up to rounding (s/s^2).

The clip is what makes eps = 0 safe at a zero-padded warm start, whose padded singular values come back from LAPACK at roundoff (~1e-17) rather than at an exact zero; a zero spectrum (the zero tensor) is clipped entirely, so f is identically 0 there. Both guards are a double where (no division by zero is ever evaluated on a selected branch), so the result is finite everywhere and jit-safe. Dispatch is inferred from s and eps.

Examples

>>> import numpy as np
>>> import t3toolbox.backend.linalg as linalg
>>> s = np.array([4.0, 2.0, 1e-20])                      # the last value is a roundoff "zero"
>>> linalg.filtered_reciprocal(s, None).tolist()         # exact 1/s, roundoff clipped to 0
[0.25, 0.5, 0.0]
>>> f = linalg.filtered_reciprocal(s, np.array(1.0))     # damped: s / (s^2 + 1)
>>> print(np.allclose(f, [4 / 17, 2 / 5, 0.0]))
True

A spectrum stack carries one damping per element (shape C), broadcast over its values:

>>> S = np.array([[4.0, 2.0], [1.0, 0.5]])                # C = (2,), k = 2
>>> print(linalg.filtered_reciprocal(S, np.array([0.0, 1.0])).round(3).tolist())
[[0.25, 0.5], [0.5, 0.4]]
Parameters:
  • s (NDArray)

  • eps (t3toolbox.backend.common.typ.Optional[NDArray])

  • rcond (t3toolbox.backend.common.typ.Optional[t3toolbox.backend.common.typ.Union[float, NDArray]])

Return type:

NDArray