Problem
Let x ⃗ = ( x 1 , . . . , x n ) \vec x = (x_1, ..., x_n) x = ( x 1 , ... , x n ) , y ⃗ = ( y 1 , . . . , y n ) ∈ R n \vec y = (y_1, ..., y_n) \in \mathbb{R}^n y = ( y 1 , ... , y n ) ∈ R n . Given δ ∈ ( 0 , 1 ) \delta \in (0, 1) δ ∈ ( 0 , 1 ) , construct a data structure with space usage O ( 1 ϵ 2 log 1 δ ) O \left( \frac{1}{\epsilon^2} \log \frac{1}{\delta} \right) O ( ϵ 2 1 log δ 1 ) , such that with failure probability at most δ ∈ ( 0 , 1 ) \delta \in (0, 1) δ ∈ ( 0 , 1 ) ,
it returns an estimate of the inner product < x ⃗ , y ⃗ > \left< \vec x, \vec y \right> ⟨ x , y ⟩ with error O ( ϵ ⋅ ∥ x ⃗ ∥ 2 ⋅ ∥ y ⃗ ∥ 2 ) O( \epsilon \cdot \Vert \vec x \Vert_2 \cdot \Vert \vec y \Vert_2 ) O ( ϵ ⋅ ∥ x ∥ 2 ⋅ ∥ y ∥ 2 ) .
Remark: If we have x ⃗ = y ⃗ \vec x = \vec y x = y , we get an estimator of ∥ x ⃗ ∥ 2 2 \Vert \vec x \Vert_2^2 ∥ x ∥ 2 2 with ϵ \epsilon ϵ -relative error.
Prototype
Let σ ⃗ = ( σ 1 , . . . , σ n ) ∈ { − 1 , 1 } n \vec \sigma = (\sigma_1, ..., \sigma_n) \in \{ - 1, 1 \}^n σ = ( σ 1 , ... , σ n ) ∈ { − 1 , 1 } n a sequence of n n n independent Rademachers.
Define
X ≐ < x ⃗ , σ ⃗ > , Y ≐ < y ⃗ , σ ⃗ > .
X \doteq \left< \vec x, \vec \sigma \right>, \qquad Y \doteq \left< \vec y, \vec \sigma \right>.
X ≐ ⟨ x , σ ⟩ , Y ≐ ⟨ y , σ ⟩ .
Theorem. X ⋅ Y X \cdot Y X ⋅ Y is an unbiased estimator of < x ⃗ , y ⃗ > \left< \vec x, \vec y \right> ⟨ x , y ⟩ .
Proof.
Observe ∀ i , j ∈ [ n ] \forall i, j \in [n] ∀ i , j ∈ [ n ] , if entries of σ \sigma σ are pairwise independent, then
E [ σ i σ j ] = { 1 , i = j 0 , i ≠ j .
\mathbb{E} [ \sigma_i \sigma_j ] = \begin{cases}
1, & i = j \\
0, & i \neq j
\end{cases}.
E [ σ i σ j ] = { 1 , 0 , i = j i = j . Hence,
E [ X ⋅ Y ] = E [ ( ∑ i ∈ [ n ] σ i x i ) ( ∑ j ∈ [ n ] σ j y j ) ] = ∑ i , j ∈ [ n ] E [ σ i σ j ] x i y j = ∑ i ∈ [ n ] x i y i .
\begin{aligned}
\mathbb{E} [ X \cdot Y ]
&= \mathbb{E} \left[ \left( \sum_{i \in [n] } \sigma_i x_i \right) \left( \sum_{j \in [n] } \sigma_j y_j \right) \right] \\
&= \sum_{i, j \in [n] } \mathbb{E} [ \sigma_i \sigma_j ]x_i y_j \\
&= \sum_{i \in [n] } x_i y_i.
\end{aligned}
E [ X ⋅ Y ] = E i ∈ [ n ] ∑ σ i x i j ∈ [ n ] ∑ σ j y j = i , j ∈ [ n ] ∑ E [ σ i σ j ] x i y j = i ∈ [ n ] ∑ x i y i . □ \square □
Theorem. V a r [ X ⋅ Y ] ≤ ∥ x ⃗ ∥ 2 2 ⋅ ∥ y ⃗ ∥ 2 2 \mathbb{Var}[ X \cdot Y ] \le \Vert \vec x \Vert_2^2 \cdot \Vert \vec y \Vert_2^2 V a r [ X ⋅ Y ] ≤ ∥ x ∥ 2 2 ⋅ ∥ y ∥ 2 2 .
Proof. If entries of σ \sigma σ are four-wise independent, then
V a r [ X ⋅ Y ] = V a r [ ( ∑ i ∈ [ n ] σ i x i ) ( ∑ j ∈ [ n ] σ j y j ) ] = V a r [ ∑ i ≠ j ∈ [ n ] σ i σ j x i y j ] = ∑ i ≠ j V a r [ σ i σ j x i y j ] + ∑ i ≠ j , k ≠ ℓ , ( i , j ) ≠ ( k , ℓ ) C o v [ σ i σ j x i y j , σ k σ ℓ x k y ℓ ] = ∑ i ≠ j x i 2 y j 2 ≤ ∥ x ⃗ ∥ 2 2 ⋅ ∥ y ⃗ ∥ 2 2
\begin{aligned}
\mathbb{Var} [ X \cdot Y ]
&= \mathbb{Var} \left[ \left( \sum_{i \in [n] } \sigma_i x_i \right) \left( \sum_{j \in [n] } \sigma_j y_j \right) \right] \\
&= \mathbb{Var} \left[ \sum_{i \neq j \in [n] } \sigma_i \sigma_j x_i y_j \right] \\
&= \sum_{i \neq j } \mathbb{Var} \left[ \sigma_i \sigma_j x_i y_j \right] + \sum_{i \neq j, k \neq \ell, (i, j) \neq (k, \ell) } \mathbb{Cov} [ \sigma_i \sigma_j x_i y_j, \sigma_k \sigma_\ell x_k y_\ell ]\\
&= \sum_{i \neq j } x_i^2 y_j^2 \\
&\le \Vert \vec x \Vert_2^2 \cdot \Vert \vec y \Vert_2^2
\end{aligned}
V a r [ X ⋅ Y ] = V a r i ∈ [ n ] ∑ σ i x i j ∈ [ n ] ∑ σ j y j = V a r i = j ∈ [ n ] ∑ σ i σ j x i y j = i = j ∑ V a r [ σ i σ j x i y j ] + i = j , k = ℓ , ( i , j ) = ( k , ℓ ) ∑ C o v [ σ i σ j x i y j , σ k σ ℓ x k y ℓ ] = i = j ∑ x i 2 y j 2 ≤ ∥ x ∥ 2 2 ⋅ ∥ y ∥ 2 2 □ \square □
If we have m m m independent copies of X X X and Y Y Y , denoted as X 1 , . . . , X m X_1, ..., X_m X 1 , ... , X m , and Y 1 , . . . , Y m Y_1, ..., Y_m Y 1 , ... , Y m , then we can compute the average ( 1 / m ) ⋅ ∑ i ∈ [ m ] X i ⋅ Y i (1 / m) \cdot \sum_{i \in [m] } X_i \cdot Y_i ( 1/ m ) ⋅ ∑ i ∈ [ m ] X i ⋅ Y i , whose variance is bounded by ( 1 / m ) ⋅ ∥ x ⃗ ∥ 2 2 ⋅ ∥ y ⃗ ∥ 2 2 (1 / m) \cdot \Vert \vec x \Vert_2^2 \cdot \Vert \vec y \Vert_2^2 ( 1/ m ) ⋅ ∥ x ∥ 2 2 ⋅ ∥ y ∥ 2 2 . If we set m = 1 / ϵ 2 m = 1 / \epsilon^2 m = 1/ ϵ 2 , then it becomes ϵ 2 ⋅ ∥ x ⃗ ∥ 2 2 ⋅ ∥ y ⃗ ∥ 2 2 \epsilon^2 \cdot \Vert \vec x \Vert_2^2 \cdot \Vert \vec y \Vert_2^2 ϵ 2 ⋅ ∥ x ∥ 2 2 ⋅ ∥ y ∥ 2 2 and by Chebyshev's inequality ∣ ( 1 / m ) ⋅ ∑ i ∈ [ m ] X i ⋅ Y i − < x ⃗ , y ⃗ > ∣ |(1 / m) \cdot \sum_{i \in [m] } X_i \cdot Y_i - \left< \vec x , \vec y \right> | ∣ ( 1/ m ) ⋅ ∑ i ∈ [ m ] X i ⋅ Y i − ⟨ x , y ⟩ ∣ is bounded by ϵ ⋅ ∥ x ⃗ ∥ 2 ⋅ ∥ y ⃗ ∥ 2 \epsilon \cdot \Vert \vec x \Vert_2 \cdot \Vert \vec y \Vert_2 ϵ ⋅ ∥ x ∥ 2 ⋅ ∥ y ∥ 2 with constant probability.
By Chernoff bound, we can boost the probability to 1 − δ 1 - \delta 1 − δ , by repeating the experiment O ( log 1 δ ) O(\log \frac{1}{\delta}) O ( log δ 1 ) times and taking the median of the estimation.
Computing ( 1 / m ) ⋅ ∑ i ∈ [ m ] X i ⋅ Y i (1 / m) \cdot \sum_{i \in [m] } X_i \cdot Y_i ( 1/ m ) ⋅ ∑ i ∈ [ m ] X i ⋅ Y i takes O ( 1 / ϵ 2 ) O( 1 / \epsilon^2 ) O ( 1/ ϵ 2 ) time. Repeating this O ( log 1 δ ) O(\log \frac{1}{ \delta}) O ( log δ 1 ) times and taking the median results in time complexity O ( log ( 1 / δ ) ϵ 2 ) O( \frac{\log (1 / \delta) }{\epsilon^2} ) O ( ϵ 2 l o g ( 1/ δ ) ) .
On the other hand, we construct O ( ϵ 2 ⋅ log 1 δ ) O ( \epsilon^2 \cdot \log \frac{1}{\delta} ) O ( ϵ 2 ⋅ log δ 1 ) copies of X X X , which takes time
O ( n ⋅ ϵ 2 ⋅ log 1 δ ) .
O ( n \cdot \epsilon^2 \cdot \log \frac{1}{\delta} ).
O ( n ⋅ ϵ 2 ⋅ log δ 1 ) . Algorithm
In this section, we show how to reduce the construction time to
O ( n ⋅ log 1 δ ) .
O ( n \cdot \log \frac{1}{\delta} ).
O ( n ⋅ log δ 1 ) . Given m ∈ N + m \in \mathbb{N}^+ m ∈ N + , let h : [ n ] → [ m ] h : [n] \rightarrow [m] h : [ n ] → [ m ] be a pairwise independent hash function.
Let X ⃗ = ( X 1 , . . . , X m ) , Y ⃗ = ( Y 1 , . . . , Y m ) ∈ R m \vec X = (X_1, ..., X_m), \vec Y = (Y_1, ..., Y_m) \in \mathbb{R}^m X = ( X 1 , ... , X m ) , Y = ( Y 1 , ... , Y m ) ∈ R m be random vectors, such that ∀ t ∈ [ m ] \forall t \in [m] ∀ t ∈ [ m ] ,
X t = ∑ i ∈ [ n ] : h ( i ) = t σ i x i , Y t = ∑ i ∈ [ n ] : h ( i ) = t σ i y i .
X_t = \sum_{ i \in [n] : h(i) = t } \sigma_i x_i, \\
Y_t = \sum_{ i \in [n] : h(i) = t } \sigma_i y_i.
X t = i ∈ [ n ] : h ( i ) = t ∑ σ i x i , Y t = i ∈ [ n ] : h ( i ) = t ∑ σ i y i .
Theorem. < X ⃗ , Y ⃗ > \left< \vec X, \vec Y \right> ⟨ X , Y ⟩ is an unbiased estimator of < x ⃗ , y ⃗ > \left< \vec x, \vec y \right> ⟨ x , y ⟩ .
Proof.
If entries of σ \sigma σ are pairwise independent, then
E [ < X ⃗ , Y ⃗ > ] = ∑ t ∈ [ m ] E [ X t Y t ] = ∑ t ∈ [ m ] E [ ∑ i , j ∈ [ n ] : h ( i ) = h ( j ) = t σ i σ j x i y j ] = ∑ t ∈ [ m ] E [ ∑ i ∈ [ n ] 1 m x i y i + ∑ i ≠ j 1 m 2 σ i σ j x i y j ] = ∑ i ∈ [ n ] x i y i
\begin{aligned}
\mathbb{E} \left[ \left< \vec X, \vec Y \right> \right]
&= \sum_{ t \in [m] } \mathbb{E}[ X_t Y_t ] \\
&= \sum_{ t \in [m] } \mathbb{E} \left[ \sum_{ i, j \in [n] : h(i) = h(j) = t } \sigma_i \sigma_j x_i y_j \right] \\
&= \sum_{ t \in [m] } \mathbb{E} \left[ \sum_{ i \in [n] } \frac{1}{m} x_i y_i + \sum_{ i \neq j } \frac{1}{m^2} \sigma_i \sigma_j x_i y_j\right] \\
&= \sum_{ i \in [n] } x_i y_i
\end{aligned}
E [ ⟨ X , Y ⟩ ] = t ∈ [ m ] ∑ E [ X t Y t ] = t ∈ [ m ] ∑ E i , j ∈ [ n ] : h ( i ) = h ( j ) = t ∑ σ i σ j x i y j = t ∈ [ m ] ∑ E i ∈ [ n ] ∑ m 1 x i y i + i = j ∑ m 2 1 σ i σ j x i y j = i ∈ [ n ] ∑ x i y i □ \square □
Theorem. V a r [ < X ⃗ , Y ⃗ > ] ≤ 1 m ⋅ ∥ x ⃗ ∥ 2 2 ⋅ ∥ y ⃗ ∥ 2 2 \mathbb{Var} \left[ \left< \vec X, \vec Y \right> \right] \le \frac{1}{m} \cdot \Vert \vec x \Vert_2^2 \cdot \Vert \vec y \Vert_2^2 V a r [ ⟨ X , Y ⟩ ] ≤ m 1 ⋅ ∥ x ∥ 2 2 ⋅ ∥ y ∥ 2 2 .
Proof. If entries of σ \sigma σ are four-wise independent, then
V a r [ < X ⃗ , Y ⃗ > ] = V a r [ ∑ t ∈ [ m ] X t Y t ] = V a r [ ∑ i , j ∈ [ n ] : h ( i ) = h ( j ) σ i σ j x i y j ] = V a r [ ∑ i ≠ j , h ( i ) = h ( j ) σ i σ j x i y j ] = ∑ i ≠ j V a r [ 1 [ h ( i ) = h ( j ) ] ⋅ σ i σ j x i y j ] + ∑ i ≠ j , k ≠ ℓ , ( i , j ) ≠ ( k , ℓ ) C o v [ 1 [ h ( i ) = h ( j ) ] ⋅ σ i σ j x i y j , 1 [ h ( k ) = h ( ℓ ) ] ⋅ σ k σ ℓ x k y ℓ ] = ∑ i ≠ j E [ ( 1 [ h ( i ) = h ( j ) ] ⋅ σ i σ j x i y j ) 2 ] = ∑ i ≠ j 1 m ⋅ x i 2 y j 2 ≤ 1 m ⋅ ∥ x ⃗ ∥ 2 2 ⋅ ∥ y ⃗ ∥ 2 2
\begin{aligned}
\mathbb{Var} \left[ \left< \vec X, \vec Y \right> \right]
&= \mathbb{Var} \left[ \sum_{ t \in [m] } X_t Y_t \right] \\
&= \mathbb{Var} \left[ \sum_{ i, j \in [n] : h(i) = h(j) } \sigma_i \sigma_j x_i y_j \right] \\
&= \mathbb{Var} \left[ \sum_{ i \neq j, h(i) = h(j) } \sigma_i \sigma_j x_i y_j \right] \\
&= \sum_{i \neq j } \mathbb{Var} \left[ 1_{ [ h(i) = h (j) ] } \cdot \sigma_i \sigma_j x_i y_j \right] \\
&\quad+ \sum_{i \neq j, k \neq \ell, (i, j) \neq (k, \ell) } \mathbb{Cov} [ 1_{ [ h(i) = h (j) ] } \cdot \sigma_i \sigma_j x_i y_j, 1_{ [ h(k) = h (\ell ) ] } \cdot \sigma_k \sigma_\ell x_k y_\ell ] \\
&= \sum_{i \neq j } \mathbb{E} \left[ \left( 1_{ [ h(i) = h (j) ] } \cdot \sigma_i \sigma_j x_i y_j \right)^2 \right] \\
&= \sum_{i \neq j } \frac{1}{m} \cdot x_i^2 y_j^2 \\
&\le \frac{1}{m} \cdot \Vert \vec x \Vert_2^2 \cdot \Vert \vec y \Vert_2^2
\end{aligned}
V a r [ ⟨ X , Y ⟩ ] = V a r t ∈ [ m ] ∑ X t Y t = V a r i , j ∈ [ n ] : h ( i ) = h ( j ) ∑ σ i σ j x i y j = V a r i = j , h ( i ) = h ( j ) ∑ σ i σ j x i y j = i = j ∑ V a r [ 1 [ h ( i ) = h ( j )] ⋅ σ i σ j x i y j ] + i = j , k = ℓ , ( i , j ) = ( k , ℓ ) ∑ C o v [ 1 [ h ( i ) = h ( j )] ⋅ σ i σ j x i y j , 1 [ h ( k ) = h ( ℓ )] ⋅ σ k σ ℓ x k y ℓ ] = i = j ∑ E [ ( 1 [ h ( i ) = h ( j )] ⋅ σ i σ j x i y j ) 2 ] = i = j ∑ m 1 ⋅ x i 2 y j 2 ≤ m 1 ⋅ ∥ x ∥ 2 2 ⋅ ∥ y ∥ 2 2 □ \square □
By setting m = 1 / ϵ 2 m = 1/ \epsilon^2 m = 1/ ϵ 2 , repeating the procedure O ( log 1 δ ) O(\log \frac{1}{\delta}) O ( log δ 1 ) times and taking the median as our estimation, we can obtained the desired result.
Reference
[1] G. Cormode and K. Yi, Small Summaries for Big Data, 1st ed. Cambridge University Press, 2020.
← Back to all notes Back to top ↑