Probabilistic arguments are a key tool for the analysis of algorithms in machine learning theory and probability theory. They also assume a prominent role in the analysis of randomized and streaming algorithms, where one imposes a restriction on the amount of storage space an algorithm is allowed to use for its computations (usually sublinear in the size of the input).

While a whole host of probabilistic arguments are used, one theorem in particular (or family of theorems) is ubiquitous: the Chernoff bound. In its simplest form, the Chernoff bound gives an *exponential* bound on the deviation of sums of random variables from their expected value.

This is perhaps most important to algorithm analysis in the following mindset. Say we have a program whose output is a random variable . Moreover suppose that the expected value of is the correct output of the algorithm. Then we can run the algorithm multiple times and take a median (or some sort of average) across all runs. The probability that the algorithm gives a *wildly* incorrect answer is the probability that more than half of the runs give values which are wildly far from their expected value. Chernoff’s bound ensures this will happen with small probability.

So this post is dedicated to presenting the main versions of the Chernoff bound that are used in learning theory and randomized algorithms. Unfortunately the *proof* of the Chernoff bound in its full glory is beyond the scope of this blog. However, we will give short proofs of weaker, simpler bounds as a straightforward application of this blog’s previous work laying down the theory.

If the reader has not yet intuited it, this post will rely heavily on the mathematical formalisms of probability theory. We will assume our reader is familiar with the material from our first probability theory primer, and it certainly wouldn’t hurt to have read our conditional probability theory primer, though we won’t use conditional probability directly. We will refrain from using measure-theoretic probability theory entirely (some day my colleagues in analysis will like me, but not today).

## Two Easy Bounds of Markov and Chebyshev

The first bound we’ll investigate is almost trivial in nature, but comes in handy. Suppose we have a random variable which is non-negative (as a function). Markov’s inequality is the statement that, for any constant ,

In words, the probability that grows larger than some fixed constant is bounded by a quantity that is inversely proportional to the constant.

The proof is quite simple. Let be the indicator random variable for the event that ( when and zero otherwise). As with all indicator random variables, the expected value of is the probability that the event happens (if this is mysterious, use the definition of expected value). So , and linearity of expectation allows us to include a factor of :

The rest of the proof is simply the observation that . Indeed, as random variables we have the inequality . Whenever , the former is equal to zero while the latter is nonnegative. And whenever , the former is precisely while the latter is by assumption at least . It follows that .

This last point is a simple property of expectation we omitted from our first primer. It usually goes by *monotonicity of expectation,* and we prove it here. First, if then (this is trivial). Second, if , then define a new random variable . Since and using linearity of expectation, it must be that . Hence . Note that we do require that has a finite expected value for this argument to work, but if this is not the case then Markov’s inequality is nonsensical anyway.

Markov’s inequality by itself is not particularly impressive or useful. For example, if is the number of heads in a hundred coin flips, Markov’s inequality ensures us that the probability of getting at least 99 heads is at most 50/99, which is about 1/2. Shocking. We know that the true probability is much closer to , so Markov’s inequality is a bust.

However, it does give us a more useful bound as a corollary. This bound is known as Chebyshev’s inequality, and its use is sometimes referred to as the *second moment method* because it gives a bound based on the variance of a random variable (instead of the expected value, the “first moment”).

The statement is as follows.

**Chebyshev’s Inequality: **Let be a random variable with finite expected value and positive variance. Then we can bound the probability that deviates from its expected value by a quantity that is proportional to the variance of . In particular, for any ,

And without any additional assumptions on , this bound is sharp.

*Proof.* The proof is a simple application of Markov’s inequality. Let , so that . Then by Markov’s inequality

Since is nonnegative , and . The theorem is proved.

Chebyshev’s inequality shows up in so many different places (and usually in rather dry, technical bits), that it’s difficult to give a good example application. Here is one that shows up somewhat often.

Say is a nonnegative integer-valued random variable, and we want to argue about when versus when , given that we know . No matter how large is, it can still be possible that is arbitrarily close to 1. As a colorful example, let is the number of alien lifeforms discovered in the next ten years. We might debate that can arbitrarily large: if some unexpected scientific and technological breakthroughs occur tomorrow, we could discover an unbounded number of lifeforms. On the other hand, we are very likely not to discover any, and probability theory allows for such a random variable to exist.

If we know everything about , however, we can get more informed bounds.

**Theorem: **If , then .

*Proof.* Simply choose and apply Chebyshev’s inequality.

The first inequality follows from the fact that the only time can ever be zero is when , and only accounts for one such possibility.

This theorem says more. If we know that is significantly smaller than , then is more certain to occur. More precisely, and more computationally minded, suppose we have a sequence of random variables so that as . Then the theorem says that if , then . Remembering one of our very early primers on asymptotic notation, means that grows asymptotically slower than , and in terms of this fraction , this means that the denominator dominates the fraction so that the whole thing tends to zero.

## The Chernoff Bound

The Chernoff bound takes advantage of an additional hypothesis: our random variable is a sum of independent coin flips. We can use this to get exponential bounds on the deviation of the sum. More rigorously,

**Theorem: **Let be independent random -valued variables, and let . Suppose that . Then the probability that deviates from by more than a factor of is bounded from above:

The proof is beyond the scope of this post, but we point the interested reader to these lecture notes.

We can apply the Chernoff bound in an easy example. Say all are fair coin flips, and we’re interested in the probability of getting more than 3/4 of the coins heads. Here and , so the probability is bounded from above by

So as the number of coin flips grows, the probability of seeing such an occurrence diminishes extremely quickly to zero. This is important because if we want to *test* to see if, say, the coins are biased toward flipping heads, we can simply run an experiment with sufficiently large. If we observe that more than 3/4 of the flips give heads, then we proclaim the coins are biased and we can be assured we are correct with high probability. Of course, after seeing 3/4 of more heads we’d be *really* confident that the coin is biased. A more realistic approach is to define some that is small enough so as to say, “if some event occurs whose probability is smaller than , then I call shenanigans.” Then decide how many coins and what bound one would need to make the bad event have probability approximately . Finding this balance is one of the more difficult aspects of probabilistic algorithms, and as we’ll see later all of these quantities are left as variables and the correct values are discovered in the course of the proof.

## Chernoff-Hoeffding Inequality

The Hoeffding inequality (named after the Finnish statistician, Wassily Høffding) is a variant of the Chernoff bound, but often the bounds are collectively known as Chernoff-Hoeffding inequalities. The form that Hoeffding is known for can be thought of as a simplification and a slight generalization of Chernoff’s bound above.

**Theorem: **Let be independent random variables whose values are within some range . Call , , and . Then for all ,

For example, if we are interested in the sum of rolls of a fair six-sided die, then the probability that we deviate from by more than is bounded by . Supposing we want to know how many rolls we need to guarantee with probability 0.01 that we don’t deviate too much, we just do the algebra:

So with 15 rolls we can be confident that the sum of the rolls will lie between 20 and 85. It’s not the best possible bound we could come up with, because we’re completely ignoring the known structure on dice rolls (that they follow a uniform distribution!). The benefit is that it’s a quick and easy bound that works for *any* kind of random variable with that expected value.

Another version of this theorem concerns the *average* of the , and is only a minor modification of the above.

**Theorem:** If are as above, and , with , then for all , we get the following bound

The only difference here is the extra factor of in the exponent. So the deviation is exponential both in the amount of deviation (), and in the number of trials.

This theorem comes up very often in learning theory, in particular to prove Boosting works. Mathematicians will joke about how all theorems in learning theory are just applications of Chernoff-Hoeffding-type bounds. We’ll of course be seeing it again as we investigate boosting and the PAC-learning model in future posts, so we’ll see the theorems applied to their fullest extent then.

Until next time!