This site is version 0.0.1. Most of the code on this site is drafted by an agent and needs review. I apologize for the AI-speak, we are working on rewriting it!
viv-lang.org

Notebooks · lib/randla/lstsq

Sketch-and-precondition least squares

sap_lstsq(A, b, kind, gamma, seed, tol, maxiter) solves min |A x - b| for a tall A (m by n, m much larger than n) to full accuracy, the way Blendenpik (Avron, Maymounkov and Toledo 2010) and LSRN (Meng, Saunders and Mahoney

  1. do it:
  1. Sketch: S A and S b with S of d = gamma * n rows (kind is "srht", "saso" or "gaussian").
  2. Factor: S A = Q R. Because S keeps the geometry of range(A), A R^-1 has singular values in [1/(1 + eps), 1/(1 - eps)]: a condition number near (1 + sqrt(n/d)) / (1 - sqrt(n/d)), 3 for gamma = 4, whatever the condition number of A.
  3. Warm start from the sketch-and-solve answer x0 = R^-1 Q^T S b (RandLAPACK's SPO starts the same way).
  4. LSQR (Paige and Saunders 1982) on min |A R^-1 y - (b - A x0)|; each step is one product with A, one with A^T and two triangular solves, and the well-conditioned operator makes the iteration count depend on the tolerance only.

A must have full column rank: a rank-deficient A makes R singular, and the iteration runs to maxiter (the second result) without converging. For a rank-deficient problem, rsvd or a pivoted QR is the tool.

The cost is the sketch, an O(d n^2) QR, and about 30 iterations of O(m n) for tol = 10−14, against O(m n^2) for a Householder QR of A. The advantage appears once m n^2 dominates; below that, qr_lstsq is simpler.

Used with from randla.lstsq import ....

Look inside this program

  • Atlas

    The program’s map: every function and which calls which.

  • There’s no recorded run of this program yet.

Shift+Enter in a cell runs it and moves to the next. Running a cell runs every cell above it too, as one program.

[1]lines 34–174