Count sketch is a type of dimensionality reduction that is particularly efficient in statistics, machine learning and algorithms. It was invented by Moses Charikar, Kevin Chen and Martin Farach-Colton in an effort to speed up the AMS Sketch by Alon, Matias and Szegedy for approximating the frequency moments of streams (these calculations require counting of the number of occurrences for the distinct elements of the stream).
The sketch is nearly identical to the Feature hashing algorithm by John Moody, but differs in its use of hash functions with low dependence, which makes it more practical. In order to still have a high probability of success, the median trick is used to aggregate multiple count sketches, rather than the mean.
These properties allow use for explicit kernel methods, bilinear pooling in neural networks and is a cornerstone in many numerical linear algebra algorithms.
The inventors of this data structure offer the following iterative explanation of its operation:
1. For constants and (to be defined later) independently choose random hash functions and such that and . It is necessary that the hash families from which and are chosen be pairwise independent.
2. For each item in the stream, add to the th bucket of the th hash.
At the end of this process, one has sums where
To estimate the count of s one computes the following value:
The values are unbiased estimates of how many times has appeared in the stream.
The estimate has variance , where is the length of the stream and is .
Furthermore, is guaranteed to never be more than off from the true value, with probability .
Alternatively Count-Sketch can be seen as a linear mapping with a non-linear reconstruction function. Let , be a collection of matrices, defined by
for and 0 everywhere else.
Then a vector is sketched by . To reconstruct we take . This gives the same guarantees as stated above, if we take and .
The count sketch projection of the outer product of two vectors is equivalent to the convolution of two component count sketches.
The count sketch computes a vector convolution
, where and are independent count sketch matrices.
Pham and Pagh show that this equals â a count sketch of the outer product of vectors, where denotes Kronecker product.
The fast Fourier transform can be used to do fast convolution of count sketches. By using the face-splitting product such structures can be computed much faster than normal matrices.