Let XX be a Bernoulli random variable with unknown probability

P[X=1]=μ.P[X=0]=1−μ \begin{aligned} P[X = 1] &= \mu. \\ P[X = 0] &= 1 - \mu \end{aligned}

where 1n≤μ≤1\frac{1}{n} \le \mu \le 1 for some integer n>0n > 0. The goal is to estimate μ\mu (denoted by μ~\tilde \mu) via sampling.

By law of large number, μ~\tilde \mu converges to μ\mu when we sample enough numbers of XX. The convergence behavior is captured by Chernoff inequality and O(1δ2μlog⁡1pfail)O(\frac{1}{\delta^2 \mu}\log{1 \over p_{fail} }) samples are needed to get an estimation μ~\tilde \mu such that P[μ~∈(1±δ)μ]≥1−pfailP [ \tilde \mu \in (1 \pm \delta) \mu] \ge 1 - p_{fail} (See Exercise 1). Such an μ~\tilde \mu is called an (δ,pfail)(\delta, p_{fail})-estimation of μ\mu.

As μ≥1n\mu \ge \frac{1}{n}, O(nδ2log⁡1pfail)O(\frac{n}{\delta^2}\log{1 \over p_{fail} }) samples are enough. The problem is, if μ\mu is much larger than 1/n1/n, we waste a lot of samples. E.g., when n=1000n = 1000 and μ=12\mu = \frac{1}{2}, 1δ2μlog⁡1pfail\frac{1}{\delta^2 \mu}\log{1 \over p_{fail} } gives us 2δ2log⁡1pfail\frac{2}{\delta^2}\log{1 \over p_{fail} } while nδ2log⁡1pfail\frac{n}{\delta^2}\log{1 \over p_{fail} } equals to 1000δ2log⁡1pfail\frac{1000}{\delta^2}\log{1 \over p_{fail} }.

Can we obtain an (δ,pfail)(\delta, p_{fail})-estimation μ~\tilde \mu with just O(1δ2μlog⁡1pfail)O(\frac{1}{\delta^2 \mu}\log{1 \over p_{fail} }) samples, even though μ\mu itself is unknown?

Yes we can (with the lost of a factor log⁡log⁡n\log \log n, which is almost negligible). First we relax the goal a little bit -- finding a μ~∈[μ/2,2μ]\tilde \mu \in [\mu/2, 2 \mu] instead of a μ~∈(1±δ)μ\tilde \mu \in (1 \pm \delta) \mu. We show how to achieve this with O(1μlog⁡log⁡npfail)O(\frac{1}{\mu}\log{\log n \over p_{fail} }) samples.

The high level idea is to divide [1n,1][\frac{1}{n}, 1] into a set of intervals

{[1n,12log⁡n−1],...,[12i,12i−1],...,,[14,12],[12,1]} \{ [\frac{1}{n}, \frac{1}{2^{ \log n -1} }], ..., [\frac{1}{2^{i} }, \frac{1}{2^{i - 1} }], ...,, [\frac{1}{4}, \frac{1}{2}], [\frac{1}{2}, 1]\}

Let [12j,12j−1][\frac{1}{2^{j} }, \frac{1}{2^{j - 1} }] (j∈N)(j \in N) be the interval that uu belongs to.

Figure

Given an integer ii, such that i≤j−2i \le j - 2 or i≥j+1i \ge j + 1, we can determine whether μ≥12i\mu \ge \frac{1}{2^i} with high probability. We generate O(2ilog⁡log⁡npfail)O(2^i \log \frac{\log n}{p_{fail} }) samples and test whether their average (i.e., μ~\tilde \mu) is greater than 12i\frac{1}{2^i}. If μ~>12i\tilde \mu > \frac{1}{2^i}, by Chernoff inequality, μ>12i\mu > \frac{1}{2^i} with high probability and the test returns true.

To search for the interval [12j,12j−1][\frac{1}{2^{j} }, \frac{1}{2^{j - 1} }] that μ\mu belongs to, we perform the test for increasing values of i=1,2,...i = 1, 2, ... until we find the first ii, such that the test for μ≥12i\mu \ge \frac{1}{2^i} returns true. We claim that with high probability, ii takes one of the following values: {j−1,j,j+1}\{j - 1, j, j + 1 \}. The reason is that the test returns false (with high probability) when i≤j−2i \le j - 2. The results for i=j−1i = j - 1 and jj are undetermined. Even if the test fails to return true for both i=j−1i = j - 1 and jj, it returns true for i=j+1i = j + 1 with high probability.

Finally, after we find an i∈{j−1,j,j+1}i \in \{j - 1, j, j + 1 \}, we know that μ≥12⋅2i\mu \ge \frac{1}{2 \cdot 2^i}. Therefore, O(2ilog⁡log⁡npfail)O(2^i \log \frac{\log n}{p_{fail} }) samples gives an (δ,pfail)(\delta, p_{fail})-estimate of μ\mu.

Then the total number of samples we generate is at most:

∑k=1j+1O(2klog⁡log⁡npfail)=O(2j+2log⁡log⁡npfail)=O(1μlog⁡log⁡npfail) \sum_{k = 1}^{j+1}O(2^k\log \frac{\log n}{p_{fail} }) = O(2^{j+2}\log \frac{\log n}{p_{fail} }) = O(\frac{1}{\mu}\log \frac{\log n}{p_{fail} })

The procedure code is shown by Algorithm 1.

Algorithm 1

  1. for i←1i \leftarrow 1 to log⁡n−1\log n - 1 do
  2. \quad Let θ=6⋅2ilog⁡log⁡npfail\theta = 6 \cdot 2^i \log \frac{\log n}{p_{fail} }.
  3. \quad Let Y=0Y = 0
  4. \quad for j←1j \leftarrow 1 to θ\theta do
  5. \quad\quad Generate a sample of XX, denoted by XjX_j.
  6. \quad\quad Y=Y+XjY = Y + X_j.
  7. \quad if Yθ>12i\frac{Y}{\theta} > \frac{1}{2^i} then
  8. \quad \quad return Yθ\frac{Y}{\theta}
  9. return 1n\frac{1}{n}

To analyse Algorithm 1, we use the following Chernoff Bounds.

Chernoff Bound

Let X1,X2,...,XθX_1, X_2, ..., X_\theta be i.i.d.i.i.d. Bernoulli random variables with mean μ\mu and Y=1θ∑k=1θXkY = \frac{1}{\theta} \sum_{k =1}^\theta X_k. Then

  1. P[Y≥(1+δ)μ]≤exp⁡(−δ2δ+2θμ)P[Y \ge (1 + \delta) \mu] \le \exp(- \frac{\delta^2}{\delta + 2} \theta \mu).
  2. P[Y≤(1−δ)μ]≤exp⁡(−δ22θμ)P[Y \le (1 - \delta) \mu] \le \exp(- \frac{\delta^2}{2} \theta \mu)

Corollary

For an integer k≥1k \ge 1,

  1. P[Y≥2kμ]≤exp⁡(−(2k−1)22k+1θμ)≤exp⁡(−22k−22k+1θμ)=exp⁡(−2k4(1+1/2k)θμ)≤exp⁡(−2k6θμ)P[Y \ge 2^k \mu] \le \exp (- \frac{(2^k -1)^2}{2^k + 1} \theta \mu) \le \exp(- \frac{2^{2k - 2} }{2^k + 1} \theta \mu) = \exp(-\frac{2^k}{4(1+ {1} / {2^k})} \theta \mu) \le \exp(-\frac{2^k}{6} \theta \mu)
  2. P[Y≤12kμ]≤exp⁡(−(1−12k)22θμ)≤exp⁡(−18θμ)P[Y \le \frac{1}{2^k}\mu] \le \exp(-\frac{(1-\frac{1}{2^k})^2}{2} \theta \mu) \le \exp(-\frac{1}{8}\theta \mu)

Theorem

Let X1,X2,...,XθX_1, X_2, ..., X_\theta be i.i.d.i.i.d. Bernoulli random variables with mean μ∈[12j,12j−1]\mu \in [\frac{1}{2^j}, \frac{1}{2^{j - 1} }] and Y=1θ∑k=1θXkY = \frac{1}{\theta} \sum_{k =1}^\theta X_k. Suppose θ=6⋅2ilog⁡log⁡npfail\theta = 6 \cdot 2^i \log \frac{\log n}{p_{fail} } for some ii, then

  1. P[Y≥12i]≤pfaillog⁡nP[Y \ge \frac{1}{2^i}] \le \frac{p_{fail} }{\log n}, if i≤j−2i \le j - 2,
  2. P[Y≤12i]≤pfail2i−j−1log⁡nP[Y \le \frac{1}{2^i}] \le \frac{p_{fail} }{2^{i - j - 1} \log n}, if i≥j+1i \ge j + 1.

Proof: First consider i≤j−2i \le j - 2. Then 12i≥2j−1−iμ\frac{1}{2^i} \ge 2^{j - 1 - i} \mu , 2j−1μ≥12^{j - 1} \mu \ge 1 and

P[Y≥12i]≤P[Y≥2j−1−iμ]≤exp⁡(−2j−1−i6θμ)=exp⁡(−2j−1μ⋅2−iθ6)≤exp⁡(−2−iθ6)≤pfaillog⁡n \begin{aligned} P[Y \ge \frac{1}{2^i}] &\le P[Y \ge 2^{j - 1 - i} \mu] \\ &\le \exp(-\frac{2^{j- 1 - i} }{6}\theta \mu) \\ &= \exp(-\frac{2^{j - 1} \mu \cdot 2^{-i}\theta}{6}) \\ &\le\exp(-\frac{2^{-i}\theta}{6}) \\ &\le \frac{p_{fail} }{\log n} \end{aligned}

For i≥j+1i \ge j + 1, we have 12i≤12i−jμ\frac{1}{2^{i} } \le \frac{1}{2^{i - j} } \mu , i−j≥1i - j \ge 1 and

P[Y≤12i]≤P[Y≤12i−jμ]≤exp⁡(−μθ8)≤exp⁡(−2−jθ8)≤pfail2i−j−1log⁡n \begin{aligned} P[ Y \le \frac{1}{2^{i} }] &\le P [Y \le \frac{1}{2^{i - j} } \mu] \\ &\le \exp(-\frac{\mu \theta}{8}) \\ &\le \exp(-\frac{2^{-j}\theta }{8}) \\ &\le \frac{p_{fail} }{2^{i - j -1}\log n} \end{aligned}

It follows that by union bound the test fails for all i=1,2,...,j−2,j+1i = 1, 2, ..., j - 2, j + 1 is at most pfaillog⁡n⋅(j−1)≤pfail\frac{p_{fail} }{\log n} \cdot (j - 1) \le p_{fail}.

Exercise
  1. Given a Bernoulli random variable XX with mean μ\mu, prove that (with Chernoff bound) if we generate Ω(1δ2μlog⁡1pfail)\Omega(\frac{1}{\delta^2 \mu}\log{1 \over p_{fail} }) independent samples, we get an estimate of XX with relative error δ\delta with probability 1−pfail1 - p_{fail}.
Reference:
  1. Tang Youze, Xiaokui Xiao, and Yanchen Shi. "Influence maximization: Near-optimal time complexity meets practical efficiency." Proceedings of the 2014 ACM SIGMOD international conference on Management of data. ACM, 2014.