Count sketch

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[citation needed] 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.

Intuitive explanation

The inventors of this data structure offer the following iterative explanation of its operation:

Mathematical definition

1. For constants w and t (to be defined later) independently choose d=2t+1 random hash functions h1,…,hd and s1,…,sd such that hi:[n]→[w] and si:[n]→{±1}. It is necessary that the hash families from which hi and si are chosen be pairwise independent.

2. For each item qi in the stream, add sj(qi) to the hj(qi)th bucket of the jth hash.

At the end of this process, one has wd sums (Cij) where

Ci,j=∑hi(k)=jsi(k).

To estimate the count of qs one computes the following value:

rq=mediani=1dsi(q)⋅Ci,hi(q).

The values si(q)⋅Ci,hi(q) are unbiased estimates of how many times q has appeared in the stream.

The estimate rq has variance O(min{m12/w2,m22/w}), where m1 is the length of the stream and m22 is ∑q(∑i[qi=q])2.

Furthermore, rq is guaranteed to never be more than 2m2/w off from the true value, with probability 1−e−O(t).

Vector formulation

Alternatively Count-Sketch can be seen as a linear mapping with a non-linear reconstruction function. Let M(i∈[d])∈{−1,0,1}w×n, be a collection of d=2t+1 matrices, defined by

Mhi(j),j(i)=si(j)

for j∈[w] and 0 everywhere else.

Then a vector v∈ℝn is sketched by C(i)=M(i)v∈ℝw. To reconstruct v we take vj∗=medianiCj(i)si(j). This gives the same guarantees as stated above, if we take m1=‖v‖1 and m2=‖v‖2.

Relation to Tensor sketch

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

C(1)x∗C(2)xT, where C(1) and C(2) are independent count sketch matrices.

Pham and Pagh show that this equals C(x⊗xT) – a count sketch C 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.

See also