srinivas raghav blog's

Deep Learning Note 2: Sums, Variance, and Alignment

One of the most useful mathematical ideas for understanding deep learning begins with a surprisingly simple question:

What happens when we add a large number of quantities together?

Imagine standing at the origin of a number line and taking a step to the left or right depending on the outcome of a fair coin toss. After taking 100 steps, you have certainly travelled 100 units, but you are unlikely to be 100 units away from where you started. Some steps undo the progress made by others. This distinction between the total amount of activity and its net effect is what we want to understand.

Pasted image 20261202205948

Figure 1: A random walk illustrating the difference between distance travelled and net displacement.

Understanding mean and variance

Suppose we repeat this experiment thousands of times. Sometimes we finish to the left of the origin, sometimes to the right. Since both directions are equally likely, our average final position approaches zero. This average is called the mean, commonly denoted by μ=𝔼[X]. However, the mean alone tells us very little about how far we have wandered. Whether we take ten steps or a million, our expected final position remains zero, even though a million steps give us considerably more opportunity to wander away from the origin. We therefore need another quantity that describes how widely our outcomes are spread around their mean.

Pasted image 20261202210000

Figure 2: Three distributions sharing the same mean but having progressively larger spreads.

We begin by measuring each outcome's deviation from the mean, X−μ. Simply averaging these deviations would bring us back to zero, since positive and negative deviations cancel. Instead, we square them before averaging. This gives us a quantity called variance.

Var(X)=𝔼[(X−μ)2]

Since squaring changes the units of our measurement, we take the square root to return to the original scale. This gives us the standard deviation, denoted by σ.

σ=Var(X)

The mean describes where our numbers tend to live, while the standard deviation describes how far they typically wander from that centre.

The hidden interactions inside a sum

Now consider two random quantities, x1 and x2, each with zero mean and variance σ2. We want to understand the typical magnitude of their sum. Since both have zero mean, their sum also has zero mean, and its variance is simply the expected squared sum.

S=x1+x2

Squaring this expression reveals something particularly interesting:

S2=x12+x22⏟Individual contributions+2x1x2⏟Interaction

The first two terms describe the individual contributions of the numbers, while the third describes their relationship with one another. When both numbers have the same sign, their product is positive, increasing the squared magnitude of the sum. When their signs differ, their product is negative, reducing it. The cross term therefore captures whether the two quantities reinforce or cancel one another.

Pasted image 20261202210049

Figure 3: A geometric decomposition of a squared sum, highlighting individual contributions and cross terms.

Two different worlds

Imagine that x1 and x2 are outcomes of two independent fair coin tosses, each producing either +1 or −1. There are four equally likely possibilities.

x1 x2 Interaction x1x2
+1 +1 +1
+1 −1 −1
−1 +1 −1
−1 −1 +1

The positive and negative interactions balance perfectly in expectation. Consequently,

𝔼[x1x2]=0

Only the individual squared contributions survive. More generally, for uncorrelated quantities with variance σ2,

Var(S)=σ2+σ2=2σ2

Now imagine a slightly different experiment. Instead of tossing two independent coins, we toss a single coin and repeat its outcome twice. Each individual quantity still has exactly the same mean and variance, but their relationship has changed. They always share the same sign, meaning their interaction is positive whenever the outcome is nonzero.

More generally, when both quantities are copies of the same zero-mean random variable with variance σ2,

𝔼[x1x2]=σ2

Therefore,

Var(S)=σ2+σ2+2σ2=4σ2

Notice that we have not changed the statistical properties of the individual quantities. We have only changed how they relate to one another, and that alone has changed the magnitude of their combined effect.

Pasted image 20261202210105

Figure 4: An animation comparing independent coin tosses with perfectly aligned coin tosses.

Why this becomes remarkable at scale

Let us extend this idea from two quantities to N quantities. When we square their sum, every quantity interacts with every other quantity.

(∑i=1Nxi)2=∑i=1Nxi2⏟N individual terms+2∑i<jxixj⏟N(N−1) ordered cross terms

There are only N individual squared contributions, but there are N(N−1) ordered cross terms, counting both orders of each pair. As N increases, the number of interactions grows much faster than the number of individual contributions.

Pasted image 20261202210119

Figure 5: An expanding matrix of pairwise products, showing how off-diagonal interactions rapidly outnumber diagonal contributions.

When the quantities are uncorrelated, the cross terms average to zero, leaving only the individual contributions. When the quantities are perfectly aligned, every interaction reinforces the others.

Uncorrelated Perfectly aligned
Variance Nσ2 N2σ2
Standard deviation Nσ Nσ

This is the origin of two fundamentally different scaling laws:

Uncorrelated accumulation:NσAligned accumulation:Nσ

Pasted image 20261202210128

Figure 6: An animated comparison of square-root growth and linear growth as the number of contributions increases.

The world in between

Of course, most interesting systems are neither completely uncorrelated nor perfectly aligned. Suppose every pair of quantities shares a small positive correlation ρ. The variance of their sum becomes

Var(S)=Nσ2+N(N−1)ρσ2

Or, equivalently,

Std(S)=σN+ρN(N−1)

Even a tiny positive correlation can become significant when thousands of quantities interact. For instance, with 10,000 quantities of unit variance, a pairwise correlation of just ρ=0.01 increases the standard deviation of their sum from 100 to approximately 1,005. Individually, these relationships appear almost insignificant. Collectively, they can dominate the behaviour of the entire system.

Figure 7: A visualization showing how even a small positive correlation changes the scaling behaviour of a sum.

The central idea worth carrying forward is that the magnitude of a sum depends not only on the magnitude of its individual contributions, but also on the relationships between them. Uncorrelated contributions tend to cancel, while aligned contributions reinforce one another. As the number of quantities grows, even a small amount of alignment can produce a surprisingly large collective effect.

We will encounter this same mathematical idea repeatedly when studying high-dimensional vectors, attention, normalization, residual connections, and gradient updates. Although these mechanisms may initially appear unrelated, understanding cancellation and alignment gives us a common starting point for exploring them.

#dl-notes