pinned_leading_columns#
- t3toolbox.backend.linalg.pinned_leading_columns(pinned, A, k)#
def pinned_leading_columns( pinned: NDArray, # C+(n, s): orthonormal columns, held fixed A: NDArray, # C+(n, m): the content whose leading directions are wanted k: int, # s + k <= n (structural) ) -> NDArray: # C+(n, k): the leading k left singular directions of (I - P P^T) A, completed against P
The pinned truncated SVD: the leading
kleft singular directions ofAprojected offspan(pinned), completed bypinned_completion()when the projection has rank< k. The countkis the caller’s (structural); nothing is compared with a tolerance.The steps:
Aperp = A - P (P^T A); its thin SVD’s left factor (descending); thenpinned_completion(pinned, U, k), whose QR of the orthonormal[P | U_k]returnsU_kup to column signs. WhenAperphas at leastknonzero singular values the result spans its leading-kleft singular subspace. Otherwise the columns beyond that rank come from the SVD’s trailing singular vectors (zero or roundoff-levelsigma), orthogonalized againstPand the leading columns by the QR: always a valid orthonormal completion orthogonal toP, deterministic for a given input and backend, but not determined byA– roundoff-level changes toA(e.g. its content insidespan(pinned)) can rotate those columns by O(1), and backends may differ there. A tie at the cut (sigma_k = sigma_{k+1}) returns some basis of the tied subspace, as any truncated SVD does.pinnedis assumed orthonormal (a caveat, not checked). The stackCis vectorized;k = 0returnsC+(n, 0); structural errors aspinned_completion().Examples
A planted leading direction outside
span(pinned)is recovered, whateverAholds inside it:>>> import numpy as np >>> import t3toolbox.backend.linalg as linalg >>> np.random.seed(0) >>> P, _ = np.linalg.qr(np.random.randn(6, 2)) # pinned: n = 6, s = 2 >>> B = np.linalg.qr(np.concatenate([P, np.random.randn(6, 2)], axis=1))[0] >>> u, w = B[:, 2], B[:, 3] # orthonormal, orthogonal to P >>> A = 100.0 * P @ np.random.randn(2, 4) + 10.0 * np.outer(u, [1, 0, 0, 0]) + np.outer(w, [0, 1, 0, 0]) >>> U = linalg.pinned_leading_columns(P, A, 1) # off span(P): sigma = 10 (u), 1 (w) >>> print(U.shape, bool(abs(U[:, 0] @ u) > 1 - 1e-12)) (6, 1) True
When the projected content has rank below
kthe rest is completed – still orthonormal and orthogonal topinned:>>> A1 = P @ np.random.randn(2, 3) + np.outer(u, np.random.randn(3)) # rank 1 off span(P), k = 3 >>> PU = np.concatenate([P, linalg.pinned_leading_columns(P, A1, 3)], axis=1) >>> print(bool(np.linalg.norm(PU.T @ PU - np.eye(5)) < 1e-14)) True