高级算法 (Fall 2021)/Limited independence

From TCS Wiki
Revision as of 06:17, 29 September 2021 by imported>Etone (Collision number)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

k-wise independence

Recall the definition of independence between events:

Definition (Independent events)
Events E1,E2,,En are mutually independent if, for any subset I{1,2,,n},
Pr[iIEi]=iIPr[Ei].

Similarly, we can define independence between random variables:

Definition (Independent variables)
Random variables X1,X2,,Xn are mutually independent if, for any subset I{1,2,,n} and any values xi, where iI,
Pr[iI(Xi=xi)]=iIPr[Xi=xi].

Mutual independence is an ideal condition of independence. The limited notion of independence is usually defined by the k-wise independence.

Definition (k-wise Independenc)
1. Events E1,E2,,En are k-wise independent if, for any subset I{1,2,,n} with |I|k
Pr[iIEi]=iIPr[Ei].
2. Random variables X1,X2,,Xn are k-wise independent if, for any subset I{1,2,,n} with |I|k and any values xi, where iI,
Pr[iI(Xi=xi)]=iIPr[Xi=xi].

A very common case is pairwise independence, i.e. the 2-wise independence.

Definition (pairwise Independent random variables)
Random variables X1,X2,,Xn are pairwise independent if, for any Xi,Xj where ij and any values a,b
Pr[Xi=aXj=b]=Pr[Xi=a]Pr[Xj=b].

Note that the definition of k-wise independence is hereditary:

  • If X1,X2,,Xn are k-wise independent, then they are also -wise independent for any <k.
  • If X1,X2,,Xn are NOT k-wise independent, then they cannot be -wise independent for any >k.

Pairwise Independent Bits

Suppose we have m mutually independent and uniform random bits X1,,Xm. We are going to extract n=2m1 pairwise independent bits from these m mutually independent bits.

Enumerate all the nonempty subsets of {1,2,,m} in some order. Let Sj be the jth subset. Let

Yj=iSjXi,

where is the exclusive-or, whose truth table is as follows.

a b ab
0 0 0
0 1 1
1 0 1
1 1 0

There are n=2m1 such Yj, because there are 2m1 nonempty subsets of {1,2,,m}. An equivalent definition of Yj is

Yj=(iSjXi)mod2.

Sometimes, Yj is called the parity of the bits in Sj.

We claim that Yj are pairwise independent and uniform.

Theorem
For any Yj and any b{0,1},
Pr[Yj=b]=12.
For any Yj,Y that j and any a,b{0,1},
Pr[Yj=aY=b]=14.

The proof is left for your exercise.

Therefore, we extract exponentially many pairwise independent uniform random bits from a sequence of mutually independent uniform random bits.

Note that Yj are not 3-wise independent. For example, consider the subsets S1={1},S2={2},S3={1,2} and the corresponding random bits Y1,Y2,Y3. Any two of Y1,Y2,Y3 would decide the value of the third one.

Pairwise Independent Variables

We now consider constructing pairwise independent random variables ranging over [p]={0,1,2,,p1} for some prime p. Unlike the above construction, now we only need two independent random sources X0,X1, which are uniformly and independently distributed over [p].

Let Y0,Y1,,Yp1 be defined as:

Yi=(X0+iX1)modpfor i[p].
Theorem
The random variables Y0,Y1,,Yp1 are pairwise independent uniform random variables over [p].
Proof.
We first show that Yi are uniform. That is, we will show that for any i,a[p],
Pr[(X0+iX1)modp=a]=1p.

Due to the law of total probability,

Pr[(X0+iX1)modp=a]=j[p]Pr[X1=j]Pr[(X0+ij)modp=a]=1pj[p]Pr[X0(aij)(modp)].

For prime p, for any i,j,a[p], there is exact one value in [p] of X0 satisfying X0(aij)(modp). Thus, Pr[X0(aij)(modp)]=1/p and the above probability is 1p.

We then show that Yi are pairwise independent, i.e. we will show that for any Yi,Yj that ij and any a,b[p],

Pr[Yi=aYj=b]=1p2.

The event Yi=aYj=b is equivalent to that

{(X0+iX1)a(modp)(X0+jX1)b(modp)

Due to the Chinese remainder theorem, there exists a unique solution of X0 and X1 in [p] to the above linear congruential system. Thus the probability of the event is 1p2.

Universal Hashing

Hashing is one of the oldest tools in Computer Science. Knuth's memorandum in 1963 on analysis of hash tables is now considered to be the birth of the area of analysis of algorithms.

  • Knuth. Notes on "open" addressing, July 22 1963. Unpublished memorandum.

The idea of hashing is simple: an unknown set S of n data items (or keys) are drawn from a large universe U=[N] where Nn; in order to store S in a table of M entries (slots), we assume a consistent mapping (called a hash function) from the universe U to a small range [M].

This idea seems clever: we use a consistent mapping to deal with an arbitrary unknown data set. However, there is a fundamental flaw for hashing.

  • For sufficiently large universe (N>M(n1)), for any function, there exists a bad data set S, such that all items in S are mapped to the same entry in the table.

A simple use of pigeonhole principle can prove the above statement.

To overcome this situation, randomization is introduced into hashing. We assume that the hash function is a random mapping from [N] to [M]. In order to ease the analysis, the following ideal assumption is used:

Simple Uniform Hash Assumption (SUHA or UHA, a.k.a. the random oracle model):

A uniform random function h:[N][M] is available and the computation of h is efficient.

Families of universal hash functions

The assumption of completely random function simplifies the analysis. However, in practice, truly uniform random hash function is extremely expensive to compute and store. Thus, this simple assumption can hardly represent the reality.

There are two approaches for implementing practical hash functions. One is to use ad hoc implementations and wish they may work. The other approach is to construct class of hash functions which are efficient to compute and store but with weaker randomness guarantees, and then analyze the applications of hash functions based on this weaker assumption of randomness.

This route was took by Carter and Wegman in 1977 while they introduced universal families of hash functions.

Definition (universal hash families)
Let [N] be a universe with NM. A family of hash functions H from [N] to [M] is said to be k-universal if, for any items x1,x2,,xk[N] and for a hash function h chosen uniformly at random from H, we have
Pr[h(x1)=h(x2)==h(xk)]1Mk1.
A family of hash functions H from [N] to [M] is said to be strongly k-universal if, for any items x1,x2,,xk[N], any values y1,y2,,yk[M], and for a hash function h chosen uniformly at random from H, we have
Pr[h(x1)=y1h(x2)=y2h(xk)=yk]=1Mk.

In particular, for a 2-universal family H, for any elements x1,x2[N], a uniform random hH has

Pr[h(x1)=h(x2)]1M.

For a strongly 2-universal family H, for any elements x1,x2[N] and any values y1,y2[M], a uniform random hH has

Pr[h(x1)=y1h(x2)=y2]=1M2.

This behavior is exactly the same as uniform random hash functions on any pair of inputs. For this reason, a strongly 2-universal hash family are also called pairwise independent hash functions.

2-universal hash families

The construction of pairwise independent random variables via modulo a prime introduced in Section 1 already provides a way of constructing a strongly 2-universal hash family.

Let p be a prime. The function ha,b:[p][p] is defined by

ha,b(x)=(ax+b)modp,

and the family is

H={ha,ba,b[p]}.
Lemma
H is strongly 2-universal.
Proof.
In Section 1, we have proved the pairwise independence of the sequence of (ai+b)modp, for i=0,1,,p1, which directly implies that H is strongly 2-universal.
The original construction of Carter-Wegman

What if we want to have hash functions from [N] to [M] for non-prime N and M? Carter and Wegman developed the following method.

Suppose that the universe is [N], and the functions map [N] to [M], where NM. For some prime pN, let

ha,b(x)=((ax+b)modp)modM,

and the family

H={ha,b1ap1,b[p]}.

Note that unlike the first construction, now a0.

Lemma (Carter-Wegman)
H is 2-universal.
Proof.
Due to the definition of H, there are p(p1) many different hash functions in H, because each hash function in H corresponds to a pair of 1ap1 and b[p]. We only need to count for any particular pair of x1,x2[N] that x1x2, the number of hash functions that h(x1)=h(x2).

We first note that for any x1x2, ax1+bax2+b(modp). This is because ax1+bax2+b(modp) would imply that a(x1x2)0(modp), which can never happen since 1ap1 and x1x2 (note that x1,x2[N] for an Np). Therefore, we can assume that (ax1+b)modp=u and (ax2+b)modp=v for uv.

Due to the Chinese remainder theorem, for any x1,x2[N] that x1x2, for any u,v[p] that uv, there is exact one solution to (a,b) satisfying:

{ax1+bu(modp)ax2+bv(modp).

After modulo M, every u[p] has at most p/M1 many v[p] that vu but vu(modM). Therefore, for every pair of x1,x2[N] that x1x2, there exist at most p(p/M1)p(p1)/M pairs of 1ap1 and b[p] such that ((ax1+b)modp)modM=((ax2+b)modp)modM, which means there are at most p(p1)/M many hash functions hH having h(x1)=h(x2) for x1x2. For h uniformly chosen from H, for any x1x2,

Pr[h(x1)=h(x2)]p(p1)/Mp(p1)=1M.

We prove that H is 2-universal.

A construction used in practice

The main issue of Carter-Wegman construction is the efficiency. The mod operation is very slow, and has been so for more than 30 years.

The following construction is due to Dietzfelbinger et al. It was published in 1997 and has been practically used in various applications of universal hashing.

The family of hash functions is from [2u] to [2v]. With a binary representation, the functions map binary strings of length u to binary strings of length v. Let

ha(x)=axmod2u2uv,

and the family

H={haa[2v] and a is odd}.

This family of hash functions does not exactly meet the requirement of 2-universal family. However, Dietzfelbinger et al proved that H is close to a 2-universal family. Specifically, for any input values x1,x2[2u], for a uniformly random hH,

Pr[h(x1)=h(x2)]12v1.

So H is within an approximation ratio of 2 to being 2-universal. The proof uses the fact that odd numbers are relative prime to a power of 2.

The function is extremely simple to compute in c language. We exploit that C-multiplication (*) of unsigned u-bit numbers is done mod2u, and have a one-line C-code for computing the hash function:

h_a(x) = (a*x)>>(u-v)

The bit-wise shifting is a lot faster than modular. It explains the popularity of this scheme in practice than the original Carter-Wegman construction.