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/sketch

Sketching operators, generated from a counter

A sketching operator S is a random matrix with far fewer rows than columns (or the reverse) that keeps the geometry of the vectors it is applied to: for every x in a fixed subspace of dimension n, |Sx| stays within a factor 1 +- eps of |x| once S has a small multiple of n rows. Every algorithm in randla starts by applying one.

Each operator here is a deterministic function of (seed, stream): entry (i, j) of a dense operator comes from Philox block (i * cols + j) / 2 or / 4 of that stream, so the same call gives the same operator, bit for bit, in every engine and in any order (RandBLAS's DenseDist and SparseDist work the same way). Use a different stream for each operator one computation needs.

  • gaussian(rows, cols, seed, stream): independent N(0, 1) entries. The reference operator, the one the theory is easiest for; costs a full matrix product to apply.
  • rademacher(rows, cols, seed, stream): independent +-1 entries. Cheaper to generate, same guarantees in practice; the trace estimators use it because a +-1 vector has the smallest variance in Hutchinson's estimator.
  • saso_apply(A, d, nnz, seed, stream): S A for a short-axis-sparse operator (RandBLAS's SASO, the sparse sign embedding of Clarkson and Woodruff with nnz nonzeros per column, values +-1/sqrt(nnz)). Applying it costs nnz times the number of entries of A, with no matrix product.
  • srht_apply(A, d, seed, stream): S A for a subsampled randomized Hadamard transform. It flips the sign of each row of A at random, applies a Walsh-Hadamard transform to each column (zero padded to a power of two), and keeps d rows sampled without replacement, scaled so that E[S^T S] = I. Costs m log m per column.

Used with from randla.sketch 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 36–262