Skip to content
AI360XpertBeta

Integrals in Probability

For anything measured on a continuous scale, probability is area rather than height — which is why the chance of hitting an exact value is zero and why so many useful quantities have no formula.

For a continuous variable the height of the curve is not a probability; only the shaded area between two points is, which is why the chance of landing on any exact value is zero
For a continuous variable the height of the curve is not a probability; only the shaded area between two points is, which is why the chance of landing on any exact value is zero

Why Does This Exist?

Three tools you use constantly are integrals, and none makes sense without this page.

norm.cdf is an integral. Every p-value, confidence interval and z-score lookup is area under a bell curve up to some point. There is no algebraic formula for it, which is why that function is a numerical routine and why statistics tables existed for a century.

The denominator in Bayes theorem is an integral. For continuous parameters the evidence term needs integrating over every possible value. That integral is why Bayesian methods are hard and why sampling and variational methods exist. The discrete version and its priors live in probability distributions.

The VAE loss is a workaround for an integral. The data probability under the model needs integrating over the whole latent space. It cannot be done, so training optimises a lower bound instead. The integral is step one, the bound is step three.

Think of It Like This

Asking how much a single point on a map weighs

You hold a map shaded by population density, people per square kilometre. Dark cities, pale countryside.

Ask how many people live in this province and the map answers: multiply density by area and total it. Ask how many live at these exact coordinates and the answer is zero. A point has no area, so however dark the shading, it contains nobody.

That is not a defect. It is what a density means. The shading is people per unit area, not people, and you get people only by multiplying by an area. A very dark point says the region around it is crowded, nothing about the point itself.

A probability density works the same. Its height is probability per unit of xx, not probability. Multiply by a width and you get probability. That is why a density can exceed 11 while a probability cannot.

How It Actually Works

For a discrete variable every rule is a sum. For a continuous one every sum becomes an integral. That is the whole translation.

Density to probability

A density p(x)p(x) meets two conditions:

p(x)≥0and∫−∞∞p(x) dx=1p(x) \ge 0 \quad \text{and} \quad \int_{-\infty}^{\infty} p(x)\, dx = 1

Never negative, total area exactly one. Probability comes from intervals:

P(a≤X≤b)=∫abp(x) dxP(a \le X \le b) = \int_a^b p(x)\, dx

Two consequences surprise people. First, P(X=c)=0P(X = c) = 0 for any single cc, because zero width has zero area, so ≤\le and << are interchangeable here. Second, p(x)p(x) can exceed 11. A Gaussian with σ=0.1\sigma = 0.1 peaks near 3.993.99. Nothing is wrong, it is a rate and narrowness compensates.

The CDF is the integral of the density

The cumulative function accumulates area from the left:

F(x)=∫−∞xp(t) dtF(x) = \int_{-\infty}^{x} p(t)\, dt

The chance of landing at or below xx. It runs 00 to 11 and never falls. Differentiate it and you get the density back, so CDF and PDF are an antiderivative pair. That is the most useful fact here, and it is why practical work happens in CDF space: any interval is one subtraction F(b)−F(a)F(b) - F(a), and every p-value is a CDF call.

Expectation becomes an integral

Discrete expectation sums xx times probability. Continuous version:

E[X]=∫−∞∞x p(x) dxE[X] = \int_{-\infty}^{\infty} x\, p(x)\, dx

Each value weighted by density, totalled across the line. More generally E[g(X)]=∫g(x)p(x) dxE[g(X)] = \int g(x) p(x)\, dx, the form that appears everywhere because a loss is an expectation of per-example cost. Variance follows the same swap with (x−E[X])2(x - E[X])^2 inside.

The normalising constant, and where things go wrong

Often you can write a shape proportional to a density but not the density itself:

p(x)=1Zp~(x),Z=∫p~(x) dxp(x) = \frac{1}{Z} \tilde{p}(x), \qquad Z = \int \tilde{p}(x)\, dx

ZZ forces total area to 11. Discrete ZZ is a sum you can compute, exactly what a softmax denominator is. Continuous ZZ is an integral, and that is where tractability dies.

Bayes with parameters θ\theta and data DD shows it:

P(θ∣D)=P(D∣θ) P(θ)∫P(D∣θ) P(θ) dθP(\theta \mid D) = \frac{P(D \mid \theta)\, P(\theta)}{\int P(D \mid \theta)\, P(\theta)\, d\theta}

Numerator is easy, both pieces chosen by you. Denominator integrates over every setting, hopeless for millions of parameters. Every practical method dodges it: conjugate priors make it solvable for a few families, MAP maximises the numerator and drops ZZ, MCMC samples without knowing ZZ, variational methods bound it.

Worked example

Uniform on [0,2][0, 2]. Width 22 needs height p(x)=0.5p(x) = 0.5 for area 11.

P(0≤X≤1)=∫010.5 dx=0.5P(0 \le X \le 1) = \int_0^1 0.5\, dx = 0.5 E[X]=∫02x⋅0.5 dx=0.5[x22]02=1E[X] = \int_0^2 x \cdot 0.5\, dx = 0.5 \left[\frac{x^2}{2}\right]_0^2 = 1

Midpoint, as symmetry demands. Narrow it to [0,0.5][0, 0.5] and p(x)=2p(x) = 2 keeps area 11. The density is 22, above 11, yet every probability stays below 11 because widths are small.

Gaussian case: standard normal P(−1≤X≤1)≈0.6827P(-1 \le X \le 1) \approx 0.6827, the familiar 6868 percent, and it is an area. No elementary formula exists for ∫e−x2/2dx\int e^{-x^2/2} dx, which is why the diagram labels that region 0.680.68 instead of deriving it.

Code

This snippet checks the uniform arithmetic and the Gaussian area with only numpy and the standard library.

import mathimport numpy as np

def uniform_pdf(x: np.ndarray, lo: float, hi: float) -> np.ndarray:    return np.where((x >= lo) & (x <= hi), 1.0 / (hi - lo), 0.0)

grid = np.linspace(0, 2, 200001)pdf = uniform_pdf(grid, 0, 2)print(round(float(np.trapezoid(pdf, grid)), 4))  # -> 1.0print(round(float(np.trapezoid(grid * pdf, grid)), 4))  # -> 1.0print(float(uniform_pdf(np.array([0.25]), 0, 0.5)[0]))  # -> 2.0print(round(0.5 * (1 + math.erf(1 / math.sqrt(2))), 4))  # -> 0.8413

The first two prints confirm total area 11 and mean 11. The third shows density 22 is fine. The last is Φ(1)\Phi(1), so Φ(1)−Φ(−1)\Phi(1) - \Phi(-1) is 2×0.8413−1≈0.68272 \times 0.8413 - 1 \approx 0.6827.

Watch Out For

Comparing densities across different units or parameterisations

A density shifts under a change of variable by a Jacobian factor, because the widths you multiply by changed. Probabilities stay identical, density values do not. So log-likelihoods on different preprocessings can read −2.3-2.3 versus −4.1-4.1 for the same model on the same data.

Compare continuous likelihoods and bits-per-dimension only across identical preprocessing. A positive continuous log-likelihood is also fine, since density above 11 has positive log.

Assuming a normalising constant can be computed

The common failure is writing an unnormalised density, getting a working loss, and never noticing ZZ was dropped. Dropping it is correct for ranking or MAP, where ZZ has no gradient. It fails the moment you need a real probability, a calibrated confidence, a likelihood comparison or an energy model.

Know whether your objective needs ZZ. If you quote a probability, name the approximation that produced it.

The Quick Version

  • For continuous variables every probability rule becomes an integral instead of a sum.
  • A density is probability per unit, not probability. It may exceed 11.
  • P(X=c)=0P(X = c) = 0 always, because zero width has zero area.
  • The CDF is the integral of the density, differentiating it returns the density.
  • Expectation is ∫x p(x) dx\int x\, p(x)\, dx, and E[g(X)]=∫g(x)p(x) dxE[g(X)] = \int g(x) p(x)\, dx covers every loss.
  • The normalising constant forces total area to 11. Discrete is a sum, continuous is often intractable.
  • Bayes denominator is that integral, which is why MAP, MCMC and variational methods exist.
  • Densities shift under reparameterisation, so compare likelihoods only on identical preprocessing.