24.1 Random Variables
In Section 1.6, we built probability by counting. A die has six faces, a label belongs to one of ten classes, and the probability of an event is simply the sum of the probabilities of its outcomes. Most of the numbers a neural network works with are not like that. A pixel intensity, a weight drawn at initialization, or the Gaussian noise that a diffusion model adds to an image can each take any value in an interval, and there are far too many values to list one by one. What, then, is the probability of a single one of them?
Think of a dart thrown at a round board so carelessly that it is equally likely to land anywhere on the board, and suppose it comes to rest at half the radius from the center. Asked how likely that was, we would round the distance (say, to between and radii), which happens about one time in ten. Asking for one more digit of precision makes the probability ten times smaller, and another digit makes it ten times smaller again. With infinitely many digits, the probability is zero, and yet the dart clearly landed somewhere.
The way out is to stop asking for the probability of a single point and ask instead how fast probability accumulates near it. Each time we narrow the interval tenfold, its probability drops tenfold, so the ratio of probability to width stays constant. This probability per unit length is the density. With it, every tool of discrete probability carries over to quantities that vary continuously, with sums replaced by integrals.
Some of what follows revisits Section 1.6, now extended to continuous variables and backed by proofs: we already motivated the mean and variance there, so we move straight to their continuous forms and algebra. Alongside them, we introduce the density itself, a general method for drawing samples from the cumulative distribution function, the tail bounds of Markov and Chebyshev, and a bell-shaped density whose tails are so heavy that both bounds fail. If you carry only two results out of this section, make them the relationship between the density and the cumulative distribution function (24.1.6) and Markov's inequality (24.1.14), from which the rest of this chapter's tail bounds descend. We follow the dart throughout, focusing on a single number, its distance from the center, and leave its two coordinates and transformations of densities for Section 24.2.
24.1.1 Densities#
We develop the idea of a density in three steps: first at a single point, as the limit of ever narrower bins; next over an interval, as an area under a curve; and finally through the function that accumulates that area, which also gives us a practical way to draw random samples.
24.1.1.1 From Bins to a Density#
To make "probability per unit length" precise, we first need the probability that the dart lands within a given range of distances. Let be the dart's distance from the center of a board of radius . The dart lands within distance of the center whenever it hits the disk of radius . Because every part of the board is equally likely, this probability is simply that disk's share of the board's area:
Half the radius holds only a quarter of the probability, because it holds only a quarter of the area. A bin of width centered at therefore has probability , which produces the numbers from our opening example:
| bin | width | probability | probability |
|---|---|---|---|
Each tenfold narrowing divides the probability by ten, leaving the ratio unchanged. That limiting ratio is the quantity we want to name. The probability density of a random variable at is the probability per unit length near ,
wherever this limit exists. Equivalently, for a short interval, the probability is approximately its length times the density,
with an error that shrinks faster than . This describes the density one point at a time, which is all we need for now; we give the formal definition in terms of intervals in the next subsection. For our dart at any distance in , the interval has probability . Dividing by the width gives , and letting yields
The density grows linearly from the center to the rim, mirroring the circumference of the circle at radius : there is simply more board farther out. At the density equals , matching the ratio in the table above.
Notice that a density is not a probability. At , the dart's density is , and a variable that is equally likely to land anywhere in has density on that interval, since it packs a total probability of into a length of . A density can take any non-negative value, though it can exceed only on a set of total length less than , or else the probability of that set would exceed . Think of a density as a rate, much like speed. A car's speed tells you how fast distance accumulates, not how far the car has traveled. In the same way, a density of at tells you how fast probability accumulates as increases past , not how much probability sits at the point itself.
Because a single point has zero length, it also carries zero probability. For every , the point lies inside , so is at most about , which vanishes as shrinks to zero. Thus, for any random variable with a density,
This resolves our opening puzzle: the dart lands at distance with probability zero, just as it does at every other exact distance, and yet it must land somewhere. In continuous probability, an event of probability zero is not impossible.
A single point that does carry positive probability is called an atom. A variable with a density has no atoms, whereas a discrete variable such as a die roll consists entirely of atoms. Some variables have both. For example, the output of a ReLU unit fed a standard normal input equals with probability (an atom) and spreads the remaining half of its probability over with a density (Exercise 2 works out the details).
The table above came from an exact area formula, but a simulation needs no formula at all. To throw darts uniformly at the circular board, a computer can throw them uniformly at the surrounding square and keep only those that land inside the circle, which leaves every part of the board equally likely. Below, we count the fraction of darts falling in each of our three bins and divide by the bin width.
rng = np.random.default_rng()
xy = rng.uniform(-1, 1, size=(4 * 10**6, 2)) # darts on the square
on_board = (xy**2).sum(axis=1) <= 1 # keep those on the board
r_dart = np.linalg.norm(xy[on_board], axis=1) # distances R
for width in [0.1, 0.01, 0.001]:
prob = np.mean(np.abs(r_dart - 0.5) <= width / 2) # fraction in the bin
print(f'width {width:<5} probability {prob:.5f} ratio {prob / width:.3f}')width 0.1 probability 0.09983 ratio 0.998
width 0.01 probability 0.01002 ratio 1.002
width 0.001 probability 0.00099 ratio 0.990
As expected, each tenfold narrowing reduces the fraction tenfold while keeping the ratio close to . What the exact table hid, however, is how noisy a very narrow bin becomes in practice. Roughly million of the four million darts land on the board, and only about of those fall into the bin of width , so the final ratio fluctuates by a few percent from run to run.
24.1.1.2 Probability as Area#
So far we have read the density off from the probabilities of tiny intervals. Now let us reverse the direction: given a density, how do we find the probability of a full interval? Partition the real line into bins of width . By (24.1.1), each bin has probability roughly , and because the bins are disjoint, their probabilities add. Summing widths times heights forms a Riemann sum, which approaches the area under the curve, namely the integral (Section 22.6), as shrinks to zero. Since must take some real value, all bins together have probability one:
Summing only the bins between and suggests that the probability of an interval is simply the area under the density above it. Strictly speaking, this argument is motivation rather than a proof: there are roughly bins, and their individual errors, each small compared with , sum to a negligible total only if they shrink uniformly across . To put things on solid footing, we turn this area formula into our formal definition.
Definition. A random variable has the density when and, for all ,
Letting and confirms that the total area under any density is . In fact, these two conditions, non-negativity () and unit total area, are all a function needs to qualify as a valid density. Figure 24.1.1 illustrates this definition for a density with two peaks. Our dart passes the test as well: for , the integral recovers the area-based probability , confirming that is indeed its density. In particular, the probability of landing in the outer half of the radius is : fully three quarters of the board lies more than half the radius from the center.
A probability density . The total area under the curve is ; the probability that lands in the interval from to is the area of the shaded slab above it, . The density itself is not a probability (it may exceed ); only its integral over an interval is.
24.1.1.3 The Cumulative Distribution Function#
Often it is convenient to work with a function whose values are genuine probabilities, and one that handles discrete and continuous variables alike. The cumulative distribution function (c.d.f.) of gives the probability that lands at or below . When has a density, this is simply the area under the density to the left of :
In other words, sweeps across the real line from left to right, accumulating probability as it goes. It starts at as and rises to as . It can never decrease, because the non-negative density only adds area, and whenever has a density, is continuous. For our dart, we computed it at the very beginning: for , for , and for . That function is where we started, and the density came directly from it.
Unlike a density, the c.d.f. is defined for every random variable. A fair coin that reports or has
which is a staircase that jumps upward by the probability of each atom. Because includes any atom sitting right at , the function takes the upper value at every jump. More generally, every c.d.f. is right-continuous, meaning . A mixed variable combines both behaviors: the ReLU output mentioned earlier has a c.d.f. that is for , jumps to at , and then climbs smoothly toward . A single function therefore unifies discrete, continuous, and mixed random variables; Figure 24.1.2 shows one of each.
Three cumulative distribution functions. (a) The dart's distance from the center: rises continuously from to . (b) A fair coin reporting or : a staircase that jumps by at each atom and takes the upper value there (filled dots). (c) The ReLU of a standard Gaussian: is for , jumps to at , and from there follows the Gaussian c.d.f. .
When a density exists, the c.d.f. and the density carry the same information: integrating produces , and differentiating recovers . This brings back our opening limit of shrinking bins, now established as a theorem.
Proposition (density is the derivative of the c.d.f.). If has a density that is continuous at , then is differentiable at and
In particular, the probability per unit length tends to as .
Proof. By (24.1.5), is the area-so-far function of . The fundamental theorem of calculus says that the derivative of an area-so-far function is the integrand at every point where the integrand is continuous (Section 22.6). For the second statement, the single point has probability at most for every , and these integrals tend to zero with . Including or excluding an endpoint therefore changes nothing, so , and the ratio is simply a difference quotient of .
For the dart, on , recovering the density we found from the bins. Figure 24.1.3 places the two functions side by side: the shaded area on the left equals the vertical rise on the right.
Left: a density with the area over the interval from to shaded. Right: the matching c.d.f. , an increasing curve from to ; the rise equals the shaded area on the left. The density is the slope of the c.d.f. and the c.d.f. is the accumulated area under the density.
24.1.1.4 Quantiles and Inverse-Transform Sampling#
Computers give us ready access to random numbers that are equally likely to fall anywhere between and . To simulate the dart, or any other continuous distribution, we need a way to turn those uniform draws into samples from our target distribution.
Our building block is the simplest density of all. A random variable is uniform on if its density is on and elsewhere. Every subinterval of then has probability equal to its length, and the c.d.f. is simply for .
The c.d.f. maps a value to a probability level . Reversing that map, asking for the value below which a given fraction of the probability lies, yields the quantile function. Whenever is continuous and strictly increasing on the interval where , it maps one-to-one onto , and its inverse is the quantile function. Its values at are the quartiles, with the middle quartile called the median. For our dart, inverts to , giving quartiles of , , and . Notice that the median dart lands at , well past half the radius, because three quarters of the board lies beyond .
Remarkably, the quantile function is also a universal sampler.
Proposition (inverse-transform sampling). Let be a continuous c.d.f. that is strictly increasing on the interval where , and let be uniform on . Then has c.d.f. .
Proof. With probability one, lies in , so is defined and lies in . For in , the events and coincide, because is increasing on . Since is uniform on , the second event has probability equal to the length of :
For to the left of , and always; for to the right of , and always.
Notice that this hypothesis allows to be flat outside an interval, just as the dart's c.d.f. is ( for and for ). Replacing with the generalized inverse removes the hypothesis altogether and samples staircase c.d.f.s as well.
For the dart, inverse-transform sampling gives . It is tempting to take the shortcut , and we can see immediately why that fails without running a single line of code: places half the darts inside , where only a quarter belong. Figure 24.1.4 shows the geometry of the construction on our two-bump density. Wherever the density is high, the c.d.f. rises steeply, so an evenly spaced set of levels on the vertical axis is compressed into a tight cluster of samples on the horizontal axis.
Inverse-transform sampling. Uniform levels on the vertical axis (left) reflect through the c.d.f. down to values on the horizontal axis. Where is steep, that is, where the density is large, a uniform spread of levels is compressed into a dense cluster of samples, so the histogram of reflected points reproduces .
We now have two completely different ways to generate the dart's distance: throwing darts at the square and keeping those on the board, or simply computing . The cell below compares the two, alongside the naive shortcut .
u = rng.uniform(size=10**6)
r = np.sqrt(u) # R = F^{-1}(U)
print(f'P(R < 0.5): darts {np.mean(r_dart < 0.5):.3f}, sqrt(U) '
f'{np.mean(r < 0.5):.3f}, naive U {np.mean(u < 0.5):.3f}')
print(f'mean distance: darts {r_dart.mean():.3f}, sqrt(U) {r.mean():.3f}')P(R < 0.5): darts 0.250, sqrt(U) 0.250, naive U 0.500
mean distance: darts 0.667, sqrt(U) 0.667
The two valid methods agree. Both place a quarter of their distances below , and both have a mean distance close to , a number we will derive in the next subsection. The naive shortcut puts half its samples below because it spreads distances evenly across , ignoring the fact that the board has far more area near the rim than near the center.
24.1.2 Mean and Variance#
A density specifies an entire distribution, yet two summary numbers often tell us most of what we need to know: where the distribution is centered, and how widely it spreads. Section 1.6 introduced both for discrete variables and motivated their use; here we extend them to densities and prove the algebraic rules we rely on.
24.1.2.1 The Mean#
The mean averages the values of , weighting each by its probability. For a variable with a density, slicing the real line into bins of width as before shows that the bin at contributes its value times its probability, roughly , and the resulting sum tends to an integral. The mean, or expectation, of is therefore
Just as in the discrete case, the mean acts as a balance point: a thin rod with mass density along its length balances at . For this definition to make sense, we require in the discrete case and for a density. When that condition fails, the mean does not exist, and we will soon meet a concrete density where this happens. Using the same probability weights lets us average any function directly,
again provided the sum or integral of is finite. Notice how convenient this is: we weight the values of by the probabilities of , without first having to work out the distribution of the transformed variable . This rule is famously called the law of the unconscious statistician, because it is so natural to apply that one easily forgets it is a theorem rather than the definition of . Keep in mind that generally differs from ; when is convex, Jensen's inequality (Section 23.3.3.1) tells us which of the two is larger.
For our dart,
The mean distance is , not , again because the board has more area near the rim than near the center. Notice also that the mean sits slightly below the median : the relatively few darts that land near the center pull the average downward more than they shift the middle value.
The property of expectation we use most often is linearity. We relied on it in Section 1.6; here we prove it.
Proposition (linearity of expectation). For random variables whose means exist and constants ,
Proof. Both identities follow from the linearity of the sum (or integral) that defines the mean. For the first, , using . For the second, let be the probability that , the joint distribution of the pair as in Section 1.6. Splitting the sum and recognizing the marginals and gives
For densities, the exact same computation runs with integrals over a joint density, the continuous counterpart of , which Section 24.2 defines.
Crucially, the second identity requires no independence at all: the mean of a sum equals the sum of the means no matter how tightly and depend on each other. Every time we take the expected loss as an average over a dataset, we are relying on this fact.
24.1.2.2 Variance and Standard Deviation#
The mean tells us where a distribution sits, but nothing about how tightly it clusters there. As in Section 1.6, we measure spread by the average squared distance from the mean, called the variance,
which is defined whenever . Expanding the square and applying linearity (24.1.8), treating as a constant, yields a form that is usually much easier to compute: the mean of the square minus the square of the mean,
For a variable with a density, the mean and variance are therefore given by the two integrals
For the dart, , so . For the uniform variable on , and .
Rescaling units or centering data are affine transformations. Under an affine map , the shift drops out of the variance while the scale factor comes out squared. Indeed, linearity gives , so the deviation from the mean is ; squaring and taking the expectation gives
Two further properties are worth keeping in mind. First, variance is never negative, and it equals zero if and only if is constant with probability one, since the expectation of the non-negative quantity can vanish only when that quantity is zero with probability one. Second, variances of independent random variables add (Section 1.6); we will prove this in Section 24.2.2.1, along with the covariance term that replaces independence when variables interact.
Because variance squares the deviations, it carries squared units, such as dollars squared for a profit measured in dollars. Taking its square root restores the original units and gives the standard deviation,
which scales linearly under affine maps as . For our dart, , measured in units of the board's radius.
24.1.3 Tails#
The standard deviation sets a natural scale for typical fluctuations around the mean. A natural next question is how much probability can sit far out in the tails when all we know is the mean, or the mean and variance. Two classic inequalities answer this for every distribution at once. Both bounds are quite crude, yet surprisingly they are the sharpest possible without extra assumptions, as a simple three-point distribution will demonstrate. We then turn to a bell-shaped density that has neither a mean nor a variance, showing what those two assumptions were protecting us from.
24.1.3.1 Markov's and Chebyshev's Inequalities#
The first bound uses only the mean and applies to any non-negative random variable. Its proof takes a single line, yet nearly every tail bound in this chapter comes from applying it to a well-chosen function of the variable.
Proposition (Markov's inequality). If has a mean and , then
Proof. Let be the indicator variable that equals when and otherwise. Then for every outcome: when the right-hand side is , and otherwise it is . Taking expectations of both sides and using gives .
Geometrically, on the step function that is below and from onward stays underneath the line (Figure 24.1.5), so its average value must stay underneath the average value of . Setting to ten times the mean gives an immediate rule of thumb: at most a tenth of any non-negative population can exceed ten times its average, whether we are looking at incomes, file sizes, or gradient norms.
Geometry of Markov's inequality. For the step function (orange) lies under the line (blue), so its average cannot exceed . The shaded gap is what the bound gives away.
Because Markov's inequality uses only the mean, it is necessarily crude. Applying it to the squared deviation , whose mean is the variance, bounds both tails at once. This result is due to Bienaymé and Chebyshev (Chebyshev, 1867).
Proposition (Chebyshev's inequality). For any with finite, nonzero variance and any ,
Proof. The variable is non-negative with mean , and the event is identical to the event . Since , the threshold is positive, so Markov's inequality (24.1.14) gives .
In particular, at most of any distribution can lie ten or more standard deviations from its mean. Running the same proof with an absolute threshold in place of gives an equivalent form that requires only finite variance and also covers the degenerate case :
For our dart, and . Two standard deviations below the mean is , while two above lies outside the board altogether, so , far smaller than Chebyshev's bound of .
Given how loose is for the dart, can a bound valid for every distribution be sharpened? Not without further assumptions, and a distribution supported on just three points proves it. Let take the values and with probability each, and with the remaining probability , where . We call this the three-atom example. By symmetry its mean is , and its variance is , so . Take . As shrinks, the threshold shrinks with it, while the two outer atoms stay fixed at distance from . Figure 24.1.6 shows the three resulting regimes. When , the threshold exceeds , so neither outer atom falls in the tail and the probability is . At , the threshold lands right at , giving and placing two standard deviations from the mean; both outer atoms now count, their total probability is , and Chebyshev's bound holds with equality. When , both outer atoms still lie beyond the threshold, and their combined mass falls below .
Chebyshev's bound on the three-atom example: masses , , drawn as vertical bars at , , , with the threshold distance for marked as a horizontal bracket from to . The three panels show the regimes , (where the bound is attained with equality), and . Orange atoms lie at or beyond the threshold and count toward the event .
The same construction settles every . Choosing , which is at most , gives , so the threshold lands squarely on the outer atoms and . Equality holds, proving that no constant smaller than can work for all distributions. (For , the bound exceeds and says nothing.)
Chebyshev's inequality therefore captures the worst case over all distributions with a given variance. For the distributions we usually encounter, it is quite loose. A Gaussian with mean and standard deviation , the bell curve with density studied in full in Section 24.3.2.3, puts far less probability beyond two and three standard deviations than Chebyshev allows:
| distance from the mean | Chebyshev's bound | Gaussian |
|---|---|---|
| or more | ||
| or more |
The worst-case distribution concentrates all of its tail mass at a single distance, just as our three-atom example does. Typical distributions spread their tails out and thin them rapidly.
24.1.3.2 Heavy Tails#
Chebyshev's inequality requires a finite variance, and the mean itself requires . Surprisingly, both conditions can fail for a smooth, harmless-looking bell curve. The Cauchy distribution has the density
This is a valid density, since . Unlike a Gaussian, whose tails plummet like , the Cauchy tails decay only algebraically, like . The second moment fails first. Integrating over gives
which evaluates to , , and at , , and , growing without bound because the integrand approaches the nonzero constant . Hence , and the Cauchy distribution has no finite variance.
The mean fails in a subtler way. Because the integrand is odd, it is tempting to declare the mean to be by symmetry, and indeed for every . However, the definition of expectation requires absolute convergence, and
grows without bound as . Consequently, the Cauchy mean does not exist. Without absolute convergence, the value of the integral depends on how the limits are taken: over the lopsided interval , for example,
With no mean to settle toward, what happens when we average independent Cauchy draws? One might still hope that averaging draws lands closer to than a single draw, which falls outside with probability . The cell below plots the running mean of Cauchy draws alongside that of standard Gaussian draws, and then counts how many of separate averages (each over Cauchy draws) still lie farther than from .
n = 10**5
idx = np.unique(np.logspace(0, 5, 500).astype(int)) - 1 # log-spaced n
running_mean = lambda x: (np.cumsum(x) / np.arange(1, n + 1))[idx]
d2l.plot(idx + 1, [running_mean(rng.standard_normal(n)),
running_mean(rng.standard_cauchy(n))],
'n', 'running mean', legend=['Gaussian', 'Cauchy'],
xscale='log', ylim=[-4, 4], figsize=(5, 3))
averages = rng.standard_cauchy((1000, 1000)).mean(axis=1)
print(f'averages of 1000 Cauchy draws with |average| > 1: '
f'{np.mean(np.abs(averages) > 1):.2f}')averages of 1000 Cauchy draws with |average| > 1: 0.49
The Gaussian running mean settles smoothly toward . The Cauchy running mean never settles: it lurches in sudden jumps, each triggered by a single extreme draw, and an order-one jump can strike at any . Averaging brings no improvement at all. Roughly half of the averages of draws still lie farther than from , matching the fraction for a single draw. In fact, as we state without proof, the average of independent standard Cauchy variables has the same distribution as a single standard Cauchy variable.
A distribution is called heavy-tailed when its tails decay more slowly than every exponential with . Power-law tails, where decays like , are the canonical example: they force every moment with to be infinite, with the Cauchy distribution corresponding to . Heavy tails do not automatically imply infinite moments, however; the log-normal distribution, which we derive in Section 24.2.3.1, is heavy-tailed yet has all moments finite. Heavy tails matter in deep learning because sample averages over them converge slowly or fail to converge altogether. Minibatch gradient noise, for example, has been argued to be heavy-tailed (Simsekli et al., 2019), a hypothesis that Exercise 5 lets you test.
Everything in this section dealt with one number at a time, whereas our dart lands in a plane and has two coordinates. Those two coordinates turn out to be uncorrelated yet far from independent, and making sense of that requires densities over the plane, which we take up in Section 24.2.
24.1.4 Summary#
A continuous random variable assigns probability zero to every individual value, so we describe its distribution through a density, the probability per unit length. Integrating the density over an interval gives that interval's probability, the c.d.f. accumulates this area from left to right with , and inverting the c.d.f. turns uniform noise into samples from the distribution. Markov's and Chebyshev's inequalities bound the tails of any distribution using only its mean or variance; Chebyshev's bound is tight in the worst case yet loose for typical distributions. Heavy-tailed distributions like the Cauchy have neither a mean nor a variance, and averaging their draws does nothing to reduce their spread. Above all, carry Markov's inequality forward: every tail bound in Section 24.9 descends from it.
24.1.5 Exercises#
-
Power-law tail. Let have the density for and otherwise.
- Verify that is a density, and compute and the c.d.f. for every real .
- Find the quantile function for , the median, and the other two quartiles. Write down the inverse-transform sampler of Figure 24.1.4 for this distribution.
- Show that . Clipping at a level , as gradient clipping does for a gradient norm, gives . Compute , and describe how it grows with .
- For the Cauchy density , derive the values of and quoted in the text, and their limits as . What do the two limits say about the mean of the Cauchy distribution? Why can no such ambiguity arise for the mean of the non-negative variable of part (a)?
-
Rectified Gaussian. Let have the standard Gaussian density and c.d.f. , and let . This is the output of a ReLU unit with a standard normal pre-activation, a common model of a unit at initialization.
- Express the c.d.f. through and sketch it. Where does have an atom, and what is its mass? Is discrete, does it have a density, or is it mixed?
- Explain why has no density. For a strictly monotone, continuously differentiable transformation , the change-of-variables rule of Section 24.2.3.1 gives the density . Which of its hypotheses fails for the ReLU?
- Clipping to for a threshold , as the hard-tanh
activation does for , gives . Write
down the c.d.f. of , and find the threshold at which the atoms
of together hold of the probability. The equation has no
closed-form solution; use tabulated values of , or
math.erfwith . - Show that and . Hint: write and use the symmetry of . The He initialization of Section 4.4.2.2 multiplies the weight variance by ; which of these two moments does the factor compensate for?
-
[code] Logistic distribution and calibration. The logistic distribution has the c.d.f. .
- Find its density with (24.1.6) and its quantile function. What are its quartiles?
- Let have a continuous, strictly increasing c.d.f. . Show that is uniform on . This is the converse of inverse-transform sampling.
- A probabilistic regression model predicts for each input a logistic distribution for the target , centered at the correct location but with a scale , that is, the c.d.f. . The actual errors follow the standard logistic distribution. Draw errors with the quantile function from (a), compute for , and plot the three histograms of the . Which shape reveals predicted distributions that are too narrow, and which reveals distributions that are too wide? Such histograms are a standard check of the calibration of probabilistic forecasts (Gneiting et al., 2007).
-
One-sided Chebyshev. ● Chebyshev's inequality (24.1.15) bounds both tails at once. Cantelli's inequality bounds one tail: for with mean and variance , and for every ,
- For every , apply Markov's inequality (24.1.14) to to show that . Choose to prove Cantelli's inequality.
- Write the bound for , and compare it with (24.1.15) at and .
- For given , and , find a distribution on two points with mean and variance that attains the bound.
- [extended] Averages of heavy tails. ●●
Simsekli et al. (2019) argued that the gradient
noise of SGD in deep networks is heavy-tailed and better described by an
-stable distribution, whose variance is infinite for
, than by a Gaussian. This project measures how a Monte Carlo
average behaves in that regime and then tests the premise on a small
model. The Pareto density on , with
, contains the density of problem
1 as the case .
- Generalize problem 1b and c to this family: show that exactly when , compute the mean for , and write down an inverse-transform sampler.
- Let , so that the mean is finite but the variance is not. Show that the largest of independent draws exceeds with probability close to when is small, and find the scale that the largest draw typically reaches. Argue heuristically that the error of the sample mean is of order rather than . The generalized central limit theorem that Simsekli et al. invoke makes this argument precise.
- For and , estimate the median of over repetitions, and fit the slope of the logarithm of the median error against . Compare the slope at with the rate from (b). Compare the slopes at and with the rate that holds when the variance is finite.
- In each repetition, form the interval , where is the sample standard deviation; for Gaussian averages it covers with probability about . Record how often it covers . Explain the coverage at and , given that is finite in every run. What does this imply for error bars computed from heavy-tailed samples, such as minibatch gradients?
- The Hill estimator (Hill, 1975) estimates the tail index from the largest of positive draws as
Check it on Pareto draws for and . Then train the softmax regression of Section 3.3.5. At the trained parameters, collect the coordinates of the difference between the minibatch gradient and the full-batch gradient over minibatches, for batch sizes and . Plot of their absolute values against for both batch sizes. Is the estimate below ? How much does the conclusion depend on ?