Skip to content

countSketch

linear-algebra · scripts/linear-algebra/countSketch.m

: Y = countSketch (X, k)
: [Y, S] = countSketch (X, k)

CountSketch dimensionality reduction of the columns of X.

Y = countSketch (X, K) maps an n-by-d numeric matrix X (rows are points / observations) to an n-by-k sketch Y. The sketch is formed by a sparse CountSketch matrix S (d-by-k) with exactly one nonzero \pm 1 in each row, so that Y = X * S exactly.

The optional second output returns that sparse sketch matrix S. Randomness comes from the current global random stream (randi); seed with rng for reproducibility.

Output class follows X for floating-point inputs (double / single). Logical and integer X are promoted to double.

Behaviour note (MATLAB R2026a): MathWorks does not ship countSketch in R2026a (exist ('countSketch') is 0; the closest core sketching entry point is svdsketch). This Nexus API follows the Clarkson–Woodruff CountSketch convention used in randomized linear algebra (column hashing with random signs) so that pairwise \ell_2 distances among rows of X are preserved in expectation for sufficiently large k (nexus#1945).