Lesson 1.9: The Calculus of Center and Spread

We now upgrade our tools to handle the continuous world. This lesson shows how to calculate the Expected Value and Variance by replacing discrete summation (∑) with continuous integration (∫). We will rigorously derive these essential formulas and apply them to prove the moments of the Uniform distribution, laying the groundwork for analyzing all continuous models.

Part 1: Upgrading Your Toolkit from Sums to Integrals

The concepts of "mean" and "variance" are universal. The only thing that changes between the discrete and continuous worlds is the mathematical tool we use to calculate them.

The Great Translation: From Σ to ∫

This table is the key to the entire lesson. Everything we do is a direct translation of what we learned in Lesson 1.5.

ConceptDiscrete Tool (PMF)Continuous Tool (PDF)
Expected Value E[X]xp(x)\sum x \cdot p(x)xf(x)dx\int x \cdot f(x)dx
Expected Value E[g(X)]g(x)p(x)\sum g(x) \cdot p(x)g(x)f(x)dx\int g(x) \cdot f(x)dx

Part 2: Expected Value - The Center of Mass of an Area

Deriving the Continuous Expected Value
Instead of a seesaw with weights, we're now finding the balancing point of a solid shape defined by the area under the PDF curve.

Expected Value (Continuous)

The Expected Value (μ\mu) is the integral of xx weighted by the probability density f(x)f(x) over all possible values of xx.

E[X]=μ=xfX(x)dxE[X] = \mu = \int_{-\infty}^{\infty} x \cdot f_X(x) \, dx

Example: Proving the Mean of a Uniform Distribution

Let's use our new tool on the simplest continuous case: the Uniform distribution U(a,b)U(a, b), where the PDF is a flat line at f(x)=1/(ba)f(x) = 1/(b-a) for x[a,b]x \in [a, b], and 0 everywhere else. Logically, the balancing point of a perfect rectangle should be its exact middle, (a+b)/2(a+b)/2. Let's prove it.

Calculation: E[X] for U(a, b)

Step 1: Set up the integral. We only need to integrate over [a,b][a,b] where the PDF is non-zero.

E[X]=abx1badxE[X] = \int_{a}^{b} x \cdot \frac{1}{b-a} \, dx

Step 2: Factor out the constant term.

E[X]=1baabxdxE[X] = \frac{1}{b-a} \int_{a}^{b} x \, dx

Step 3: Evaluate the integral of x. The antiderivative of xx is x2/2x^2/2.

E[X]=1ba[x22]ab=1ba(b22a22)E[X] = \frac{1}{b-a} \left[ \frac{x^2}{2} \right]_{a}^{b} = \frac{1}{b-a} \left( \frac{b^2}{2} - \frac{a^2}{2} \right)

Step 4: Simplify the algebra. Use the difference of squares identity, b2a2=(ba)(b+a)b^2 - a^2 = (b-a)(b+a).

E[X]=12(ba)(ba)(b+a)=a+b2E[X] = \frac{1}{2(b-a)} (b-a)(b+a) = \frac{a+b}{2}

The calculus confirms our intuition perfectly.

Part 3: Variance - The Spread of an Area

Deriving the Continuous Variance
We use the same "shortcut" formula as before, Var(X)=E[X2](E[X])2\text{Var}(X) = E[X^2] - (E[X])^2, but we calculate the two expected values with integrals.

The Two-Step Plan for Variance

  1. Calculate the second moment, E[X2]E[X^2], by integrating x2f(x)x^2 \cdot f(x).
  2. Plug E[X2]E[X^2] and E[X]E[X] (from Part 2) into the variance formula.

The Second Moment (Continuous)

Using the general rule E[g(X)]=g(x)f(x)dxE[g(X)] = \int g(x)f(x)dx, we set g(x)=x2g(x)=x^2.

E[X2]=x2fX(x)dxE[X^2] = \int_{-\infty}^{\infty} x^2 \cdot f_X(x) \, dx

Example: Proving the Variance of a Uniform Distribution

Calculation: Var(X) for U(a, b)

Step 1: Calculate E[X2]E[X^2]. The antiderivative of x2x^2 is x3/3x^3/3.

E[X2]=abx21badx=1ba[x33]abE[X^2] = \int_{a}^{b} x^2 \cdot \frac{1}{b-a} \, dx = \frac{1}{b-a} \left[ \frac{x^3}{3} \right]_a^b
=13(ba)(b3a3)= \frac{1}{3(b-a)} (b^3 - a^3)

Using the identity b3a3=(ba)(a2+ab+b2)b^3 - a^3 = (b-a)(a^2+ab+b^2):

E[X2]=a2+ab+b23E[X^2] = \frac{a^2+ab+b^2}{3}

Step 2: Plug into the variance formula. We know E[X]=(a+b)/2E[X] = (a+b)/2.

Var(X)=E[X2](E[X])2=a2+ab+b23(a+b2)2\text{Var}(X) = E[X^2] - (E[X])^2 = \frac{a^2+ab+b^2}{3} - \left(\frac{a+b}{2}\right)^2
=a2+ab+b23a2+2ab+b24= \frac{a^2+ab+b^2}{3} - \frac{a^2+2ab+b^2}{4}

Finding a common denominator and simplifying the algebra...

=4(a2+ab+b2)3(a2+2ab+b2)12=a22ab+b212= \frac{4(a^2+ab+b^2) - 3(a^2+2ab+b^2)}{12} = \frac{a^2-2ab+b^2}{12}
Var(X)=(ba)212\text{Var}(X) = \frac{(b-a)^2}{12}
The Quant Finance & ML Connection

    This isn't just abstract calculus; this is the daily work of a quantitative professional.

    • Derivatives Pricing: The expected payoff of a financial option is literally the integral of the payoff function multiplied by the risk-neutral PDF of the underlying asset's price. The Black-Scholes formula is a famous closed-form solution to such an integral.
    • Continuous Loss Functions: In machine learning, when we assume the errors of a model follow a continuous distribution (like the Normal distribution), the process of minimizing the loss function is implicitly finding the parameters that best match the expected value and variance derived through these integral methods.

What's Next? The Continuous Toolbox

We have now fully upgraded our mathematical machinery to handle the continuous world. We know what PDFs are and how to use integration to find their moments.

It is time to build our toolbox. Just as we had the Binomial and Poisson for discrete counts, we need a set of standard, named distributions for continuous measurements. The next lesson introduces the most common and useful continuous PDFs.